File citadel.fedora of Package citadel
#!/bin/sh
#
# citadel Citadel Groupware Core
#
# chkconfig: 2345 20 80
# description: control citadel server start at boot time
# Copyright (c) 2011 Stefan Jakobs
# Author: Stefan Jakobs
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# /etc/init.d/citadel
### BEGIN INIT INFO
# Provides: citadel
# Required-Start: $local_fs $remote_fs $syslog
# Required-Stop: $local_fs $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: control citadel server start at boot time
# Description: control citadel server start at boot time
### END INIT INFO
# uncomment this to create coredumps as described in
# http://www.citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files
# ulimit -c unlimited
DESC="Citadel Groupware "
NAME=citserver
RUNDIR=/var/run/citadel
DAEMON=/usr/sbin/$NAME
PIDFILE=$RUNDIR/citadel.pid
SENDCOMMAND=/usr/sbin/sendcommand
LOCKFILE=/var/lock/subsys/$NAME
SETUP=/usr/sbin/citadel-setup
CONFIGURED=/var/lib/citadel/data/citadel.config
# Exit if the package is not installed
[ -x "$DAEMON" ] || { echo "$DAEMON not installed"; exit 1; }
# Source function library.
. /etc/rc.d/init.d/functions
# Read configuration variable file if it is present
[ -r /etc/sysconfig/citadel ] || { echo "citadel sysconfig file is not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 1; fi; }
. /etc/sysconfig/citadel
if [[ -n $CITADEL_HOME_DIR ]]; then
CITADEL_DAEMON_ARGS="$CITADEL_DAEMON_ARGS -h$CITADEL_HOME_DIR"
fi
start() {
[ -x $DAEMON ] || exit 5
if [ -f $CONFIGURED ] ; then
echo -n $"Starting $DESC: "
pidofproc -p $PIDFILE $DAEMON &> /dev/null && exit 0
daemon $DAEMON $CITADEL_DAEMON_ARGS \
-l$CITADEL_LOG_FACILITY -x$CITADEL_LOG_LEVEL \
-t$CITADEL_TRACE_FILE
retval=$?
else
retval=$?
echo "Citserver is not configured. Please run: '$0 setup'.";
fi
echo
[ $retval -eq 0 ] && touch $LOCKFILE
return $retval
}
stop() {
echo -n "Stopping $DESC: "
if $SENDCOMMAND "DOWN" &> /dev/null ; then
retval=$?
timer=0
killer=0
while pidofproc -p $PIDFILE $DAEMON &> /dev/null ; do
timer=$((timer+1))
sleep 1
if test "$timer" = "10"; then
killproc $DAEMON -TERM
retval=$?
killer=1
fi
if test "$timer" -ge "20"; then
killproc $DAEMON -KILL
retval=$?
killer=1
if test "$timer" eq "25"; then
echo "\tsomething went wrong ..."
exit 4;
fi
fi
done
else
retval=$?
fi
if [ $retval -eq 0 ] ; then
[ $killer -eq 0 ] && echo -en "\t\t\t\t [ OK ]"
rm -f $LOCKFILE
rm -f $PIDFILE
else
echo -en "\t\t\t\t [ FAIL ]"
fi
echo
return $retval
}
restart() {
stop
start
}
reload() {
echo -n "Reloading $DESC "
$SENDCOMMAND "DOWN 1" 2>&1|grep '^200 '>/dev/null
retval=$?
if [ $retval -eq 0 ] ; then
echo -e "\t\t\t\t [ OK ]"
else
echo -e "\t\t\t\t [ FAIL ]"
fi
return $retval
}
setup() {
$SETUP
}
force_reload() {
restart
}
rh_status() {
# run checks to determine if the service is running or use generic status
status $DAEMON
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
setup)
setup
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|setup}"
exit 2
esac
exit $?