Remote Wake Up And Shut Down

Recently I have had to deal with several days of power outages and fluctuations. I have all my systems on UPS's however only one UPS has a usb connection so only one system knows how much battery life is left. For power fluctuations or small outages this is fine, but for long term outages it would be nice to shutdown all systems and when power returns power all systems back online.


I leave my Raspberry PI connected to my main ups, it has the lowest power consumption so it will stay up the longest and then use it to control the power of the other systems. I use ssh and samba client to perform remote shut downs and then wakeonlan to turn on systems.


Wake On Lan

To wake up a system it has to have a physical lan connection. As far as I know and as far as I have researched you cannot do wake on lan via wireless cards. However you can use a media bridge to connect a system(s) over wireless and maintain wake on lan compatibility.


First you have to install the client



To wake the system up you need to know the mac address of the system. In linux you can use "ifconfig" and look for the HWaddr section, in windows go to start->run, enter cmd, when the DOS window comes up do a "ipconfig /all" and look at the physical address section. The following example will use a mac address of 00:11:32:10:26:04



Shortly after this command the computer should start. If it does not check your BIOS settings to see if you have wakeonlan enabled. Most systems have it enabled but some have it disabled. Generally the settings are found under the power management section.


Remote Power Off

There are two systems that we need to look at to powering off, linux and windows. To turn off a linux system the easiest way is to ssh into it and then run the shutdown command. You can use ssh so that you dont need to put in a password to login to the other system. For windows you can use samba to run a remote shutdown command. Some windows sytems (vista to current) need to have two edits done to the systems to enable remote shutdown.


POWERING OFF LINUX SYSTEMS:


To enable ssh without a password we first generate a ssh key...



Then copy that key to the system(s) we want to shut down



Now to shutdown the remote host run the following command...



POWERING OFF WINDOWS SYSTEMS:


To shutdown windows system from a linux client you need to install the needed client tools



For windows vista and older systems you need to make some edits to enable remote power off.


Go to Start, type services.msc into the Start menu and press Enter.
Locate the “Remote Registry” service in the list
right-click it and select Properties.
From the properties window, set the Startup type to Automatic and click the Start button to launch the service.


Turn Firewall Off altogether or allow remote registry through


Go to Start, type regedit into the Start menu and press Enter.
Navigate to the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
Create the DWORD LocalAccountTokenFilterPolicy with the value "1"


Reboot the windows system to make the changes take effect...and now you can shutdown the remote windows system using the following command, replacing the uppercase values with your own.