rshdown(1) - Linux man page
Name
rshdown - Remote shutdown.
Synopsis
rshdown [<configfile>]
Description
The program listens on an UDP port for shutdown data packets. If a valid shutdown data packet was received the program shuts down the computer.
If you have two computers powered by the same UPS you can connect the signal cable to one of them. If power is off for too long and the computer with the signal cable goes down it can notify the other computer to shut down too.
Return Value
The program is running as a daemon, it does not return a value.
Example
Create a file containing up to 1500 bytes random data (you can use the rndbytes program to do so).
Copy this file to /etc/rshdown-secret on both computers. Use a secure mechanism to transfer the file (i.e. scp) and set permissions to 600.
Choose a free port number on the shutdown master (the computer with the signal cable) and the shutdown slave (the other computer). In the example we use port 2 on both systems.
On the shutdown master modify the startup scripts to create an indicator file, i.e. ''/var/run/rshdown/rshdown.txt' on each reboot.
Modify the the shutdown scripts to check for the presence of the indicator file, if the file exists send the data packet.
#! /bin/sh
if [ -f /var/run/rshdown/rshdown.txt ]
then
for i in 1 2 3 4 5 6 7 8 9 10
do
nc -u -p 2 -w 2 slave 2 < /etc/rshdown-secret
done
fiOn the shutdown slave create a shutdown script /etc/powerfail-fast:
/etc/powerfail-full > /dev/null 2>&1 &The /etc/powerfail-fast must return immediately, longer processes (the full shutdown) must go to background.
The /etc/powerfail-full script, i.e.
/usr/sbin/poweroffdoes a shutdown of the system.
Create the configuration file /etc/rshdown.conf
sender-ip 192.168.1.2 sender-port 2 receiver-ip 192.168.1.3 receiver-port 2 file /etc/rshdown-secret action /etc/powerfail.fastModify the startup scripts to run
rshdown /etc/rshdown.confwhen the system is booted.
Author
Dirk Krause
Copyright And License
Copyright © 2010, Dirk Krause All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Dirk Krause nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
See Also
rndbytes(1), scp(1), shutdown(1), http://dktools.sourceforge.net/rshdown.html