-
Notifications
You must be signed in to change notification settings - Fork 1
/
restart.sh
40 lines (33 loc) · 961 Bytes
/
restart.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
#!/bin/bash
old=$(< lastcount.txt)
new_count=$(curl --user admin:tweetpinna http://127.0.0.1:8080/ajax/get/docs-in-collection 2>&1 | grep -oP ',([0-9]{1,})' | cut -d, -f2)
if [ "$old" == "" ] && [ "$new_count" == "" ]
then
old=0
new_count=0
fi
echo $new_count > lastcount.txt
echo "Old Count: $old"
echo "New Count: $new_count"
delta=$(expr $new_count - $old)
if ((delta < 100))
then
echo "There seem to be no new tweets..."
. start.sh
fi
# Restart MongoDB; Requires sudo rights: tweetpinna ALL=NOPASSWD:/usr/sbin/service mongodb *
# This, obviously, only works if MongoDB is running on the same host
service=mongodb
if sudo service mongodb status | grep -q 'failed'
then
sudo service mongodb start
else
echo "$service is running (method primary)"
fi
# Alternative method based on ps
#if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
# then
# echo "$service is running (method alt)"
# else
# sudo service mongodb start
#fi