-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.sh
executable file
·77 lines (74 loc) · 2.17 KB
/
monitor.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
#!/bin/bash
#SMSEMAIL=<cell phone number @ sms-gateway>
SENDEREMAIL=alert@localhost
SERVER=http://localhost:8050
PAUSE=80
FAILED=0
DEBUG=1
COUNT=0
while true
do
/usr/bin/curl -sSf $SERVER > /dev/null 2>&1
CS=$?
# For debugging purposes
if [ $DEBUG -eq 1 ]
then
echo "STATUS = $CS"
echo "FAILED = $FAILED"
if [ $CS -ne 0 ]
then
echo "$SERVER is down"
elif [ $CS -eq 0 ]
then
echo "$SERVER is up"
fi
fi
# If the server is down and no alert is sent - alert
if [ $CS -ne 0 ] && [ $FAILED -eq 0 ]
then
FAILED=1
if [ $DEBUG -eq 1 ]
then
echo "$SERVER failed"
echo `date`
docker run -p 8050:8050 scrapinghub/splash
#java -jar target/dropwizard-sample-1.0-SNAPSHOT.jar server src/main/resources/sample.yml >> logfile.log 2>&1 &
#python /home/ubuntu/metonym_galaxy/runserver.py &
fi
if [ $DEBUG = 0 ]
then
echo "$SERVER went down $(date)" | /usr/bin/mailx -s "$SERVER went down" -r "$SENDEREMAIL" "$SMSEMAIL"
echo "$SERVER went down $(date)" | /usr/bin/mailx -s "$SERVER went down" -r "$SENDEREMAIL" "$NOTIFYEMAIL"
echo `date`
docker run -p 8050:8050 scrapinghub/splash
#java -jar target/dropwizard-sample-1.0-SNAPSHOT.jar server src/main/resources/sample.yml >> logfile.log 2>&1 &
#python /home/ubuntu/metonym_galaxy/runserver.py &
fi
# If the server is back up and no alert is sent - alert
elif [ $CS -eq 0 ] && [ $FAILED -eq 1 ]
then
FAILED=0
if [ $DEBUG -eq 1 ]
then
echo "$SERVER is back up"
fi
if [ $DEBUG = 0 ]
then
echo "$SERVER is back up $(date)" | /usr/bin/mailx -s "$SERVER is back up again" -r "$SENDEREMAIL" "$SMSEMAIL"
echo "$SERVER is back up $(date)" | /usr/bin/mailx -s "$SERVER is back up again" -r "$SENDEREMAIL" "$NOTIFYEMAIL"
fi
fi
if [ $COUNT -eq 500 ]
then
PID=`lsof -i :8080 | grep java | head -1 | awk '{printf "%s\n", $2}'`
kill -9 $PID
echo `date`
docker run -p 8050:8050 scrapinghub/splash
#java -jar target/dropwizard-sample-1.0-SNAPSHOT.jar server src/main/resources/sample.yml >> logfile.log 2>&1 &
echo "RESTARTING SERVER "
COUNT=0
fi
sleep $PAUSE
COUNT=$((COUNT + 1))
done