Protocol: | system daemon |
Standard Port: | N/A |
The Advanced Power Management
daemon (apmd)
is a system daemon that may be used to monitor the power status of a machine,
for hardware which supports the APM specification.
It is most useful on laptop computers,
where apmd will monitor the battery charge and charging status,
and may be used to put the system into various states of power conservation.
Normally, apmd is started up by the system boot scripts.
On my own laptop,
a year 2002 brand D
(Dell Latitude C610) running OpenBSD (3.4),
I have this setup for apmd running as a service under
daemontools instead.
First, the local service directory:
# mkdir -p /var/svc.d/apmd/log
Then the run
script for
/var/svc.d/apmd/run:
#!/bin/sh # apmd/run exec 2>&1 echo "*** Starting apmd..." exec \ /usr/sbin/apmd -d -m -t 11 ### that's all, folks!
In the invocation of apmd here,
the -d option is for debug
mode.
This runs the daemon in the foreground,
as is required for any daemontools service.
Here's the usual run
script for the logger in
/var/svc.d/apmd/log/run:
#!/bin/sh # apmd/log/run exec setuidgid multilog multilog t /var/multilog/apmd ### that's all, folks!
Prepare the log directory in /var/multilog:
# mkdir -p /var/multilog/apmd # chown multilog:nofiles /var/multilog/apmd
The apmd(8) program itself logs via syslog, so this multilog doesn't do much except show when the service was started. It seems like the -m option to apmd would result in power status messages for multilog, but I have not found this to be true on my own system.
That's about all there is to it. grep and kill the apmd program if it is already running. Then make this link into /service to bring the daemon up:
# ln -s /var/svc.d/apmd /service/apmd
Check to see if the daemon is listening with the apm(8) control program:
$ apm -v Battery state: high Battery remaining: 93 percent Battery life estimate: 156 minutes A/C adapter state: not connected Power management enabled
Don't forget to disable apmd in your system's boot scripts. On OpenBSD, set apmd_flags=NO in /etc/rc.conf.
Are there any advantages to running apmd as a service? For most users, probably not a great many. It's mostly a djb way thing, setting up as many daemontools services as possible.
On my own system, though, recovery from sleep
mode is now
much more reliable.
Before converting to a daemontools service,
sometimes pushing the power button to recover from sleep
wouldn't quite wake up the machine.
Indicator lights would blink a couple times,
but the machine would roll over back into its snooze.
A second push of the power button would then reboot!
Now the system wakes up just fine, every time.
Note: a slight imperfection in this machine, the auich sound device flubs the resume from suspend. For some reason, it comes back with the sound muted.
This problem is remedied by a simple script in /etc/apm/resume:
#!/bin/bash # /etc/apm/resume # === sleep 2 /usr/bin/mixerctl -w \ outputs.master.mute=off \ inputs.cd.mute=off \ inputs.dac.mute=off ### that's all, folks!
Make sure the script is executable, chmod +x. The system will now wake up with sound restored in all its high-fidelelity, ready for these great tunes!
Copyright © 2002, 2003, 2004, Wayne Marshall.
All rights reserved.
Last edit 2004.09.06, wcm.