#4 Daemonization possibilities

open
nobody
None
5
2009-10-19
2009-10-19
Anonymous
No

Please include daemonization possibilities to new versions. I'd like to start igmpproxy from rc.local scripts at system startup.

Discussion

  • I can provide daemonize patch used myself:

    diff -urBp igmpproxy.orig/src/igmpproxy.c igmpproxy/src/igmpproxy.c
    --- igmpproxy.orig/src/igmpproxy.c 2009-09-15 19:25:13.000000000 +0400
    +++ igmpproxy/src/igmpproxy.c 2009-09-15 19:56:19.000000000 +0400
    @@ -126,6 +126,20 @@ int main( int ArgCn, char *ArgVc[] ) {
    break;
    }

    + if ( !Log2Stderr ) {
    +
    + // Only daemon goes past this line...
    + if (fork()) exit(0);
    +
    + // Detach daemon from terminal
    + if ( close( 0 ) < 0 || close( 1 ) < 0 || close( 2 ) < 0
    + || open( "/dev/null", 0 ) != 0 || dup2( 0, 1 ) < 0 || dup2( 0, 2 ) < 0
    + || setpgrp() < 0
    + ) {
    + my_log( LOG_ERR, errno, "failed to detach daemon" );
    + }
    + }
    +
    // Go to the main loop.
    igmpProxyRun();

     

  • Anonymous
    2010-01-17

    The program can be run in background (from rc.local scripts) without any modifications to the original code. It also can create pid file (might be useful for killing, monitoring the daemon easier) when used with start-stop-daemon. Here's mine:

    #!/bin/bash
    ### BEGIN INIT INFO
    # Provides: igmpproxy
    # Required-Start: $remote_fs $syslog
    # Required-Stop: $remote_fs $syslog
    # Default-Start: 2
    # Default-Stop: 1
    # Short-Description: IP-TV multicast routing daemon
    ### END INIT INFO
    #
    # (c) hid3nax, 2o1o
    #

    PATH=/sbin:/bin:/usr/sbin:/usr/local/sbin:/usr/bin
    DAEMON=/usr/local/sbin/igmpproxy
    NAME=igmpproxy
    DESC="IP-TV routing daemon"
    PIDFILE="/var/run/$NAME.pid"
    PNAME="igmpproxy"
    DOPTIONS=""
    CONF="/etc/igmpproxy.conf"

    test -x $DAEMON || exit 0

    test -r $CONF || exit 0

    case "$1" in
    start)
    echo -n "Starting $DESC: "
    start-stop-daemon --start --make-pidfile --pidfile $PIDFILE --background --exec $DAEMON $DOPTIONS $CONF

    echo "$NAME."
    ;;
    stop)
    echo -n "Stopping $DESC: "

    start-stop-daemon --stop --pidfile $PIDFILE --name $PNAME --oknodo

    echo "$NAME."
    ;;
    restart)
    echo -n "Restarting $DESC: "
    start-stop-daemon --stop --pidfile $PIDFILE --name $PNAME --retry 5 --oknodo
    start-stop-daemon --start --make-pidfile --pidfile $PIDFILE --background --exec $DAEMON $DOPTIONS $CONF

    echo "$NAME."
    ;;
    *)
    echo "Usage: /etc/init.d/${0##*/} {start|stop|restart}" >&2
    exit 1
    ;;
    esac

    exit 0

     
  • There is no start-stop-daemon on most embedded platforms.