183 lines
4.2 KiB
Plaintext
183 lines
4.2 KiB
Plaintext
|
#! /bin/bash
|
||
|
|
||
|
### BEGIN INIT INFO
|
||
|
# Provides: sogo
|
||
|
# Required-Start: $network
|
||
|
# Required-Stop: $network
|
||
|
# Default-Start: 2 3 4 5
|
||
|
# Default-Stop: 0 1 6
|
||
|
# Short-Description: SOGo server
|
||
|
### END INIT INFO
|
||
|
|
||
|
# SOGo init script for Debian GNU/Linux
|
||
|
#
|
||
|
# Copyright (C) 2007-2009 Inverse inc.
|
||
|
#
|
||
|
# Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
||
|
# Ludovic Marcotte <ludovic@inverse.ca>
|
||
|
#
|
||
|
# This file 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, or (at your option)
|
||
|
# any later version.
|
||
|
#
|
||
|
# This file 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; see the file COPYING. If not, write to
|
||
|
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||
|
# Boston, MA 02111-1307, USA.
|
||
|
|
||
|
# specify more if you are using a load-balancer
|
||
|
PREFORK=1
|
||
|
SOGO_ARGS=""
|
||
|
USER=sogo
|
||
|
|
||
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
||
|
|
||
|
DAEMON=/usr/sbin/sogod-wrapper
|
||
|
NAME=sogod
|
||
|
DESC="Scalable OpenGroupware.Org"
|
||
|
|
||
|
PIDFILE=/var/run/sogo/sogod.
|
||
|
|
||
|
if [ -f /etc/default/sogo ]; then
|
||
|
. /etc/default/sogo
|
||
|
fi
|
||
|
|
||
|
if [ ! -x $DAEMON ]; then
|
||
|
echo "$DAEMON is not executable."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
if [ `/usr/bin/stat /var/run/sogo -c %U` != $USER ]; then
|
||
|
echo "/var/run/sogo is not owned by the ${USER}."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
if [ `/usr/bin/stat /var/spool/sogo -c %U` != $USER ]; then
|
||
|
echo "/var/spool/sogo is not owned by the ${USER}."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
if [ `/usr/bin/stat /var/log/sogo -c %U` != $USER ]; then
|
||
|
echo "/var/log/sogo is not owned by the ${USER}."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
case "$1" in
|
||
|
start)
|
||
|
echo $"Starting $DESC: "
|
||
|
for ((a=1; a <= PREFORK ; a++))
|
||
|
do
|
||
|
ppid="`cat ${PIDFILE}${a} 2> /dev/null`"
|
||
|
if [ -n "$ppid" ]
|
||
|
then
|
||
|
ppid="`ps --pid ${ppid} -o pid=`"
|
||
|
if [ -n "$ppid" ]
|
||
|
then
|
||
|
echo " $NAME $a already running. Skipped."
|
||
|
else
|
||
|
rm -f ${PIDFILE}${a}
|
||
|
start-stop-daemon -c $USER \
|
||
|
-b --start --quiet --exec $DAEMON $a
|
||
|
echo " $NAME $a (stale pid file removed)"
|
||
|
fi
|
||
|
else
|
||
|
start-stop-daemon -c $USER \
|
||
|
-b --start --quiet --exec $DAEMON $a
|
||
|
echo " $NAME $a"
|
||
|
fi
|
||
|
done
|
||
|
;;
|
||
|
|
||
|
stop)
|
||
|
echo $"Stopping $DESC: "
|
||
|
su "$USER" -c '/usr/bin/killall gdnc >& /dev/null'
|
||
|
# We kill the parent processes with SIGTERM so that they
|
||
|
# can exit gracefully.
|
||
|
for ((a=1; a <= PREFORK ; a++))
|
||
|
do
|
||
|
ppid="`cat ${PIDFILE}${a} 2> /dev/null`"
|
||
|
if [ -n "$ppid" ]
|
||
|
then
|
||
|
ppid="`ps --pid ${ppid} -o pid=`"
|
||
|
if [ -n "$ppid" ]
|
||
|
then
|
||
|
if kill $ppid >& /dev/null
|
||
|
then
|
||
|
echo " $NAME $a stopped"
|
||
|
fi
|
||
|
else
|
||
|
echo " $NAME $a not running"
|
||
|
fi
|
||
|
else
|
||
|
echo " $NAME $a not running"
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
sleep 1
|
||
|
# We kill the parent and child processes with SIGKILL to make sure they
|
||
|
# really are shutdown, and then we remove their pidfile.
|
||
|
for ((a=1; a <= PREFORK ; a++))
|
||
|
do
|
||
|
ppid="`cat ${PIDFILE}${a} 2> /dev/null`"
|
||
|
if [ -n "$ppid" ]
|
||
|
then
|
||
|
ppid="`ps --pid ${ppid} -o pid= 2> /dev/null`"
|
||
|
if [ -n "$ppid" ]
|
||
|
then
|
||
|
kill -9 $ppid >& /dev/null
|
||
|
pid="`ps --ppid ${ppid} -o pid= 2> /dev/null`"
|
||
|
if [ -n "$pid" ]
|
||
|
then
|
||
|
kill -9 $pid >& /dev/null
|
||
|
fi
|
||
|
echo " $NAME $a killed"
|
||
|
fi
|
||
|
fi
|
||
|
rm -f ${PIDFILE}${a}
|
||
|
done
|
||
|
;;
|
||
|
|
||
|
restart|force-reload)
|
||
|
echo $"Restarting $DESC: "
|
||
|
su "$USER" -c '/usr/bin/killall gdnc >& /dev/null'
|
||
|
for ((a=1; a <= PREFORK ; a++))
|
||
|
do
|
||
|
ppid="`cat ${PIDFILE}${a} 2> /dev/null`"
|
||
|
if [ -n "$ppid" ]
|
||
|
then
|
||
|
ppid="`ps --pid ${ppid} -o pid=`"
|
||
|
if [ -n "$ppid" ]
|
||
|
then
|
||
|
kill $ppid >& /dev/null
|
||
|
sleep 1
|
||
|
fi
|
||
|
ppid="`ps --pid ${ppid} -o pid=`"
|
||
|
if [ -n "$ppid" ]
|
||
|
then
|
||
|
pid="`ps --ppid ${ppid} -o pid=`"
|
||
|
kill -9 $ppid >& /dev/null
|
||
|
kill -9 $pid >& /dev/null
|
||
|
fi
|
||
|
rm -f ${PIDFILE}${a}
|
||
|
fi
|
||
|
start-stop-daemon -c $USER \
|
||
|
-b --start --quiet --exec $DAEMON $a
|
||
|
echo " $NAME $a"
|
||
|
done
|
||
|
;;
|
||
|
|
||
|
*)
|
||
|
N=/etc/init.d/$NAME
|
||
|
echo "Usage: $N {start|stop|restart|force-reload}" >&2
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
exit 0
|