Skip to content

chkconfig script for fanout

qirtaiba edited this page Jan 15, 2013 · 9 revisions

Save the following script as: /etc/init.d/fanout

To modify it to work on Debian or derivative distributions, just change "nobody:nobody" to "nobody:nogroup" and change ". /etc/init.d/functions" to ". /lib/lsb/init-functions", then run "update-rc.d fanout defaults" to install in the default runlevels.

#!/bin/bash
#/etc/init.d/fanout
# Cam McKenzie 
# www.cammckenzie.com
# Cent-OS 6.3 / Fedora / Redhat Compatible 
# Don't forget to: chmod +x /etc/init.d/fanout
# chkconfig --add fanout
# and finally start the service:
# service fanout start

# chkconfig: 2345 99 25
# description: Fanout - SparkleShare announcement server service

### BEGIN INIT INFO
# Provides: fanout
# Required-Start: $network 
# Required-Stop: $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Should-Start: 
# Should-Stop: 
# Short-Description: Fanout - SparkleShare announcement server service
# Description: Fanout - SparkleShare announcement server service
### END INIT INFO

# Source function library.
. /etc/init.d/functions


FANOUT_BIN="/usr/bin/fanout"
RUNAS="--run-as=nobody:nobody"
DAEMON="--daemon"
LOGFILE="/var/log/fanout.log"
LOGGING="--logfile="
LOGSIZE="--max-logfile-size=5"
PIDFILE="/var/run/fanout.pid"
DEBUG="--debug-level=3"

check_log_file()
{
        if [ ! -f $LOGFILE ]; then
                touch $LOGFILE && chown nobody:root $LOGFILE
        fi
}

case "$1" in
        start)
                echo "Starting Fanout..."
                check_log_file
                if [ ! -f $FANOUT_BIN ]; then
                        echo "Error: $FANOUT_BIN not found"
                        exit 5
                fi
                $FANOUT_BIN $RUNAS $DAEMON $LOGGING$LOGFILE $LOGSIZE --pidfile=$PIDFILE
                exit $?
                ;;

        stop)
                echo "Shutting down Fanout..."
                if [ ! -f "$PIDFILE" ]; then
                  echo "Error: Fanout not running or PIDFILE unreadable"
                  exit 1
                fi
                PID="`cat $PIDFILE`"
                if [ "$PID" != "" ]; then
                        kill -TERM "$PID" >/dev/null 2>&1
                        if [ $? -ne 0 ]; then
                                echo "Error: Fanout not running"
                                exit 1
                        fi
                else
                        echo "Error: Fanout not running or PIDFILE unreadable"
                        exit 1
                fi
                sleep 2
                exit 0
                ;;

        restart)
                echo "Shutting down Fanout..."
                 stop >/dev/null 2>&1
                 start
                exit $?
                ;;

        status)
                echo "Status not implemented yet..."
                exit 0
                ;;
        *)
                echo "Usage:  {start|stop|restart|status}"
                exit 0
                ;;
esac
Clone this wiki locally