I have been trying to get my RaspberryPi ready to operate as a mobile robot. The first major hurdle was to create a process to monitor battery voltage and be able to stop the system if the voltage drops to a critical level. I wrote a daemon process to monitor the I2C ADC that measures the voltage as well as interfaced to custom PIC microcontroller to handle switching the power on and off from both a user button and GPIO pins on the Raspberry. Next step was to make the daemon run on start-up. I added a service file for the process and enabled that in systemd. That works well so the process now starts when the RaspberryPi boots up.
However all the signaling I added to the daemon is broken now. SIGUSR1 was supposed to cause the process to write a file that contained the current battery voltage and ADC output into a file so other processes could read the battery state on demand. That is not working at all, sending any signal at all to the process now causes it to die. SIGUSR2 was to be a way to force a system shutdown. That signal caused the daemon to send a KILL signal to the PIC over a GPIO pin and then used system() to call the poweroff command so the RaspberryPi did a clean shutdown and then the PIC pulls the plug when the GPIO line is released and floats back to it's normal condition. This is also broken and was a second big part of why I made the daemon in the first place.
How can I keep the signals working and start the daemon with systemd? How does it manage to intercept my signals even when I send them straight to the running daemon? All of this works perfectly if I run the daemon from the command line by hand.
So if it is started by systemd and I send SIGUSR1 then this happens:
[robot@robopi-1 ~]$ sudo kill -s SIGUSR1 116
[robot@robopi-1 ~]$ sudo systemctl status powermond
powermond.service - Custom power/battery monitor application for RaspberryPi
Loaded: loaded (/etc/systemd/system/powermond.service; enabled)
Active: failed (Result: signal) since Mon 2013-03-04 15:43:24 CST; 9s ago
Process: 116 ExecStart=/robot/sbin/powermond (code=killed, signal=USR1)
[robot@robopi-1 ~]$ sudo kill -s SIGUSR1 419
If I run it by hand at the command prompt it works and the correct information shows in syslog:
Mar 4 15:45:07 localhost powermond[419]: Starting power monitor process (0.85.0128)
Mar 4 15:45:07 localhost powermond[419]: Battery Status: 7.32V (54.5)
Mar 4 15:45:38 localhost powermond[419]: Signal Caught
Mar 4 15:45:38 localhost powermond[419]: SIGUSR1 - Write output file