Forked from
713 / Warden / Warden - archive
913 commits behind the upstream repository.
-
Tomáš Plesník authoredTomáš Plesník authored
wardend 3.92 KiB
#!/bin/bash
# Pri pouziti Apache + mod_perl se tento soubor nepouziva
#
# wardend
#
# Copyright (C) 2011-2012 Cesnet z.s.p.o
# Author(s): Tomas PLESNIK <plesnik@ics.muni.cz>
# Jan SOUKAL <soukal@ics.muni.cz>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name of the Cesnet z.s.p.o nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# This software is provided ``as is'', and any express or implied
# warranties, including, but not limited to, the implied warranties of
# merchantability and fitness for a particular purpose are disclaimed.
# In no event shall the Cesnet z.s.p.o or contributors be liable for
# any direct, indirect, incidental, special, exemplary, or consequential
# damages (including, but not limited to, procurement of substitute
# goods or services; loss of use, data, or profits; or business
# interruption) however caused and on any theory of liability, whether
# in contract, strict liability, or tort (including negligence or
# otherwise) arising in any way out of the use of this software, even
# if advised of the possibility of such damage.
### BEGIN INIT INFO
# Provides: wardend
# Required-Start: $local_fs $network $syslog $time
# Required-Stop: $local_fs $syslog $time
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start the Warden server
# Description: Starts or stops server for exchange of events
# among CSIRT teams
### END INIT INFO
VERSION="0.2"
DAEMON="/usr/local/bin/warden-server.pl"
PID_FILE="/var/run/warden-server.pl.pid"
LOCK_FILE="/var/lock/warden-server"
SCRIPTNAME=`basename "$0"`
# check if daemon is present and executable
test -x $DAEMON || exit 0
if [ $UID -ne 0 ]; then
echo "You must be root for runnnig this script!"
exit 1
fi
usage() {
echo "Usage: $0 [start|stop|status|restart|force-stop]"
exit 1
}
check_status() {
if /bin/ps axo pid,comm | grep -q "warden-serv*"; then
STATUS=1 # true - warden is running
else
STATUS=0 # false - warden is not running
fi
}
get_pid() {
PID=`ps axo pid,comm | grep "warden-serv*" | sed 's/^ \{1,4\}//g' | cut -f 1 -d " "`
return $PID
}
warden_start() {
check_status
if [ $STATUS -eq 1 ]; then
get_pid PID
echo "Warden server daemon is running (pid $PID)."
else
logger -s "Starting Warden server daemon ..."
$DAEMON
PID=`cat $PID_FILE`
logger -s "Warden server daemon is running (pid $PID)."
touch $LOCK_FILE
fi
}
warden_stop() {
check_status
if [ $STATUS -eq 1 ]; then
logger -s "Stopping Warden server daemon ..."
if [ -e $PID_FILE ]; then
PID=`cat $PID_FILE`
kill -1 $PID
rm -f $LOCK_FILE
logger -s "Warden server daemon (pid $PID) is stopped."
else
echo "Unable to stop Warden server daemon. Try to use: $SCRIPTNAME force-stop"
fi
else
echo "Warden daemon is NOT running."
fi
}
warden_status() {
check_status
if [ $STATUS -eq 1 ]; then
get_pid PID
echo "Warden daemon is running (pid $PID)."
exit 0
else
echo "Warden daemon is NOT running."
exit 1
fi
}
warden_force_stop() {
logger -s "Force stopping Warden server daemon ..."
get_pid PID
kill -9 $PID 1>/dev/null 2>&1
if [ -e $PID_FILE ]; then
rm -f $PID_FILE
fi
if [ -e $LOCK_FILE ]; then
rm -f $LOCK_FILE
fi
}
case $1 in
status)
warden_status
;;
start)
warden_start
;;
stop)
warden_stop
;;
force-stop)
warden_force_stop
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
usage
;;
esac
exit 0