How to close TrueNAS via a Windows CLI ?

NumberSix

Contributor
Joined
Apr 9, 2021
Messages
188
Hi
Is it possible to send a command from windows to Truenas, originating in a windows batch file, that will tell TrueNAS to close down gracefully, in the same manner that a UPS might signal it to do so? (and to push my luck, of restarting it when power resumes?).

The reason I ask: I have a great little freeware app called "WTUPS" which runs as a Windows daemon, listening to my UPS. If it gets a battery problem signal, the daemon shuts down everything attached to Windows (chiefly my Netgear ReadyNAS), then closes down a server process I run on Windows, before finally closing down Windows itself. It does this by running one of two windows .bat files (one for power going down, one for back up) that contain commands like the following :

Code:
@echo off
rem Define the commands for the tool to execute in case of a power outage

rem Examples

rem Shut down a remote Windows system in 5 minutes from now
rem shutdown -f -s -t 300 -m \\HOSTNAME

rem Shut down a remote linux system in 5 minutes from now
rem plink -ssh -pw PASSWORD USERNAME@HOSTNAME /sbin/shutdown -h +5

rem Shut down local systems
start "" "C:\OPENSIM\Shutdownsequence.exe"
TIMEOUT /T 90 /nobreak
shutdown -a
sleep 1
shutdown -f -s -t 0


So I reason that it must be possible to add TrueNAS to this list? Either with a command that addresses TrueNAS itself, or the underlaying BSD OS, and tells it to go sleepytime? I'm adept with neither TrueNAS nor BSD (nervous noobie) and just feeling my way at the moment, but if someone nearer guru status knows what I'm asking and can supply an answer I'd be thrilled! Thank you!!
 
Joined
Jun 2, 2019
Messages
591
Why go to all that trouble when you can use NUT everywhere?


TrueNAS and ReadyNAS both use NUT, and you can install NUT client on Windows/Linux

You can configure one as the UPS Master and all other clients as a UPS Slave to monitor the Master over a network. Just make sure UPS Master shuts down last.

To automatically power back up depends if your UPS will automatically reapply power and if each client BIOS supports powering back up upon power restore, but is typically not recommended in case power is intermittent during storms for example.

The other option is if the network card in each client supports Wake on LAN (WOL) where you can send the magic WOL packets from one client to other clients to cause them to boot back up.
 
Last edited:

NumberSix

Contributor
Joined
Apr 9, 2021
Messages
188
Hi
Thank you for that alternative solution. I appreciate a fresh way of thinking about a problem, and it's good to know what complimentary software is out there too.

However, I disagree that my approach is 'going to all that trouble' , especially compared to NUT. Consider:

* Downloading it.
* Installing it (maybe on multiple machines?).
* Learning how to use it.
* Configuring and testing it.

when the alternative is:

* insert one line of text into my existing. bat file.

On that basis, I'd prefer to hold out to see if anyone knows of a cli shutdown command, if one exists.
Cheers.
 

Redcoat

MVP
Joined
Feb 18, 2014
Messages
2,925
and you can install NUT client on Windows/Linux
Have you run the NUT client on Windows? If so, please describe your experience (and if it worked, how you achieved it). TIA.
 

Redcoat

MVP
Joined
Feb 18, 2014
Messages
2,925

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Is it possible to send a command from windows to Truenas, originating in a windows batch file, that will tell TrueNAS to close down gracefully
From a Unix-y system, you could just do ssh root@freenas shutdown -p now. I'd expect that would also work under Windows 10 (which includes a CLI SSH client); not sure about other versions. This would naturally require you to have public-key authentication set up for SSH. Otherwise, you could figure out the API call to do it, and make an appropriate HTTP call.
 
Joined
Jan 4, 2014
Messages
1,644
Have you run the NUT client on Windows? If so, please describe your experience (and if it worked, how you achieved it). TIA.
WinNUT! It's an old piece of s/w that still works its magic under Win10.

I have two Plex servers (Plex on TrueNAS and Plex on Win10) being serviced with one UPS. Plex on Win10 runs a DVR tuner so I can capture shows like the Olympics, Eurovision, etc. TrueNAS is configured as the master; Win10 as the slave. On a low battery condition, TrueNAS signals WinNUT on Win10 to shut down the Windows PC and then shut itself down. The arrangement works perfectly! Years ago, I use to have a ReadyNAS configured as a slave as well, before it decided to bite the dust. I would recommend @elvisimprsntr's solution as I know the shutdown arrangement works. Personally, I'd trust TrueNAS orchestrating the shutdown before I trust Windows doing the same.

Btw, I lost all the data on the ReadyNAS. I think Netgear use a proprietary version of RAID... X-RAID if I recall correctly. While the data was probably intact, it was the ReadyNAS h/w that failed and I didn't have a spare unit to move the disks into. Fortunately, that data was a backup copy being replicated from a FreeNAS server. After that, I set up replication between two FreeNAS servers to circumvent proprietary h/w solutions.
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Top