-
Notifications
You must be signed in to change notification settings - Fork 18
/
islandora_microservices
executable file
·186 lines (173 loc) · 3.95 KB
/
islandora_microservices
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/sh
#
# Startup/shutdown script for running islandora microservices.
#
# Linux chkconfig stuff:
#
# chkconfig: 2345 99 15
# description: Startup/shutdown script for running Islandora Microservices.
### BEGIN INIT INFO
# Provides: islandora_microservices
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start islandora_microservices at boot.
# Description: Start the islandora_microservices and listen to fedora.
### END INIT INFO
# Source function library.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
fi
PROG="Islandora Microservices"
PYTHON=python
MICROSERVICES_PATH=/opt/islandora_microservices/
CONFIG_FILE=/opt/islandora_microservices/config/islandora_listener.cfg
PLUGIN_DIR=/opt/islandora_microservices/plugins_stable
START_STOP_WAIT=30
FEDORA_SERVER_ADDRESS=localhost
STOMP_PORT=61613
MICROSERVICES_USER=microservices
PID_SEARCH="pgrep -u $MICROSERVICES_USER -nf $CONFIG_FILE"
# Check to make sure fedora is running
command -v nmap >/dev/null 2>&1
RETVAL=$?
if [ ! $RETVAL = 0 ]; then
echo "Please install nmap. We use it to make sure activeMQ is running"
exit 1
fi
#****** CHECK FOR ROOT STATUS AND BLOCK IT ******#
if [ -z "$MICROSERVICES_USER" ]; then
ASROOT=0 # a flag to force "run as root"
for var in "$@"; do
case $var in
"-r")
ASROOT=1
;;
esac
done
# check for root status
if [[ $EUID -eq 0 && $ASROOT -eq 0 ]]; then
echo "It looks like you're trying to run this script as root"
echo "This is not normally allowed, to force it use $0 -r"
exit 1
fi
fi
start() {
if [ `$PID_SEARCH` ]; then
echo "$PROG already running! Try running with \"force-start\" if you know for certain it is not running."
else
force_start
fi
}
force_start () {
echo -n "Starting $PROG"
# start JMS as the microservices user
cd $MICROSERVICES_PATH
startwait=$START_STOP_WAIT
count=0
## Check to make sure that activeMQ has started for $START_STOP_WAIT seconds
while [ $count -lt $startwait ]; do
echo -n "."
count=`expr $count + 1`
ACTIVEMQ_CHECK=`nmap -p$STOMP_PORT $FEDORA_SERVER_ADDRESS | grep $STOMP_PORT | awk '{ print \$2 }'`
sleep 1
if [ $ACTIVEMQ_CHECK = "open" ]; then
break
fi
done
if [ $ACTIVEMQ_CHECK = "open" ]; then
/bin/su - $MICROSERVICES_USER --shell=/bin/bash --command="env HOME=/opt/islandora_microservices $PYTHON ${MICROSERVICES_PATH}islandora_listener.py -C $CONFIG_FILE -P $PLUGIN_DIR &>/dev/null 2>/dev/null &"
else
echo "" ; echo "$PROG was unable to contact the ActiveMQ broker running at $FEDORA_SERVER_ADDRESS."
exit 1
fi
PID=`$PID_SEARCH`
ps -p $PID &>/dev/null
RETVAL=$?
if [ $RETVAL = 0 ]; then
echo ""
echo "$PROG started..."
echo ""
return 0
else
echo ""
echo "$PROG failed to start... Check your logs"
return 1
fi
}
stop() {
PID=`$PID_SEARCH`
if [ $PID ]; then
echo "> Stopping..."
kill $PID
echo "Waiting for $PROG shutdown to complete"
sleep 2
kwait=$START_STOP_WAIT
count=0;
while [ $count -lt $kwait ]; do
sleep 1
count=`expr $count + 1`
PID=`$PID_SEARCH`
if [ ! $PID = "" ]; then
echo -n "."
else
break
fi
done
echo ""
if [ $count -eq $kwait ]; then
echo "process is still running after $START_STOP_WAIT seconds, killing process"
PID=`$PID_SEARCH`
kill $PID
sleep 5
fi
PID=`$PID_SEARCH`
if [ $PID ]; then
echo "process is still running, I give up"
return 1
else
echo "$PROG shutdown completed"
return 0
fi
else
echo "$PROG is not currently running, you can start it with $0 start"
fi
}
status()
{
PID=`$PID_SEARCH`
if [ $PID ]; then
echo "$PROG is up and running with PID="$PID
return 0
else
echo "$PROG is not currently running, you can start it with $0 start"
return 1
fi
}
restart() {
stop
sleep 2
start
}
case $1 in
start)
start
;;
force-start)
force_start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $PROG {start|stop|restart|status}"
exit 3
esac
exit $RETVAL