-
Notifications
You must be signed in to change notification settings - Fork 4
/
stop
executable file
·126 lines (112 loc) · 3.38 KB
/
stop
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#! /bin/bash
######GLOBAL CONSTANTS AND FUNCTIONS
COLOR='\e[0;32m'
STATUS_COLOR='\e[0;32m'
ERROR_COLOR='\e[0;31m'
NC='\e[0m'
echo_Status () {
echo -e "${STATUS_COLOR}${1}${NC}"
}
echo_Error () {
echo -e "${ERROR_COLOR}${1}${NC}"
}
stop_historicalTweets () {
##### STOPPING historicalTweets.py
echo_Status "Checking for running instance of historicalTweets.py"
historicalTweets_running=`pgrep -f historicalTweets.py | wc -l`
if [[ $historicalTweets_running -eq 0 ]]
then echo_Status "historicalTweets.py is not running"
echo_Status "Proceeding with execution..."
else echo_Status "Running instance of historicalTweets.py detected."
echo_Status "Killing existing instance..."
pgrep -f historicalTweets.py | xargs kill
fi
echo_Status "Historical Tweets instance killed"
##### STOPPING historicalTweets.py ends
}
stop_crisisServer () {
##### STOPPING crisisServer.py
echo_Status "Checking for running instance of crisisSever"
crisisServer_running=`pgrep -f crisisServer.py | wc -l`
if [[ $crisisServer_running -eq 0 ]]
then echo_Status "crisisServer is not running"
echo_Status "Proceeding with execution..."
else echo_Status "Running instance of crisisServer detected."
echo_Status "Killing existing instance..."
pgrep -f crisisServer.py | xargs kill
fi
echo -e "${COLOR}Crisis Server instance killed."
##### STOPPING crisisServer.py ends
}
stop_mongodb () {
###### STOP MONGOD
echo_Status "Checking for running instance of Mongo DB server."
mongod_running=`pgrep -f mongod | wc -l`
if [[ $mongod_running -eq 0 ]]
then echo_Status "Mongo DB server is not running"
echo_Status "Proceeding with execution..."
else echo_Status "Running instance of Mongo DB server detected."
# sudo ${folder_mongo_root}/bin/mongod --shutdown
mongo << EOF
use admin
db.shutdownServer()
exit
EOF
echo_Status "Stopped Mongo DB server"
fi
###### STOP MONGOD ends
}
######GLOBAL CONSTANTS AND FUNCTIONS ends
######PARSE COMMANDLINE PARAMETERS
###Note to developers - if you dont pass parameters to this file, just ignore this bit
stop_mongodb="N"
stop_crisisServer="N"
stop_historicalTweets="N"
if [[ $# -eq 0 ]]
then
stop_crisisServer="Y"
stop_historicalTweets="Y"
else
while getopts "mch" OPTION
do
case $OPTION in
c) stop_crisisServer="Y";;
h) stop_historicalTweets="Y";;
m) stop_mongodb="Y"
stop_crisisServer="Y"
stop_historicalTweets="Y";;
# Unknown option. No need for an error, getopts informs
# the user itself.
\?) exit 99;;
esac
done
fi
#echo $stop_crisisServer, $stop_historicalTweets, $stop_mongodb
######PARSE COMMANDLINE PARAMETERS ends
##################MAIN PROGRAM BEGINS##################
######INITIALIZATION CODE = Derive/validate paths.
folder_mongo_root=`sudo which mongod`
if [ "${folder_mongo_root}" = "" ] #Check mongod was found
then
echo_Error"Could not find location of mongod"
exit 1
else
folder_mongo_root=${folder_mongo_root%\/mongod}
fi
######INITIALIZATION CODE ends
if [[ $stop_crisisServer = "Y" ]]
then stop_crisisServer
else echo_Status "Skipped stopping of crisisServer"
fi
if [[ $stop_historicalTweets = "Y" ]]
then stop_historicalTweets
else echo_Status "Skipped stopping of historicalTweets"
fi
if [[ $stop_crisisServer = "Y" && $stop_historicalTweets = "Y" ]]
then rm -f nohup.out
fi
if [[ $stop_mongodb = "Y" ]]
then stop_mongodb
else echo_Status "Skipped stopping of monogo DB"
fi
echo_Status "Execution finished. Exiting..."