-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkRunning
executable file
·112 lines (86 loc) · 2.09 KB
/
checkRunning
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
#!/bin/bash
dirName=`dirname $0`
progName=`basename $0`
# Directories
root="$HOME"
dropin="$root/dropin"
running="$root/running"
logDir="$root/log"
mkdir -p $logDir
mkdir -p $dropin
mkdir -p $running
# files
watchdogLog="$logDir/watchdog.log"
me=`whoami`
# Usage
# =====
function usage() {
echo "NOM"
echo " $progName"
echo "SYNOPSIS"
echo " $progName"
echo "DESCRIPTION"
echo " Script which checks if the manager is already running, and restarts"
echo " it if nedded."
echo " Activity is logged into $watchdogLog"
}
# Command line
# ============
if [ "$1" != "" ]; then
usage
exit 1
fi
# Execution
# =========
# variables
date=`date '+%Y-%m-%d'`
time=`date '+%H:%M'`
ts="$date $time"
h=`date '+%H'`
m=`date '+%M'`
u=`echo $m | cut -c 2`
# New Day ?
if [[ "$h" == "00" && "$m" == "00" ]]; then
echo "" >> $watchdogLog
echo "" >> $watchdogLog
echo "==========" >> $watchdogLog
echo "$date" >> $watchdogLog
echo "==========" >> $watchdogLog
fi
# Need to copy something ?
if [ `ls $dropin | wc -l` -ne 0 ]; then
echo "" >> $watchdogLog
echo "" >> $watchdogLog
pid=`ps -ef | grep $me | grep java | grep -v grep | tr -s ' ' | cut -d ' ' -f 2`
if [ "$pid" != "" ]; then
echo "[INFO] $ts stopping process $pid" >> $watchdogLog
kill -9 $pid
fi
# wait program terminason AND wait for the end of a copy into dropin
sleep 5
echo -n "[INFO] $ts moving files from $dropin" >> $watchdogLog
mv -f $dropin/* $running
fi
# Need tostart ?
pid=`ps -ef | grep $me | grep java | grep -v grep | tr -s ' ' | cut -d ' ' -f 2`
if [ "$pid" != "" ]; then
# new hour
if [ "$m" == "00" ]; then
echo "" >> $watchdogLog
echo -n "$h" >> $watchdogLog
fi
else
echo "" >> $watchdogLog
echo "[INFO] $ts starting manager" >> $watchdogLog
echo "" >> $watchdogLog
cd $running
nohup /usr/bin/java -jar site-manager-*.jar & &>/dev/null
echo -n "$h " >> $watchdogLog
for i in `seq $m`; do
echo -n " " >> $watchdogLog
done
fi
if [ "$u" == "0" ]; then
echo -n " " >> $watchdogLog
fi
echo -n "$u" >> $watchdogLog