IPPOWER - Automatic Power-Cycler

Copyright (c) 2006 Hiro Sugawara

GENERAL

IPPOWER is a Linux service that monitors a computer's external device availability (response to PING) and, if a certain device appears dead because it does not respond to PING for a while, automatically restarts the device by doing a power-cycle.

BACKGROUND

I am using an ADSL modem for my Internet connection. The modem locks up (provides no communication) once in a while, say two to three times a year. The exact cause of the lock-ups is unknown; it may be a firmware bug or some kind of glitch on the telephone line (though I have installed an inline filter on its telco line). Two or three failures a year may not sound significant, but, as Murphy's law tells, they usually happen at the worst times. Last summer it happened when my whole family was on vacation in a foreign country for two weeks. I lost communication with my home server and started worrying if my house had caught a fire or a group of thieves had taken away everything. After coming back home I found there was possibly a power outage for the whole house because many appliances had blinking clock display. My servers were still up because they were on a UPS, but the ADSL modem was dead. This was strange because the ADSL modem was also on a UPS, but there might be extra vulnerability beyond my knowlege.

So, I decided to prepare precautions to reduce the risk. The first measure was to subscribe to an external secondary SMTP server for my own domain, that is primarily served by my in-house SMTP server, in order to prevent incoming mail from bouncing in case my own SMPT server is not accessible. The second was to build a scheme to restart a dead network device automatically. The latter is this IPPOWER project.

IP-POWER 9258: IPPOWER uses a network-controlled power controller, namely the IP-Power 9258. A simple web interface can individually turn on and off its four AC outlets. It also has a simple timer-driven power control so that, once a timer is set via the web interface, an outlet can be automatically turned off and on without direct control by a host computer, though my IPPOWER project does not use this feature. There are two versions, once of the U.S. (100-120V) market and another for the European (220-240V) market. I bought one from eBay under $100US.

The IP-Power is a very simple but useful device. One caveat is the IP-Power 9258 has only one AC inlet that is shared by all of its AC outlets as well as its own power supply, so that, if an IP-Power 9258 is on a UPS, all the controlled devices must share that same UPS.

WEB POWER: Well, not everything goes well. A few months after I wrote the first version of this document, my IP-Power 9258 died; it started to keep beeping and power-cycling in a few second interval and of course it no longer responded to network accesses. I guess the power supply circuit is dead. I tried to contact the eBay vendor I purchased the unit from with no luck. I could not locate the manufacture at all. Another major distributor of the IP-Power 9258 advised me to update the unit's firmware through its serial port although I had told them the unit's hardware had seemed dead. I disassembled the box to locate the failure source, say just a blown fuse or a burned resister, but I was unsuccessful.

So, instead of spending more time on the dead box, I looked for an alternative solution and I found the Web Power from XXX at a local suplus store under $80US. The first unit I got was dead but a replacement worked fine. The Web Power works in a very similar way to the IP-Power; only the URLs had to be changed and this was within my original preparation for portablity of my code. I created a new device file that describes the device dependent functionality of the Web Power device and modified all port files to point to the new device file.

IPPOWER

IPPOWER is a simple chkconfig-compliant service and it is written entirely in the Bash scriptive language. It is easily configurable.

LICENSE

IPPOWER is freely usable and redistributable under the terms of GNU GENERAL PUBLIC LICENSE.

INSTALLATION

Intalling IPPOWER is pretty streigtforward as long as the target system has a RedHat or similar Linux installation that supports BSD style chkconfig. Unfortunately, I have little experience with other installations such as Suse and Debian so that I cannot provide good support for them.

Firstly, set up the IP-Power 9258 for it networking connection and account management (user name and password). Refer to the accompanying document except for the URL-based AC outlet control. The document has serious errors in this area and below is the correct URLs that I verifeied to work.

http://username:password@XXX.XXX.XXX.XXX.XXX/Set.cmd?CMD=***Power+para1=*+para2=*+para3=*...
  • Default username is admin
  • Default password is 12345678
  • XXX.XXX.XXX.XXX is the IP address of 9258
  • CMD=***Powers is the function module of 9258
  • para1 - para3 parameters
  • Example: contorl the power supply of 9258

    http://admin:12345678@192.168.1.10/Set.cmd?CMD=SetPower+P60=1+P61=1+P62=1+P63=0
    

    Make sure the IP-Power 9258 is given either a fixed IP address or a fixed host name that is always accessible from the targe Linux host. This usually requires editing of the DNS and DHCP (if used) files (and restarting these services).

    Secondly, create a special user account "ippower" on the Linux host. This should reduce the risk of unwanted hacks taking advantage of super user script processes.

    bash# groupadd -g 406 ippower
    bash# useradd -g 406 -u 406 -s /sbin/nologin ippower
    

    Next, unzip the distribution file into a work directory and edit a few file for local configuration.

    MODULE STRUCTURE

    IPPOWER consists of multiple layers of configuration files for good modularity. The configuration files are all resident in the same directory (normally /etc/ippower.d) but distinguished by their file name suffixes.

    Port Files (*.pwr)

    A port file defines an individual AC oulet controlled by IPPOWER. A port file needs the following shell variables defined:
    ippName The name of the equipment connected to the AC outlet
    ippDevcice The base name of the IPPower device file this AC outlet belongs to
    ippPort The port name of this AC outlet such as "P60"
    pingAddress The IP address to ping for accessibility checcking

    The following shell variables are optional and the default values in parenthesis will be used if not defined. All times are in number of seconds.

    powercycleDelay The time between turning off and on (10 seconds)
    bootDelay The time between power-cycle and resumption of ping (600 seconds)

    Device Files (*.dev)

    A device file defines an IP-Power deivce controlling one or more AC outlet ports defined by port files. A device file needs the following shell variables defined:
    ippModel The model name of the IP-Power device, the base name of the IP-Power model file
    ippHost The host name or the IP address of this IP-Power device
    ippLogin The login name for this IP-Power device
    ippPasswd The password for this IP-Power device

    Model Files (*.ipp)

    A model file defines an IP-Power deivce model's specific items. A model file needs the following shell functions defined:
    turnon The function to turn on AC power at port $ippPort
    turnoff The function to turn off AC power at port $ippPort