-
Notifications
You must be signed in to change notification settings - Fork 521
/
Copy pathrun_mongo.sh
74 lines (55 loc) · 1.38 KB
/
run_mongo.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
#!/bin/bash
short_system=$(uname -s)
sys_vagrant="0"
sys_cygwin="0"
sys_osx="0"
system=$(uname -a)
if [ "${system:0:15}" == "Linux precise32" ]
then
sys_vagrant="1"
echo "Running on Vagrant guest"
elif [ $short_system == "Darwin" ]
then
sys_osx="1"
echo "Running on Mac OSX"
else
sys_cygwin="1"
echo "Running on Windows"
fi
if [ "$sys_vagrant" == "1" ]
then
# on vagrant guest
mongo_running=$(ps -ae | grep mongod | wc -l | xargs)
if [ "$mongo_running" == "1" ]
then
echo "Mongo is already running."
else
echo "Attempting to start mongod"
rm ~/.mongo_log &> /dev/null
$(mongod --fork --logpath ~/.mongo_log &> ~/.mongo_result);
mongo_result=$(grep "Unclean shutdown" ~/.mongo_log | wc -l | xargs)
if [ "$mongo_result" == "1" ]
then
echo "Mongo failed to shutdown tidily. Cleaning up now."
rm /data/db/mongod.lock
rm ~/.mongo_log
$(mongod --dbpath /data/db --repair &> ~/.repair_result)
$(mongod --fork --logpath ~/.mongo_log &> ~/.mongo_result);
fi
mongo_start_result=$(grep "started successfully" ~/.mongo_result | wc -l | xargs)
if [ "$mongo_start_result" == "1" ]
then
echo "Mongo started successfully."
else
echo "Mongo has failed to start."
fi
fi
else
if [ "$sys_osx" == "1" ]
then
echo "Run this only on vagrant"
elif [ "$sys_cygwin" == "1" ]
then
echo "Run this only on vagrant"
fi
fi