Visit me elsewhere:

init.d scripts

start-stop-daemon script with pidfile - nice 19 for low priority

#!/bin/bash

NAME=agg-update
USER=www-data
GROUP=www-data
NICE=19
PID=/var/run/$NAME.pid

BIN=/usr/bin/php
EXECDIR=/var/www/tt-rss
SCRIPT=/var/www/tt-rss/update_daemon2.php
ARGS="--file $SCRIPT"


start() {
      echo "Starting $NAME"
      start-stop-daemon --quiet --start --background --chuid "$USER" --group "$GROUP" --chdir $EXECDIR --exec $BIN --nicelevel $NICE --pidfile $PID --make-pidfile -- $ARGS
      RETVAL=$?
}
stop() {
      echo "Stopping $NAME"
      start-stop-daemon --quiet --stop --pidfile $PID
      RETVAL=$?
}
status() {
      echo -n "Status: "
      ps -p `cat /var/run/agg-update.pid` > /dev/null && echo "Running" || echo "Stopped"
}

case "$1" in
    start)
      start
  ;;
    stop)
      stop
  ;;
    restart)
      stop
      start
  ;;
    status)
      status
  ;;
    *)
      echo "Usage: $NAME {start|stop|restart|status}"
      exit 1
  ;;
esac

exit $RETVAL

start-stop-daemon script with pidfile, checking for pidfile existance - nice 19 for low priority

#!/bin/sh
### BEGIN INIT INFO
# Provides:          etpub
# Required-Start:    $network $remote_fs $local_fs
# Required-Stop:     $network $remote_fs $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Stop/start etpub
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/srv/et/etpub
DESC="etpub server"
NAME=etpub

USR=et
DIR=/srv/etpub
PORT=27960

# NoQuarter
# MOD=nq
# DAEMON_ARGS="+set dedicated 2 +set net_port $PORT +set sv_maxclients 20 +set fs_homepath $DIR +set fs_basepath $DIR +set fs_game $MOD +set com_hunkMegs 128 +set com_zoneMegs 24 +set vm_game 0 +set ttycon 0 +exec server.cfg"

# Silent
# MOD=silent
# DAEMON_ARGS="+set dedicated 2 +set net_port $PORT +set sv_maxclients 20 +set fs_homepath $DIR +set fs_basepath $DIR +set fs_game $MOD +set com_hunkMegs 128 +set com_zoneMegs 24 +set vm_game 0 +set ttycon 0 +exec silent.cfg"

# Nitmod
MOD=nitmod
DAEMON_ARGS="+set dedicated 2 +set net_port $PORT +set net_port_extra 27965 +set sv_maxclients 20 +set fs_homepath $DIR +set fs_basepath $DIR +set fs_game $MOD +set com_hunkMegs 128 +set com_zoneMegs 24 +set vm_game 0 +set ttycon 0 +exec nitmod.cfg"

DAEMON=$DIR/etded300.x86
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME


# Functions
do_start()
{
    cd $DIR
    #--chdir $DIR
    start-stop-daemon --start --oknodo --chuid $USR --make-pidfile --pidfile $PIDFILE --background --exec $DAEMON -- $DAEMON_ARGS
    RETVAL=$?
}
do_stop()
{
    start-stop-daemon --stop --oknodo --user $USR --pidfile $PIDFILE --retry 5
    RETVAL=$?
}


# Param-Switch
case "$1" in
    start)
        do_start
        ;;
    stop)
        do_stop
        ;;
    status)
        echo -n "Status: "
        if [[ -f $PIDFILE ]] ; then
          ps -p `cat $PIDFILE` > /dev/null 2>/dev/null && echo "Running" || echo "Stopped"
        else
          echo "Stopped"
        fi
        ;;
    reload|force-reload)
        ;;
    restart|force-reload)
        do_stop
        do_start
        ;;
    *)
        echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
        exit 3
        ;;
esac

exit $RETVAL