Skip to main content.
June 18th, 2009

init.d template

This is a rudimentary template that I've been using for very quick and dirty /etc/init.d scripts recently.

It works under the assumption that your server daemon has a unique name and only ever runs a single instance - this also means that the binary and the init.d script cannot share a name - otherwise strange things happen ;)

Actual invocation logic may need to be updated on a per-service basis and chkconfig style headers would have to be added manually, but it works well for what it is.

#!/bin/bash

DIR=''  # path to the daemon executable
CMD=''  # name of the command itself
ARG=''  # optional. any arguments to pass when starting
NAM=''  # descriptive name of the daemon so it shows up pretty

function get_ps {
    ps --no-header -C${CMD}
}

function do_start {
    echo -n "Starting ${NAM}... "
    cd ${DIR}
    nohup ./${CMD} ${ARG} &
    SUCC=`get_ps | wc -l`
    if [ "1" == "$SUCC" ]; then
        echo "[SUCCESS]"
    else
        echo "[FAILURE]"
    fi
}

function do_stop {
    echo -n "Stopping ${NAM}... "
    PID=`get_ps | awk '{print $1}'`
    kill $PID
    SUCC=`get_ps | wc -l`
    if [ "0" == "$SUCC" ]; then
        echo "[SUCCESS]"
    else
        echo "[FAILURE]"
    fi
}

case "${1:-''}" in
    'start')
        do_start
        ;;
    'stop')
        do_stop
        ;;
    'restart')
        do_stop
        do_start
        ;;
    *)
        #echo "Usage: $SELF start|stop|restart|reload|force-reload|status"
        echo "Usage: $SELF start|stop|restart"
        exit 1
        ;;
esac

Posted by Ammon as play at 10:29 AM EDT

No Comments »

May 26th, 2009

gearman 0.3 php extension api

Posted by Ammon as play at 2:10 PM EDT

No Comments »

March 19th, 2009

mud revived, sorta

Posted by Ammon as mud, play at 10:05 AM EDT

No Comments »

February 13th, 2009

happy 1234567890

Posted by Ammon as play at 3:31 PM EST

No Comments »

February 4th, 2009

i <3 rsync

Posted by Ammon as hacker culture, howto, sysadmin, work at 3:07 PM EST

No Comments »

« Previous Entries