J
John Kelly
/*
Traditional daemons listen on a socket and never quit. To cooperate
and not interfere with file system dismounts, they begin work in the
top level / directory. To attain independence and preclude unwanted
interruptions, they detach themselves from any controlling terminal.
Not all daemons listen on sockets.
It's easy to code a script that reads standard input. And it's easy
to substitute a FIFO for standard input. And syslog will also write
selected output to a FIFO. Gluing those pieces together gives you a
real time log processor. It may not look like a traditional daemon,
but you want it to read the FIFO and never quit.
Or suppose you want to start an ordinary job without any controlling
terminal. Or suppose you want to prototype a socket daemon, using a
script language tool for rapid development. In any such case, there
are certain steps required for launching your job with a life of its
own, like a daemon.
Duplicating the same code in one program after another is boring and
messy. I wanted to synthesize the common elements of daemon startup
and distill them into a utility program.
So I developed dh, the daemon helper. Written in the C language, it
starts any program, script, or shell command as a daemon.
Before developing the daemon helper, I found sundry daemon utilities
available for download, but none of them worked the way I wanted one
to work, so off to work I went ...
Its usage is simple: dh [-p lock.pid] daemon args
The "daemon" can be a program or shell command, and the lock.pid, if
unspecified, will default to the base name of the daemon plus a .pid
suffix. The lock.pid name is used to prevent inadvertently starting
multiple instances of the same daemon; specifying different lock.pid
names on successive invocations will circumvent that control.
The lock.pid file also serves as a pid file and initial log file for
the daemon. The pid alone is on the first line, and the second line
contains the process group identifier. The third line begins a list
of environment variables and their values. Then follows a timestamp
and startup message. Standard output and standard error are sent to
the file, until redirected by the daemon to some other destination.
*/
P.S.
Producing a universal tool takes time, trial, and error, and I have
gradually refined dh to meet my needs. It has the potential to become a
standard tool, and I have ideas for further development, outlined in the
PLANNED.options file.
Whether my ideas become plans or not, dh is an open source project with
an Apache license. Small enough for an individual to comprehend, it may
appeal to C programmers having varied experience and interest.
The source code is freely available:
ftp://isp2dial.com/users/jak/src/dh/
To contact me, you can find my real email address in the headers of this
post, and in the file MY.MAILTO where the source code resides.
Traditional daemons listen on a socket and never quit. To cooperate
and not interfere with file system dismounts, they begin work in the
top level / directory. To attain independence and preclude unwanted
interruptions, they detach themselves from any controlling terminal.
Not all daemons listen on sockets.
It's easy to code a script that reads standard input. And it's easy
to substitute a FIFO for standard input. And syslog will also write
selected output to a FIFO. Gluing those pieces together gives you a
real time log processor. It may not look like a traditional daemon,
but you want it to read the FIFO and never quit.
Or suppose you want to start an ordinary job without any controlling
terminal. Or suppose you want to prototype a socket daemon, using a
script language tool for rapid development. In any such case, there
are certain steps required for launching your job with a life of its
own, like a daemon.
Duplicating the same code in one program after another is boring and
messy. I wanted to synthesize the common elements of daemon startup
and distill them into a utility program.
So I developed dh, the daemon helper. Written in the C language, it
starts any program, script, or shell command as a daemon.
Before developing the daemon helper, I found sundry daemon utilities
available for download, but none of them worked the way I wanted one
to work, so off to work I went ...
Its usage is simple: dh [-p lock.pid] daemon args
The "daemon" can be a program or shell command, and the lock.pid, if
unspecified, will default to the base name of the daemon plus a .pid
suffix. The lock.pid name is used to prevent inadvertently starting
multiple instances of the same daemon; specifying different lock.pid
names on successive invocations will circumvent that control.
The lock.pid file also serves as a pid file and initial log file for
the daemon. The pid alone is on the first line, and the second line
contains the process group identifier. The third line begins a list
of environment variables and their values. Then follows a timestamp
and startup message. Standard output and standard error are sent to
the file, until redirected by the daemon to some other destination.
*/
P.S.
Producing a universal tool takes time, trial, and error, and I have
gradually refined dh to meet my needs. It has the potential to become a
standard tool, and I have ideas for further development, outlined in the
PLANNED.options file.
Whether my ideas become plans or not, dh is an open source project with
an Apache license. Small enough for an individual to comprehend, it may
appeal to C programmers having varied experience and interest.
The source code is freely available:
ftp://isp2dial.com/users/jak/src/dh/
To contact me, you can find my real email address in the headers of this
post, and in the file MY.MAILTO where the source code resides.