Author Topic: Shutdown a Server with RT mode  (Read 4231 times)

Offline vletroye

  • Hero Member
  • *****
  • Posts: 714
  • Karma: +7/-0
    • View Profile
Shutdown a Server with RT mode
« on: February 03, 2013, 04:06:20 pm »
I read in the "Dos and Don't" that we have to always stop the storage pool through the WebUI before restarting the FlexRAID service or your OS. (http://wiki.flexraid.com/2012/06/10/real-time-raid-dos-and-donts/:o

Written like this (and possibly because my English is not great) I understand that it  is also required before shutting down the server =>  Could you confirm that this still required with the latest version of the RT mode ?


I would like to use the RT mode but my Home Server(*) is not 24/7. I use WOL to wake it up on request and as soon as I don't need access anymore I trigger a remote shutdown. Stopping manually the Pool before shutting down will be very restrictive :(

Why couldn't the service stop itself the Pool ? Windows Services can handle the preshutdown events... (and with a WaitToKillServiceTimeout = 600000, they should have time enough to close properly)


(*) My Server is used to backup all the other PC and I am afraid that disks could crash during such backups as "Edits" compromise recovery.

Offline Brahim

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8,547
  • Karma: +204/-16
    • View Profile
Re: Shutdown a Server with RT mode
« Reply #1 on: February 04, 2013, 11:15:50 am »
Those are the current limitation of RT RAID.
If you want to use RT RAID, you must follow those rules.

If you can program, you script the CMD client to send a shutdown command to the service.
Actually, someone here already implemented that. Do search and PM that user to share his script.

Offline vletroye

  • Hero Member
  • *****
  • Posts: 714
  • Karma: +7/-0
    • View Profile
Re: Shutdown a Server with RT mode
« Reply #2 on: February 04, 2013, 12:09:27 pm »
 :-\

Glups. I was still looking for a disadvantage of RT versus Snapshot. This is one  :-[

As you mention indeed, if I can find/get the command to stop the pool, I will implement a "shutdown task" via the policies (http://technet.microsoft.com/en-us/library/cc770300.aspx)

Thx !

Offline Brahim

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8,547
  • Karma: +204/-16
    • View Profile
Re: Shutdown a Server with RT mode
« Reply #3 on: February 04, 2013, 12:34:02 pm »
Well, the biggest disadvantage of RT RAID is that it is still experimental.
Make sure to follow the DOs and DON'Ts.

You can also give RT RAID a trial on Linux as it might work better there.

Offline bigbob

  • Newbie
  • *
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Shutdown a Server with RT mode
« Reply #4 on: February 04, 2013, 01:26:46 pm »
Brahim, I've installed my FR on WHS 2011.  Can I uninstall it from WHS and move the license to a Linux server?  Are you going to fix this in the next upcoming version for Windows/WHS? 

Offline Brahim

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8,547
  • Karma: +204/-16
    • View Profile
Re: Shutdown a Server with RT mode
« Reply #5 on: February 04, 2013, 02:47:56 pm »
Brahim, I've installed my FR on WHS 2011.  Can I uninstall it from WHS and move the license to a Linux server?  Are you going to fix this in the next upcoming version for Windows/WHS?

I would say, trial on Linux first, and if you want to make a permanent move, contact sales for a one time courtesy transfer.

Fix what?

Offline vletroye

  • Hero Member
  • *****
  • Posts: 714
  • Karma: +7/-0
    • View Profile
Re: Shutdown a Server with RT mode
« Reply #6 on: February 04, 2013, 03:34:50 pm »
As far as I am concerned, testing on Linux wouldn't be representative...
My purpose is to find a good alternative to the "Space Storage" of my Windows Server 2012.

And I am not afraid of "testing" FlexRaid in RT mode as far as it's not impacting the data in any way.
Also if the server must be re-installed, I don't loose any data..
I will just possibly not be protected against disk failure...

Based on your advice, I found the client to be used in Windows to stop the pool. It's not "FlexRaidClient" as mentioned in the wiki but "FlexRaidCMD"
Here are my findings (for other readers possibly interested)


FlexRaidClient is not installed by default with the service. It must be downloaded as an Option here

The syntax is: FlexRAIDClient Host Port Timeout Command

Once installed, one can use the Command "view" in a cmd prompt RUN AS Administrator on the server to Start/Stop the pool:

Code: [Select]
FlexRAIDCMD localhost - - view class1_0 start
FlexRAIDCMD localhost - - view class1_0 stop

The - -  are used as "default values" for the Port and Timeout parameters
I use class1_0 as I am using the new driver (=> class1) and I have only one pool (=> ID = 0).


Starting the pool takes about ~50 seconds.
Stopping the pool takes less than 10 seconds.


If the command fails due to a syntax error, the error message can be found in the file log.log
If the command succeed, there is nothing logged at all in the log file but a message displayed in the console (cmd prompt)

Quote
{"success": true, "status": null, "commandMessages": [{"messageCode": "successStoragePoolStarted", "messageData": ["V"]}], "serverMessages": null}
=> Le pool de stockage est bien d├®marr├® pour le volume: V:...


Notice: In a normal cmd prompt (not run as admin), the command returns an error due to an access denied on the log file:

Quote
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: log.log


Notice: if the Web UI was open before executing a Start/Stop, it must be reopened (or refreshed: CTRL-F5) otherwise it does not display the new state of the pool.


To shutdown the FlexRaid server after stopping the pool, use the command shutdown-server.

Code: [Select]
FlexRaid localhost - - shutdown-server

If the pool is still running, we get the following response:

Quote
{"success": false, "status": null, "commandMessages": [{"messageCode": "errorShutdownNotAllowedStoragePoolServiceRunning", "messageData": []}], serverMessages": null}
=> Pour pouvoir arr├¬ter le service "host", le service de pool de stockage doit ├¬tre arr├¬t├®!


If the service stops successfully, we get :

Quote
{"success": true, "status": null, "commandMessages": [{"messageCode": "successServerShutingDown", "messageData": []}], "serverMessages": null}
=> Arrêt du serveur en cours...


To restart the service, we can use:

Code: [Select]
net start "FlexRaid"

Notice: I didn't find yet on the forum the difference between 'FlexRaid localhost - - shutdown-server' and 'net stop "FlexRaid'. To my knowledge 'net stop' is synchronous and therefore maybe preferred to stop the service properly before shutting down ?! (FlexRaid message seems to indicate it's asynchronous)


Notice: If I run "FlexRaid localhost -- shutdown-server" while the service is not running, I get obviously an exception "Connection refused: connect : ConnectException" but also this message in the log file (log.log):

Quote
ERROR: Unexpected character ('A' (code 65)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: java.io.StringReader@2f3d698; line: 1, column: 2]
org.codehaus.jackson.JsonParseException: Unexpected character ('A' (code 65)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: java.io.StringReader@2f3d698; line: 1, column: 2]


Now, here is how to create a "shutdown task" in the Local Group Policies of a Windows Server 2012:

1) Enable script execution on the server
   a) On the Start Screen right-click the Windows PowerShell tile and run it As Administrator
   b) execute "Set-ExecutionPolicy RemoteSigned" in that shell and answer "Y"

2) Create the script
  a) Create a file "StopFlexRaid.ps1" in your "FlexRaid Client" folder (e.g.).
  b) Type the script found bellow in the file (change the path to FlexRaidCmd)


3) Use the script as Shutdown Script
  a) On the Start Screen, type "gpedit.msc" and run it.
  b) Go to the node "Computer Configuration\Windows Settings\Scripts (Startup/Shutdown)".
  c)  Edit "Shutdown" and in the tab "PowerShell script", "Add" StopFlexRaid.ps1

Notice:
- Shutdown scripts are run as Local System, and they have the full rights that are associated with being able to run as Local System.
- Shutdown scripts are run synchronously. The Server should wait on the script before shutting down.



Code: [Select]
$srvName = "FlexRAID"
$flexCmd = "C:\Program Files (x86)\FlexRAID 2.0 Client\FlexRAIDCMD.exe"
$servicePrior = Get-Service $srvName
#"$srvName is currently " + $servicePrior.status

function ExitWithCode
{
    param
    (
        $exitcode
    )
"Exit with code $exitcode"
    #$host.SetShouldExit($exitcode)
    #exit
}

if ($servicePrior.status -eq "Stopped")
{
"$srvName is already " + $servicePrior.status
}
elseif ($servicePrior.status -ne "Running")
{
"$srvName is not Running but " + $servicePrior.status
}
else
{
$error.clear()
"Wait on the Storage Pool to stop. This can take a few seconds."

#$stopPool = Start-Process  -ArgumentList  -NoNewWindow -Wait -PassThru -RedirectStandardOutput stdout.txt -RedirectStandardError stderr.txt

$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $flexCmd
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = "localhost - - view class1_0 stop"
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$output = $p.StandardOutput.ReadToEnd()
$output
$abort = "False"

if ( $error.count -eq 0)
{
if ($output.Contains("successStoragePoolStopped"))
{
"Storage Pool successfuly stopped"
Write-Eventlog -Logname 'Application' -source 'FlexRAID' -eventID 1 -EntryType Warning -Category 0 -message "Storage Pool stopped before shutting down"
}
else
{
if ($output.Contains("errorNoActiveStoratePool"))
{
"Storage Pool actually not started"
}
else
{
$abort = "True"
"Storage Pool failed to stop. Shutdown will abort."
$event = "FlexRaid Storage Pool failed to stop: " + $output
Write-Eventlog -Logname 'Application' -source 'FlexRAID' -eventID 1 -EntryType Error -Category 0 -message $event
cmd /c shutdown -a
ExitWithCode -exitcode 3
}
}

if ($abort -eq "False")
{

$error.clear()
Stop-Service $srvName
if ( $error.count -eq 0)
{
Write-Host -NoNewLine "Waiting on $srvName to stop "
$timeout = new-timespan -Minutes 1
$sw = [diagnostics.stopwatch]::StartNew()
while (((Get-Service $srvName).status -ne "Stopped") -and ($sw.elapsed -lt $timeout))
{
Write-Host -NoNewLine "."
sleep 1
}
"."
}
$serviceAfter = Get-Service $srvName
if ($serviceAfter.status -eq "Stopped")
{
"$srvName is now " + $serviceAfter.status
ExitWithCode -exitcode 0
}
else
{
"$srvName failed to stop. It is now " + $serviceAfter.status
ExitWithCode -exitcode 1
}
}
}
else
{
"Storage Pool failed to stop"
$error[0]
$event = "FlexRaid Storage Pool failed to stop: " + $error[0]
Write-Eventlog  -Logname 'Application' -source 'FlexRAID' -eventID 1 -EntryType Error -Category 0 -message $event
cmd /c shutdown -a
ExitWithCode -exitcode 2
}
}


This script will abort the shutdown if the pool cannot be successfully stopped and report that in the event log.

Any comment/help to improve of that script is welcome. This is my very first powershell script  :-[
« Last Edit: February 06, 2013, 05:13:51 pm by vletroye »

Offline Brahim

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8,547
  • Karma: +204/-16
    • View Profile
Re: Shutdown a Server with RT mode
« Reply #7 on: February 04, 2013, 04:23:20 pm »
As far as I am concerned, testing on Linux wouldn't be representative...
My purpose is to find a good alternative to the "Space Storage" of my Windows Server 2012.
...
Trying Linux should only be done if Linux is an option for you. Otherwise, sticking with Windows has many advantages.
A true alternative to "Storage Space" would be NZFS, but that's months out.

I would say, use Snapshot RAID for your fairly static data and then create a RAID 1 for the data you modify often as a stop gap.
Reality is such that the data you modify rarely will be 90+% of your total storage, which should only leave less than 10% to be mirrored.

FlexRAID does not have to cover 100% of your case to be useful. In almost all cases, it will reduce your cost for storage protection by protecting the bulk of your data on the cheap.
The bulk of my data is on Snapshot RAID, but I still have a number of RAID 1 arrays for different usage profiles.


Offline vletroye

  • Hero Member
  • *****
  • Posts: 714
  • Karma: +7/-0
    • View Profile
Re: Shutdown a Server with RT mode
« Reply #8 on: February 04, 2013, 06:11:50 pm »
LOL, I do have the feeling you don't make advertisement for  RT :)


> Reality is such that the data you modify rarely will be 90+%

True... But also, in my understanding of the Snapshot limitations, if a disk in a 3TB DRU crashes while doing a backup image of workstation into the pool, I could really be in trouble to restore that disk...

As you suggest I do have indeed a RAID 1  for the most critical data (documents often edited, photo, etc...). So, I think that it's not less or more risky for me to go with RT instead of Snapshot for the pool... as far as I have this script (see previous post) doing a "graceful shutdown"...

Offline Brahim

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8,547
  • Karma: +204/-16
    • View Profile
Re: Shutdown a Server with RT mode
« Reply #9 on: February 05, 2013, 09:48:56 am »
...
This script will abort the shutdown if the pool cannot be successfully stopped and report that in the event log.

Any comment/help to improve of that script is welcome. This is my very first powershell script  :-[
Wow! Very impressive work.
I don't know powershell enough to be too big of a critic, but things look good from a high level perspective.
Great work. :)

Offline Brahim

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8,547
  • Karma: +204/-16
    • View Profile
Re: Shutdown a Server with RT mode
« Reply #10 on: February 05, 2013, 09:57:40 am »
...
True... But also, in my understanding of the Snapshot limitations, if a disk in a 3TB DRU crashes while doing a backup image of workstation into the pool, I could really be in trouble to restore that disk...
...
If the backup is a new file, then there is no risk outside of losing that one file. The rest of the disk will be just fine.
If you read the wiki properly, you will see that edits are the only things to worry about with Snapshot RAID.
In the case of edits, it is another drive failing that is also the potential issue. The drive being written to will restore just fine.

In any case, I am not trying to talk you out of RT RAID as I designed it for a reason and that being that Snapshot RAID is not for every scenario.
RT RAID has it place. I just like to remind users that they can achieve greater efficiency by placing the bulk of the data under a Snapshot RAID configuration and then the remainder under RT RAID or RAID 1. :)

Offline vletroye

  • Hero Member
  • *****
  • Posts: 714
  • Karma: +7/-0
    • View Profile
Re: Shutdown a Server with RT mode
« Reply #11 on: February 05, 2013, 12:10:20 pm »
Clear!

As I will mainly drop "image backups" (or zip files) in the pool, keeping the same names, it will mainly be "edit"...

As soon as I will be able to create one pool with RT and one pool with Snapshot, I will possibly review the organization.

I will test the performance of RT but IMO you have designed a great tool. I especially love the idea that you don't touch the data in the DRU but only store Parity on the PPU.