2008-12-08 06:42:56 +00:00
|
|
|
#! /bin/sh
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: @DAEMON@
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 1
|
|
|
|
# Short-Description: Yandex daemon
|
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
USER=metrica
|
|
|
|
GROUP=metrica
|
|
|
|
SHELL=/bin/sh
|
|
|
|
PROGRAM=@DAEMON@
|
|
|
|
SYSCONFDIR=/etc/$PROGRAM
|
|
|
|
PIDDIR=/var/run/$PROGRAM
|
|
|
|
LOGDIR=/var/log/$PROGRAM
|
|
|
|
LOCALSTATEDIR=/var/lock
|
|
|
|
BINDIR=/usr/bin
|
2009-04-03 14:48:11 +00:00
|
|
|
CRONFILE=/etc/cron.d/@CRONFILE@
|
2008-12-08 06:42:56 +00:00
|
|
|
|
|
|
|
[ -x $BINDIR/$PROGRAM ] || exit 0
|
|
|
|
|
|
|
|
CNFFILE=$SYSCONFDIR/config.xml
|
|
|
|
PIDFILE=$PIDDIR/$PROGRAM.pid
|
|
|
|
LOCKFILE=$LOCALSTATEDIR/$PROGRAM
|
|
|
|
RETVAL=0
|
|
|
|
|
|
|
|
isrun()
|
|
|
|
{
|
2010-03-04 15:49:54 +00:00
|
|
|
[ -r "$PIDFILE" ] && pgrep -s `cat "$PIDFILE"` >/dev/null 2>&1
|
2008-12-08 06:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wait4done()
|
|
|
|
{
|
|
|
|
while isrun; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
start()
|
|
|
|
{
|
|
|
|
local EXIT_STATUS
|
|
|
|
EXIT_STATUS=0
|
|
|
|
|
|
|
|
echo -n "Start $PROGRAM service: "
|
|
|
|
|
2010-07-29 13:33:34 +00:00
|
|
|
isrun
|
|
|
|
if [ $? -eq 0 -o -f "$LOCKFILE" ]; then
|
2008-12-08 06:42:56 +00:00
|
|
|
echo -n "already running "
|
|
|
|
EXIT_STATUS=1
|
|
|
|
else
|
|
|
|
# Clean stale lock files
|
|
|
|
rm -f "$PIDFILE" "$LOCKFILE"
|
|
|
|
|
|
|
|
mkdir -p $LOGDIR
|
|
|
|
mkdir -p $PIDDIR
|
|
|
|
chown -R $USER:$GROUP $LOGDIR
|
|
|
|
chown -R $USER:$GROUP $PIDDIR
|
|
|
|
|
|
|
|
su -l $USER -s $SHELL -c "\"$BINDIR/$PROGRAM\" --daemon --pid-file=\"$PIDFILE\" --config-file=\"$CNFFILE\""
|
|
|
|
EXIT_STATUS=$?
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $EXIT_STATUS -eq 0 ]; then
|
|
|
|
touch "$LOCKFILE"
|
|
|
|
echo "DONE"
|
|
|
|
else
|
|
|
|
echo "FAILED"
|
|
|
|
fi
|
|
|
|
|
|
|
|
return $EXIT_STATUS
|
|
|
|
}
|
|
|
|
|
|
|
|
stop()
|
|
|
|
{
|
|
|
|
local EXIT_STATUS
|
2008-12-18 11:07:42 +00:00
|
|
|
EXIT_STATUS=0
|
2008-12-08 06:42:56 +00:00
|
|
|
|
|
|
|
echo -n "Stop $PROGRAM service: "
|
|
|
|
|
|
|
|
if isrun; then
|
2010-03-04 15:49:54 +00:00
|
|
|
if [ -f "$LOCKFILE" ]; then
|
2010-03-09 19:01:07 +00:00
|
|
|
kill -TERM `cat "$PIDFILE"`
|
2008-12-08 06:42:56 +00:00
|
|
|
wait4done
|
2010-07-29 13:33:34 +00:00
|
|
|
rm -f "$LOCKFILE"
|
2010-03-04 15:49:54 +00:00
|
|
|
else
|
|
|
|
echo "has been stopping already"
|
|
|
|
return 1
|
|
|
|
fi
|
2010-08-02 17:29:22 +00:00
|
|
|
else
|
|
|
|
rm -f "$LOCKFILE"
|
2008-12-08 06:42:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "DONE"
|
|
|
|
return $EXIT_STATUS
|
|
|
|
}
|
|
|
|
|
|
|
|
restart()
|
|
|
|
{
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
}
|
|
|
|
|
2010-03-09 19:01:07 +00:00
|
|
|
forcestop()
|
|
|
|
{
|
|
|
|
local EXIT_STATUS
|
|
|
|
EXIT_STATUS=0
|
|
|
|
|
|
|
|
echo -n "Stop $PROGRAM service: "
|
|
|
|
|
|
|
|
if isrun; then
|
|
|
|
if [ -f "$LOCKFILE" ]; then
|
|
|
|
rm -f "$LOCKFILE"
|
|
|
|
kill -9 `cat "$PIDFILE"`
|
|
|
|
wait4done
|
|
|
|
else
|
|
|
|
echo "has been stopping already"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "DONE"
|
|
|
|
return $EXIT_STATUS
|
|
|
|
}
|
|
|
|
|
|
|
|
forcerestart()
|
|
|
|
{
|
|
|
|
forcestop
|
|
|
|
start
|
|
|
|
}
|
|
|
|
|
2009-04-03 14:48:11 +00:00
|
|
|
enable_cron()
|
|
|
|
{
|
|
|
|
sed -i 's/^#*//' "$CRONFILE"
|
|
|
|
}
|
|
|
|
|
|
|
|
disable_cron()
|
|
|
|
{
|
|
|
|
sed -i 's/^#*/#/' "$CRONFILE"
|
|
|
|
}
|
|
|
|
|
2008-12-08 06:42:56 +00:00
|
|
|
# See how we were called.
|
|
|
|
EXIT_STATUS=0
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2009-04-06 08:32:43 +00:00
|
|
|
start && enable_cron
|
2008-12-08 06:42:56 +00:00
|
|
|
;;
|
|
|
|
stop)
|
2009-04-03 14:48:11 +00:00
|
|
|
disable_cron && stop
|
2008-12-08 06:42:56 +00:00
|
|
|
;;
|
|
|
|
status)
|
|
|
|
isrun && echo "$PROGRAM service is running" || echo "$PROGRAM service is stopped"
|
|
|
|
;;
|
|
|
|
restart)
|
2009-04-10 13:21:55 +00:00
|
|
|
restart && enable_cron
|
2008-12-08 06:42:56 +00:00
|
|
|
;;
|
2010-03-09 19:01:07 +00:00
|
|
|
forcestop)
|
|
|
|
disable_cron && forcestop
|
|
|
|
;;
|
|
|
|
forcerestart)
|
|
|
|
forcerestart && enable_cron
|
|
|
|
;;
|
2008-12-08 06:42:56 +00:00
|
|
|
reload)
|
|
|
|
restart
|
|
|
|
;;
|
|
|
|
condstart)
|
|
|
|
isrun || start
|
|
|
|
;;
|
|
|
|
condstop)
|
|
|
|
isrun && stop
|
|
|
|
;;
|
|
|
|
condrestart)
|
|
|
|
isrun && restart
|
|
|
|
;;
|
|
|
|
condreload)
|
|
|
|
isrun && restart
|
|
|
|
;;
|
|
|
|
fallenstart)
|
|
|
|
[ -r "$PIDFILE" ] && start
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: ${0##*/} {start|stop|status|restart|reload|condstart|condstop|condrestart|condreload|fallenstart}"
|
|
|
|
EXIT_STATUS=2
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit $EXIT_STATUS
|