Archive for May, 2008

Posted on 05-19-2008 under linux

The recent frequency of electric breakdowns, coupled with sitting in front of a dimmed laptop screen hoping against hope that the power would come back on before my battery died, produced an interesting result. Fortunately, my brain doesn’t need electricity to light bulbs in the air above my head.

With the blessings of KESC and Worldcall, I went through some web pages about ACPI, the linux power management framework. I found this website quite helpful. Really interesting stuff. (No seriously).

In particular, reading sections 6.3 and 6.4, I struck on a wonderful idea. What if I could log when KESC shuts down my electricity and when it brings it back up. Now what if that data were to be made available on the web!

No, its not that awesome. Still, it would be interesting to see the trends (or lack thereof), appearing through the statistics.

For those of you who don’t want to read my ravings about how I did it, here’s the link to the log. Let me know if you have any problems viewing it. Keep in mind, this is running off my laptop, with my not-so-reliable connection, so you might see some problems.

Now to the meat. There’s this daemon by the name of acpid which should be running on your linux system already. It’s included in most distributions, so if its not running you can probably install it very easily. This daemon has certain events that cause it to do certain things. For example, if you’ve got a laptop with some extra keys (brightness, hibernate etc.), its more than likely they’re functionality is controlled through the ACPI daemon. What we need to do is find the events corresponding to AC Power and Battery status. In my case these were ac_adapter and battery respectively. (If you haven’t read the sections in the article I mentioned earlier, I strongly recommend you do so before reading further. The path names could vary depending on your system, as they did in my case.)

What we need to know is that there needs to be a file in /etc/acpi/events/ that indicates which script to run when a particular even occurs. In addition, of course, there needs to be a script file for the acpi daemon to actually run when the event occurs. You can download my script files here.

You will probably have to change the paths in these scripts. The files powerlog.sh and battlog.sh should go into /etc/acpi, and the files ac_adapter and battery should go into /etc/acpi/events.

Once you’ve edited and copied to the proper directories, you need to restart the ACPI daemon. This can be done ( on a Debian system),

# /etc/init.d/acpid restart

And your scripts should start logging. Have fun!

For my part, I’ll keep my script running, and see what turns up.

Posted on 05-18-2008 under linux

Following on my previous two posts on No-IP, I finally figured out what was wrong with my system. In particular, even though the init scripts were installed, noip would not start at boot up. I had to manually run noip2 to start it up every time I rebooted.

The init scripts themselves were probably installed due to the debian package. I had earlier (naively) indicated that the init script would be installed by simply copying it to /etc/init.d/. This however is wrong and at the very least you would need to run update-rc.d to install it completely. A detailed description of init scripts under Debian can be read here.

I’m not sure if this was a problem with the debian package, but the script did not exist in /etc/rc2.d/. If you know anything about runlevels, you would know this is the runlevel in which debian enters after all initializations are complete to log the user in. I got wind of this when I did a find under the rc?.d directories

$ find /etc/rc*/ -name *noip*

which gave me

/etc/rc0.d/K20noip2
/etc/rc1.d/K20noip2
/etc/rc3.d/S20noip2
/etc/rc4.d/S20noip2
/etc/rc5.d/S20noip2
/etc/rc6.d/K20noip2

As you can see, rc2.d is missing. Sure enough adding a link in rc2.d fixed the problem.

Looking at the links in the other rc* directories, I found the name for the link I was about to create.

$ ls -l /etc/rc3.d/ | grep noip
lrwxrwxrwx 1 root root  15 2008-04-10 22:46 S20noip2 -> ../init.d/noip2

so,

# ln -s /etc/init.d/noip2 /etc/rc2.d/S20noip2

A quick reboot (ughh!) and a check

$ ps -A | grep noip
4108 ?        00:00:00 noip2

shows noip merrily buzzing away.

That was certainly a relief. I wasn’t looking forward to sludging through arcane scripting syntax, and obscure manuals.

Who am I kidding. I would’ve loved doing that :D