-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheocat
executable file
·114 lines (97 loc) · 2.91 KB
/
eocat
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
#!/bin/bash
usage()
{
cat << EOF
usage: ./eocat [-s][-p port][-S]
[-e]
[-h]
[-c]
This script starts or stops the EOCat server and the underlying mongodb database.
OPTIONS:
-s Start the EOCat server and mongodb
-p port Set port number the EOCat server will listen too (default 3000)
-S Use https protocol (default http)
-e Stop the EOCat server and mongodb
-h Show this message
-c Check status of EOcat server and mongod processes
EOF
}
getMyIP() {
local _ip _myip _line _nl=$'\n'
while IFS=$': \t' read -a _line ;do
[ -z "${_line%inet}" ] &&
_ip=${_line[${#_line[1]}>4?1:2]} &&
[ "${_ip#127.0.0.1}" ] && _myip=$_ip
done< <(LANG=C /sbin/ifconfig)
printf ${1+-v} $1 "%s${_nl:0:$[${#1}>0?0:1]}" $_myip
}
getMyIP myIP
echo $myIP
mkdir -p ../eocatdata/mongodb
mkdir -p ../eocatdata/log
port="3000"
prot="http"
while getopts 'hcsp:Sre' flag; do
case "${flag}" in
h) usage
exit 1
;;
s)
oper='Start'
;;
p) port="${OPTARG}";;
e) oper='Stop' ;;
c) oper='Status' ;;
S) prot='https';;
esac
done
if [ -z "$1" ]; then
usage
fi
# get pid of EO Catalogue server if it's already running
status=`ps -efww | grep -w "[n]ode eocatserver.js" | awk -v pid=$$ '$2 != pid { print $2 }'`
statusdb=`ps -efww | grep -w "[m]ongod --config ./conf/mongod.conf" | awk -v pid=$$ '$2 != pid { print $2 }'`
case "$oper" in
Start)
if [ ! -z "$status" ]; then
echo "Server is already running with pid $status"
exit 1;
fi
echo "Starting mongodb..."
mongod --config ./conf/mongod.conf &
echo "Starting EOCat..."
node eocatserver.js $prot $port &
sleep 5 # Give some time to server to start mongodb and establish connection with it
#open "$prot://$myIP:$port/*/search?format=eocat&count=200&startIndex=1"
open "$prot://$myIP:$port"
;;
Stop)
if [ ! -z "$status" ]; then
echo "Found EOCat server running with pid $status. Will now stop it."
kill "$status"
echo "EOCat server stopped."
else
echo "Couldn't find a running EOCat server"
fi
if [ ! -z "$statusdb" ]; then
echo "Found mongod running with pid $statusdb. Will now stop it."
kill "$statusdb"
echo "mongod server stopped."
else
echo "Couldn't find a running mongod server"
fi
;;
Status)
if [ ! -z "$status" ]; then
echo "EOCat server is running with pid $status. Use -e flag to stop it."
ps -efww | grep -w "[n]ode eocatserver.js"
else
echo "EOCat server is not running. Use -s flag to start it"
fi
if [ ! -z "$statusdb" ]; then
echo "mongod server is running with pid $statusdb. WARNING !! Never use 'kill 9' on this process !!)"
ps -efww | grep -w "[m]ongod --config ./conf/mongod.conf"
else
echo "mongod server is not running. [stop and] start EOCat to get it running."
fi
esac