Skip to content

Instantly share code, notes, and snippets.

@gboudreau
Created June 8, 2011 20:34
Show Gist options
  • Save gboudreau/1015337 to your computer and use it in GitHub Desktop.
Save gboudreau/1015337 to your computer and use it in GitHub Desktop.
/etc/init.d/greyhole for Debian 6
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: greyhole
# Required-Start: $network $local_fs $remote_fs mysql samba
# Required-Stop: $network $local_fs $remote_fs mysql samba
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start Greyhole daemon
### END INIT INFO
# Copyright 2009 Guillaume Boudreau
#
# This file is part of Greyhole.
#
# Greyhole is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Greyhole is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Greyhole. If not, see <http://www.gnu.org/licenses/>.
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
fi
DAEMON="greyhole"
PIDFILE="/var/run/greyhole.pid"
LOCKFILE="/var/lock/subsys/greyhole"
status () {
PID=`cat $PIDFILE 2>/dev/null`
if [ -f $PIDFILE -a "`ps ax | grep \"^ *$PID.*greyhole --daemon\" | grep -v grep | wc -l`" -eq "1" ]; then
echo " Greyhole is running."
else
echo " Greyhole isn't running."
fi
exit $?
}
daemon_start () {
nice -n 1 $DAEMON --daemon > /dev/null &
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
touch $LOCKFILE
ps ax | grep "$DAEMON --daemon" | grep -v grep | tail -1 | awk '{print $1}' > $PIDFILE
fi
return $RETVAL
}
start () {
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
fi
if [ -f $LOCKFILE -a -f $PIDFILE -a "`ps ax | grep \"^$PID.*greyhole --daemon\" | wc -l`" -eq "1" ]; then
echo "Greyhole is already running."
return 0
fi
/sbin/start-stop-daemon --start --pidfile $PIDFILE --exec $0 --background -- daemon_start
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
echo " Starting Greyhole succeeded"
else
echo " Starting Greyhole failed"
fi
echo
return $RETVAL
}
stop () {
/sbin/start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile $PIDFILE --name $DAEMON
RETVAL=$?
[ $RETVAL -eq 0 ] && echo " Stopping Greyhole succeeded" || echo " Stopping Greyhole failed"
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE $PIDFILE
echo
return $ret
}
restart () {
stop
sleep 1
start
}
condrestart () {
[ -e $LOCKFILE ] && restart || :
}
case "$1" in
status)
status
;;
start)
start
;;
daemon_start)
daemon_start
;;
stop)
stop
;;
restart)
restart
;;
force-reload)
restart
;;
condrestart)
condrestart
;;
*)
echo "Usage: $0 {start|stop|status|condrestart|restart}"
exit 1
;;
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment