-
Notifications
You must be signed in to change notification settings - Fork 0
/
freenetis-monitoring.init.sh
166 lines (143 loc) · 3.49 KB
/
freenetis-monitoring.init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#! /bin/bash
### BEGIN INIT INFO
# Provides: freenetis-monitoring
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Should-Start: $network $syslog
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop freenetis monitoring daemon
# Description: FreeNetIS monitoring script.
### END INIT INFO
################################################################################
# #
# This script serves for monitoring from IS FreeNetIS #
# #
# Author Kliment Michal 2012 #
# Email [email protected] #
# #
# Name freenetis-monitoring.init.sh #
# #
################################################################################
# Load variables from config file
CONFIG=/etc/freenetis/freenetis-monitoring.conf
# Name of monitoring daemon
MONITORD="freenetis-monitord"
# Path to monitoring daemon (without name)
MONITORD_PATH="/usr/sbin/"
# Load variables
if [ -e $CONFIG ]; then
. $CONFIG || true
else
echo "Config file is missing at path $CONFIG."
echo "Terminating..."
exit 0
fi
# try to create log file if not exists
if [ ! -e "$LOG_FILE" ] ; then
set +e
touch "$LOG_FILE"
set -e
fi
# disable logging if log cannot be written
if [ ! -w "$LOG_FILE" ]; then
echo "Cannot write to $LOG_FILE file => disabling logging"
LOG_FILE=/dev/null
fi
start_monitor()
{
# test if daemon is already started
if [ `ps aux | grep $MONITORD | grep -v grep | wc -l` -gt 0 ];
then
echo "Already started."
return 0
fi
echo -n "Starting FreenetIS monitor daemon: "
# max priority is set
if [ $MAX_PRIORITY -gt 0 ];
then
# create process for all priority from interval <0;MAX_PRIORITY>
for i in `seq 0 $MAX_PRIORITY`;
do
nohup $MONITORD_PATH$MONITORD $i 1>/dev/null 2>>$LOG_FILE &
done
else
# create one process for all priorities
nohup $MONITORD_PATH$MONITORD 1>/dev/null 2>>$LOG_FILE &
fi
# test if daemon is started
if [ `ps aux | grep $MONITORD | grep -v grep | wc -l` -gt 0 ];
then
echo "OK"
else
echo "FAILED!";
fi
}
stop_monitor()
{
# test if daemon is already stopped
if [ `ps aux | grep $MONITORD | grep -v grep | wc -l` -eq 0 ];
then
echo "Not running."
return 0
fi
echo -n "Stopping FreenetIS monitor daemon: "
# kill all processes
killall -q $MONITORD
# test if daemon is stopped
if [ `ps aux | grep $MONITORD | grep -v grep | wc -l` -eq 0 ];
then
echo "OK"
else
echo "FAILED!";
fi
}
status_monitor()
{
echo -n "FreenetIS monitor daemon is "
# test if daemon is already started
if [ `ps aux | grep $MONITORD | grep -v grep | wc -l` -gt 0 ];
then
echo "running."
else
echo "not running.";
fi
}
version_monitor ()
{
VERSION=`"$MONITORD" version 2>/dev/null`
echo $VERSION
}
usage_monitor()
{
echo "usage: `echo $0` (start|stop|restart|status|version)"
}
case "$1" in
start)
start_monitor
exit 0
;;
stop)
stop_monitor
exit 0
;;
restart|reload|force-reload) # reload is same thing as reload
stop_monitor
start_monitor
exit 0
;;
status)
status_monitor
exit 0
;;
version)
version_monitor
exit 0
;;
*)
usage_monitor
exit 0
;;
esac
exit 0