Wednesday, March 21, 2012

Starting my Program as a Daemon

As an interim test, to run a monitor program as a daemon so I can log off and disconnect the Beaglebone from the net without killing the program, I used the start-stop-daemon command as follows:

root@beaglebone:~/tcl-from-beaglebone/tcl# start-stop-daemon -S -b \
         -x /usr/bin/tclsh -- beaglegsm.tcl

The program is a Tcl script, beaglegsm.tcl,  in a subdirectory of root. I give the full path to the tclsh command, but only the relative path to the script. The -b switch runs the program in the background. The -S switch says start the program. It seems to know whether one is already running and does not start a new one if so.

To stop the daemon use the -K switch:

root@beaglebone:~/tcl-from-beaglebone/tcl# start-stop-daemon -S -b \
         -x /usr/bin/tclsh -- beaglegsm.tcl

So I can start the daemn at boot time so it runs without needing to log on, I'll either put it in a cron entry (use @bootup for the time specification) or as a script in the /etc/init.d directory.

The program quits sometimes, without complaining, so I added a &>beaglegsm.out to the end to try and capture stdout and stderr for later analysis.

No comments:

Post a Comment