diff --git a/README.md b/README.md index 03eb7f6..f0f1c3c 100644 --- a/README.md +++ b/README.md @@ -150,4 +150,13 @@ +## Start +Das Script *monitord-start-stop* muss nach /etc/init.d/monitord kopiert werden. Standardmäßig läuft monitord unter der Benutzer *monitord*. Dieser muss vorher erstellt worden sein. +Die Datei /etc/init.d/monitord muss angepasst werden, so dass die korrekten Pfade zur ausführbaren Datei von monitord und zur monitord.xml eingetragen worden sind. + +Über + + /etc/init.d/monitord start + +lässt sich monitord starten. diff --git a/create-dist.sh b/create-dist.sh index 89f3654..27bea46 100755 --- a/create-dist.sh +++ b/create-dist.sh @@ -17,6 +17,7 @@ mkdir $TARGET_DIR cp monitord/monitord $TARGET_DIR cp monitord/plugins/.libs/libmplugin_activemq.* $TARGET_DIR +cp monitord/scripts/* $TARGET_DIR # find libactivemq LIBACTIVEMQ=`ldconfig -p | grep "activemq" | cut -d\> -f2` diff --git a/scripts/monitord-start-stop b/scripts/monitord-start-stop new file mode 100644 index 0000000..3c3fd43 --- /dev/null +++ b/scripts/monitord-start-stop @@ -0,0 +1,122 @@ +#!/bin/sh +# +# monitord This is the init script for starting monitord (ZVEI/POCSAG receiver) +# +# chkconfig: - 66 19 +# description: monitord +# processname: monitord +# pidfile: /var/run/monitord.pid +# +# basically taken from /etc/init.d/postgresql for CentOS 6.2 + +# load functions +. /etc/rc.d/init.d/functions + +NAME=`basename $0` + +if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ] +then + NAME=${NAME:3} +fi + +# SELinux +if [ -x /sbin/runuser ] +then + SU=runuser +else + SU=su +fi + +MONITORD=/opt/monitord/monitord +MONITORD_USER=monitord +MONITORD_CONFIG=/opt/monitord/monitord.xml +MONITORD_OPTS="" +MONITORD_STARTUP_LOG=/tmp/monitord-startup.log + +if [[ ! -x $MONITORD ]] +then + echo + echo "$MONITORD is missing or not executable" + echo + exit 1 +fi + +lockfile="/var/lock/subsys/${NAME}" +pidfile="/var/run/monitord.pid" + +script_result=0 + +start() { + if [ -z "$1" ] + then + echo "Waiting 15 seconds for coming up ActiveMQ..." + sleep 15 + fi + + MONITORD_START="Starting monitord..." + STARTUP_LINE="$MONITORD -c $MONITORD_CONFIG$MONITORD_OPTS" + + $SU -c "$STARTUP_LINE &" - $MONITORD_USER >> "$MONITORD_STARTUP_LOG" 2>&1 #< /dev/null + sleep 2 + pid=`ps -ef | grep "$STARTUP_LINE" | grep -v "grep" | awk '{ print \$2 }'` + + if [ "x$pid" != x ] + then + success "$MONITORD_START" + touch "$lockfile" + echo $pid > "$pidfile" + echo + else + failure "$MONITORD_START" + echo + script_result=1 + fi +} + +stop() { + echo -n "Stopping monitord service: " + if [ -e "$lockfile" ] + then + kill `cat $pidfile` + ret=$? + + if [ $ret -eq 0 ] + then + echo_success + rm -f "$pidfile" + rm -f "$lockfile" + else + echo_failure + script_result=1 + fi + else + echo_success + fi + echo +} + +restart() { + stop + start +} + +case "$1" in + start) + start + ;; + start-force) + start now + ;; + stop) + stop + ;; + restart) + restart + ;; + *) + echo $"Usage: $0 (start|stop|restart)" + exit 2 +esac + +exit $script_result +