Using daemon from /etc/init.d/functions

Dave Smith dave at thesmithfam.org
Fri Mar 30 14:27:03 MDT 2007


I've written a C++ server application for Linux, and it just runs in the 
foreground for now. It's come time to ship it to users, and I want to 
provide a Red Hat init script with it. I've written such an init script, 
and I use this in my script to start the server:

start() {
    echo -n $"Starting Dave's Server: "
    daemon /usr/bin/daves-server
    RETVAL=$?
    touch /var/lock/subsys/daves-server
    echo
    return $RETVAL
}

case "$1" in
  start)
    start
    ;;
...


The daemon function doesn't appear to background my executable. Do I 
need to fork() in my executable's code, or should daemon be 
backgrounding it for me somehow? I've read over the daemon function in 
/etc/init.d/functions, and it looks like it ends by running this command:

    initlog -q -c /usr/bin/daves-server

Anyway, just curious if I need to do my own forkin()'ing, or if Red 
Hat's daemon() is supposed to background it for me.

When I call daemon(int,int) (from unitstd.h) in my executable's code, 
the init script works fine, but I was just wondering if I could get away 
without doing that...

Thanks!


--Dave



More information about the PLUG mailing list