Auto Mode Power Management
How does the "auto" mode work?
- There is a process running, waiting for WoL packets to arrive.
- This process can be found as "pwrmgr" in the process list.
- In addition to this, there is a script "/usr/local/sbin/pmcd_exec.sh" which uses a feature of the pwrmgr to keep the box alive even if there is no client anymore (e.g. in case of running backups, RAID recovery, running disk format etc.).
How to keep a box alive without a client in "auto" mode?
Sometimes one wants to keep the box alive until a script running on the box finished a long time task.
If the box is running in "auto" mode (means: staying alive until the last client stops sending WoL packets), one just has to call the next line once every 3 minutes to keep the box alive:
pwrmgr -c localhost act
But how to use this, if the long time task takes more than 3 minutes to finish?
Before starting the long time task, create a file in /var/lock/ you can test for existance:
Then start this script as a background task (means: add a " &" when calling the script):
#!/bin/sh while [ -f /var/lock/kenatonline ] ; do /usr/local/sbin/pwrmgr -c localhost act sleep 180 done
After the long time task, delete the file:
The box will shutdown automatically within 3 minutes.
Of course this will only work, if the long time task is synchronous itself (means: the long time task is blocking the user input until it has finished).
Is it asynchronous, you have to find the postcondition which is true when the task finished and replace the while condition of the script above (e.g. testing for the process of the long time task).
How to wake up and keep a box alive without using Buffalos applications?
Not everyone likes to use the utilities Buffalo provided (if they are available for the intended target operating system at all).
Adopt the following script to your needs:
- Set `bcast_addr` to the broadcast address for you network segment.
- In the example is is a private class B network 10.131/24 (10.131.0.0 - 10.131.255.255, netmask 255.255.0.0)
- If your netmask is /24 (255.255.255.0), you have to replace "10.131.255" with the first three numbers of your network segment.
- Set `target_mac` to the MAC address of the box you want to wake up. Colons are optional, case does not matter. So "ABCDEF123456" and "ab:cd:ef:12:34:56" are oth valid)
- The IP-address of your LS is not relevant in the code, but the MAC is.
#!/usr/bin/env python import socket import time bcast_addr = '10.131.255.255' # broadcast address for you network target_mac = "ab:cd:ef:12:34:56" # colons are optional, case does not matter mac = target_mac.replace(':', ) mac_bytes = .join([chr(int(mac[i:i+2], 16)) for i in range(0, len(mac), 2)]) WoL_packet = '\xff'*6 + mac_bytes * 16 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) while 1: s.sendto(WoL_packet, (bcast_addr, 9)) print "Sent paket!" time.sleep(180)
You can put the code example just into a file and start the python interpreter by hand providing the file as parameter or execute the file as a shell script (on UNIXoid systems like LINUX, Mac OS X, FreeBSD etc.).
On an Enigma2 Dreambox or Mac OS X you will have a python interpreter within the default installation of the system. Other systems may need an installation of the python package beforehand.