init,d startup script

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #241
    bsergean
    Guest

    Hello,

    Here is an init.d startup script, which works on my Mandriva Linux box but which should work elsewhere too. There is a small HOWTO in the header (service may only be available on RedHat based OS). Maybe tons of such things were already submitted, but just in case 🙂

    #!/bin/sh
    #
    # Startup script for the daap server
    #
    # chkconfig:2345 98 98
    # description: mt-daapd is a DAAP server
    #
    # processname: mt-daapd
    # pidfile: /var/run/mt-daapd.pid
    # config:
    #
    # Written by Benjamin Sergeant: bsergean gmail com
    # Quick HOWTO:
    # I called this script mt-daapd
    # su
    # cd /etc/init.d/
    # cp /path/to/mt-daapd .
    # chmod u+x mt-daapd
    # chkconfig mt-daapd
    #
    # From now on, use
    # service mt-daapd start # start
    # service mt-daapd stop # stop
    # service -f mt-daapd # restart
    #
    # Have fun !!

    me=mt-daapd
    DAAPD=/usr/local/sbin/mt-daapd
    ARGS=””
    pidfile=/var/run/mt-daapd.pid

    #DEBUG=true

    test -f $DAAPD || exit 0
    test x”$DEBUG” = x”true” && ARGS=”$ARGS -d 10″

    ok()
    {
    echo “[ OK ]”
    }
    error()
    {
    echo “[ Error ]”
    }
    echonl()
    {
    printf “%-30s” “$1”
    }

    alive()
    {
    test -f $pidfile || return 1
    ps -e | grep `cat $pidfile`> /dev/null 2> /dev/null
    ret=$?
    test x”$DEBUG” = x”true” && echo Alive: $ret
    return $ret
    }

    start()
    {
    echonl “Starting $me: “
    alive
    if test $? -eq 0 ; then
    error
    echo “Reason: Already running”
    exit 1
    fi
    $DAAPD $ARGS
    if test $? = 0 ; then ok ; else error ; fi
    }

    stop()
    {
    echonl “Shutting down $me: “
    alive
    if test $? -eq 0 ; then
    kill -INT `cat $pidfile`
    if test $? = 0 ; then ok ; else error ; fi
    rm -f $pidfile

    # FIXME: When restarting, sometimes mt-daapd exit with 0 but is not launched
    # (need to cleanup some stuff, flush some files ??)
    # with the sleep no problem. We should investigate the log file
    sleep 2
    else
    error
    echo “Reason: Not started”
    fi
    }

    status()
    {
    alive
    if test $? -eq 0 ; then
    pid=`cat $pidfile`
    echo “$me (pid $pid) is running…”
    else
    echo “$me is not alive”
    fi
    }

    case “$1” in
    start) start ;;
    stop) stop ;;
    status)status ;;
    restart) stop ; start ;;
    *) echo “Usage: $0 {start | stop | restart | status}” ; exit 1 ;;
    esac

    exit 0

Viewing 1 post (of 1 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.