-
Notifications
You must be signed in to change notification settings - Fork 0
/
rs2slack.sh
executable file
·75 lines (64 loc) · 1.31 KB
/
rs2slack.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
#!/usr/bin/env bash
set -e
basedir=$(cd $(dirname $0);pwd)
program=${basedir}/rs2slack.py
logfile=${basedir}/log/rs2slack.log
nohupfile=${basedir}/log/nohup.out
pgrep_target="python ${program}"
monitor_threshold=$((6*60))
customenv=${basedir}/rs2slack.env
start() {
if [ 0 -lt $(pgrep -f "${pgrep_target}" | wc -l) ]
then
echo "already started."
else
nohup ${program} >> ${nohupfile} 2>&1 &
fi
}
stop() {
pkill -f "${pgrep_target}" || true
echo "killed." >> ${logfile}
}
monitor() {
echo $(date) monitor start
if [ ! -e ${logfile} ]; then
echo $(date) "log file ${logfile} does not exist."
echo $(date) "trying to start application."
stop
start
else
last_modified=$(date -r ${logfile} +%s)
current=$(date +%s)
if [ $((${last_modified} + ${monitor_threshold})) -lt ${current} ]
then
echo $(date) "log file ${logfile} has not been updated for ${monitor_threshold} seconds."
echo $(date) "trying to restart application."
stop
start
fi
fi
echo $(date) monitor end
}
cd ${basedir}
if [ -e ${customenv} ]; then
source ${customenv}
fi
case "$1" in
start)
stop
start
;;
stop)
stop
;;
restart)
stop
start
;;
monitor)
monitor
;;
*)
echo $"Usage: ${0} {start|stop|restart|monitor}"
exit 1
esac