forked from adam8157/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.sh
More file actions
executable file
·56 lines (49 loc) · 1.51 KB
/
monitor.sh
File metadata and controls
executable file
·56 lines (49 loc) · 1.51 KB
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
#!/bin/bash
#by michael
# you need to add this file to cron
#EXAMPLE: every 1 minitue to execute
# m h dom mon dow user command
#*/1 * * * * {PATH}/monitor.sh
#SYSLOG=local0 # Which syslog facility to use (disabled if blank)
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:$LD_LIBRARY_PATH
NAME=monit
BIN_PREFIX=/usr/local/sbin
LOG_PREIFX=/tmp
LOG_RUN=$LOG_PREIFX/${NAME}modules_runing.log
LOG_MODULE=$LOG_PREIFX/${NAME}.log
# you should add you programm into the MOUDLES
MODULES="prg1 prg2" #modules we will be start
message(){
DATE=$(date '+%F %T ')
if test "x$SYSLOG" != "x" ; then
logger -p "${SYSLOG}.warn" -t $NAME[$$] "$1"
fi
if test "x$LOG_RUN" != "x" ; then
echo "$DATE: $1" >> "$LOG_RUN"
fi
#echo "$DATE: $1" >&2
}
monitor_modules(){
for prg in $MODULES
do
prg=$BIN_PREFIX/$prg
if [ -x $prg ] ;then
old_prg=$(pgrep -f "$prg") ##XXX: module name must be not belongto each other: mqtt-uc mqtt-uc2
if [ -z "$old_prg" ]; then
LOG=$LOG_PREIFX/`basename $prg`.log
($prg &>> $LOG&) && message "^^^^^^^-->$prg is died, restarted"
#($prg &>> /dev/null&) && message "^^^^^^^-->$prg is died, restarted"
fi
else
message "XXXXXXX--> Cannot found $prg!"
fi
done
}
main(){
if [ ! -d `dirname $LOG_RUN` ]; then
mkdir `dirname $LOG_RUN` || echo "Cannot find directory `dirname $LOG_RUN`"
else
monitor_modules
fi
}
main