Merge branch 'master' of mathias-kettner.de:omd
[omd.git] / packages / check_mk / skel / etc / init.d / mkeventd
blob371a8dcfe915cea3ca31ef65321f2ef03613fe22
1 #!/bin/bash
3 unset LANG
5 PIDFILE=$OMD_ROOT/tmp/run/mkeventd/pid
6 STATUS_SOCKET=$OMD_ROOT/tmp/run/mkeventd/status
7 DAEMON=$OMD_ROOT/bin/mkeventd
8 STATEFILE=$OMD_ROOT/var/mkeventd/status
9 THE_PID=$(cat $PIDFILE 2>/dev/null)
10 # OPTS="--debug"
11 OPTS=""
13 . $OMD_ROOT/etc/omd/site.conf
14 if [ "$CONFIG_MKEVENTD" != on ] ; then
15 exit 5
18 case "$1" in
19 start)
20 if [ "$CONFIG_MKEVENTD_SYSLOG" = on ] \
21 || [ "$CONFIG_MKEVENTD_SYSLOG_TCP" = on ] \
22 || [ "$CONFIG_MKEVENTD_SNMPTRAP" = on ]; then
24 ADD_TXT=
25 if [ "$CONFIG_MKEVENTD_SYSLOG" = on ]; then
26 ADD_TXT+='syslog-udp,'
27 OPTS+=' --syslog --syslog-fd 3'
29 if [ "$CONFIG_MKEVENTD_SYSLOG_TCP" = on ]; then
30 ADD_TXT+='syslog-tcp,'
31 OPTS+=' --syslog-tcp --syslog-tcp-fd 4'
33 if [ "$CONFIG_MKEVENTD_SNMPTRAP" = on ]; then
34 ADD_TXT+='snmptrap,'
35 OPTS+=' --snmptrap --snmptrap-fd 5'
38 echo -n "Starting mkeventd (builtin: ${ADD_TXT%*,})..."
39 if kill -0 $THE_PID >/dev/null 2>&1; then
40 echo 'Already running.'
41 exit 0
45 ${DAEMON}_open514 $OPTS
46 else
47 echo -n 'Starting mkeventd...'
48 if kill -0 $THE_PID >/dev/null 2>&1; then
49 echo 'Already running.'
50 exit 0
52 $DAEMON $OPTS
54 echo OK
56 stop)
57 echo -n 'Stopping mkeventd...'
58 if [ -z "$THE_PID" ] ; then
59 echo 'Not running.'
60 else
61 echo -n "killing $THE_PID..."
62 kill $THE_PID 2>/dev/null
63 if [ $? -eq 0 ]; then
64 # Only wait for pidfile removal when the signal could be sent
65 N=0
66 while [ -e "$PIDFILE" ] ; do
67 sleep 0.5
68 echo -n .
69 N=$((N + 1))
70 if [ $N -gt 20 ] ; then
71 echo "PID file did not vanish."
72 exit 1
74 done
75 else
76 # Remove the stale pidfile to have a clean state after this
77 rm $PIDFILE
79 echo 'OK'
82 restart)
83 $0 stop && sleep 1 && $0 start
85 reload)
86 echo -n 'Reloading mkeventd...'
87 if [ -z "$THE_PID" ] ; then
88 echo 'Not running.'
89 exit 1
90 else
91 echo "killing $THE_PID with SIGHUP..."
92 kill -1 $THE_PID
96 status)
97 echo -n 'Checking status of mkeventd...'
98 if [ -z "$THE_PID" ] ; then
99 echo "not running (PID file missing)"
100 exit 1
101 elif ! kill -0 $THE_PID ; then
102 echo "not running (PID file orphaned)"
103 exit 1
104 else
105 echo "running"
106 exit 0
109 flush)
110 if [ -n "$THE_PID" ] && kill -0 $THE_PID ; then
111 echo -n "Flushing current state and history..."
112 result=$(echo "COMMAND FLUSH" | unixcat $STATUS_SOCKET)
113 if [ "$result" = "None" ] ; then
114 echo OK
115 exit 0
116 else
117 echo "ERROR: $result"
118 exit 1
120 else
121 echo -n "Deleting status and history files..."
122 rm -f $OMD_ROOT/var/mkeventd/{status,master_config,slave_status,history/*}
123 echo OK
124 exit 0
128 echo "Usage: $0 {start|stop|restart|reload|status|flush}"
130 esac