Writing Debian init script for process that has no syslog integration
I have inherited ownership of a Debian server process that logs its error message to stdout/stderr. Currently its initscript has lines like:
start-stop-daemon [options] --exec $DAEMON -- $DAEMON_ARGS < /dev/null 2>&1 | logger $LOG_OPTIONS 2> /dev/null &
I have tried to abstract as much of that away as possible. The options specify a pid file, to make a pid file. A subsequent line tries to establish whether the process is up, though I think several conditions are not checked for. This script seems pretty ropey to me. I am trying to start again with the lsb-base one in /etc/init.d/skeleton though that is going to require a lot of modification.
Obviously the ideal would be to get the code change to use the syslog API however that is out of the question at least for now.
So the approach I experimenting with uses named pipes:
1.) Create a named pipe
2.) Start up a logger daemon that reads from the named pipe
3.) start up the server process that writes to the named pipe
It would be ideal for this if start-stop-daemon offered options to specify where the IO of the daemon process should be redirected to. However I am not about to offer to adopt that package (with ~400 bugs) so I doubt that will happen.
Trying to specify the redirection on the command line does not work. In the case of the logger daemon start-stop-daemon seems to hang on the system call. In the case of the server process the pipe gets closed when start-stop-daemon exits, so the logger daemon exits. None of that seems surprising.
So what I am doing now is to write simple wrapper scripts for the server and logger processes. Both wrapper scripts have this structure:
1.) sanity check the arguments
2.) exec program [suitable redirection of IO]
Then the start-stop-daemon can call the wrapper scripts as daemons. From my experiments so far this seems to work. However I feel a bit uncomfortable with this. It introduces several new wrapper scripts.
I cannot think of any obvious security holes but I suppose race conditions are inevitable.
|