77# Pull environment for this install
88. " {{runner_base_dir}}/lib/env.sh"
99
10- # Make sure the user running this script is the owner and/or su to that user
11- check_user $@
12- ES=$?
13- if [ " $ES " -ne 0 ]; then
14- exit $ES
15- fi
1610
1711# Keep track of where script was invoked
1812ORIGINAL_DIR=$( pwd)
@@ -29,10 +23,38 @@ usage() {
2923 echo " getpid | top [-interval N] [-sort reductions|memory|msg_q] [-lines N] }"
3024}
3125
26+ # All commands must either call bootstrap or bootstrapd
27+ # Call bootstrap for non-daemon commands like ping or chkconfig
28+ # Call bootstrapd for daemon commands like start/stop/console
29+ bootstrap () {
30+ # Make sure the user running this script is the owner and/or su to that user
31+ check_user $@
32+ ES=$?
33+ if [ " $ES " -ne 0 ]; then
34+ exit $ES
35+ fi
36+ }
37+
38+ bootstrapd () {
39+ # Create PID directory if it does not exist before dropping permissiongs
40+ # to the runner user
41+ create_pid_dir
42+ ES=$?
43+ if [ " $ES " -ne 0 ]; then
44+ echoerr " Unable to access $PID_DIR , permission denied, run script as root"
45+ exit 1
46+ fi
47+
48+ # Now call bootstrap to drop to $RUNNER_USER
49+ bootstrap $@
50+ }
3251
3352# Check the first argument for instructions
3453case " $1 " in
3554 start)
55+ # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
56+ bootstrapd $@
57+
3658 # Make sure there is not already a node running
3759 node_down_check
3860
@@ -75,6 +97,8 @@ case "$1" in
7597 fi
7698 PROCESS=` $NODETOOL rpcterms erlang whereis " '${WAIT_FOR_PROCESS} '." `
7799 if [ " $PROCESS " != " undefined" ]; then
100+ # Attempt to create a .pid file for the process
101+ create_pid_file
78102 exit 0
79103 fi
80104 done
@@ -84,9 +108,15 @@ case "$1" in
84108 echo " WAIT_FOR_ERLANG to the number of seconds to wait."
85109 exit 1
86110 fi
111+
112+ # Attempt to create .pid file
113+ create_pid_file
87114 ;;
88115
89116 stop)
117+ # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
118+ bootstrapd $@
119+
90120 get_pid
91121 ES=$?
92122 if [ " $ES " -ne 0 ] || [ -z $PID ]; then
@@ -103,9 +133,15 @@ case "$1" in
103133 do
104134 sleep 1
105135 done
136+
137+ # remove pid file
138+ rm -f $PID_FILE
106139 ;;
107140
108141 restart)
142+ # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
143+ bootstrapd $@
144+
109145 # # Restart the VM without exiting the process
110146 $NODETOOL restart
111147 ES=$?
@@ -115,6 +151,9 @@ case "$1" in
115151 ;;
116152
117153 reboot)
154+ # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
155+ bootstrapd $@
156+
118157 # # Restart the VM completely (uses heart to restart it)
119158 $NODETOOL reboot
120159 ES=$?
@@ -124,6 +163,9 @@ case "$1" in
124163 ;;
125164
126165 ping)
166+ # Bootstrap command (simply drop to $RUNNER_USER)
167+ bootstrap $@
168+
127169 # # See if the VM is alive
128170 ping_node
129171 ES=$?
@@ -133,6 +175,9 @@ case "$1" in
133175 ;;
134176
135177 attach-direct)
178+ # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
179+ bootstrapd $@
180+
136181 # Allow attaching to a node without pinging it
137182 if [ " $2 " = " -f" ]; then
138183 echo " Forcing connection..."
@@ -146,6 +191,9 @@ case "$1" in
146191 ;;
147192
148193 attach)
194+ # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
195+ bootstrapd $@
196+
149197 # Make sure a node is running
150198 node_up_check
151199
@@ -155,6 +203,9 @@ case "$1" in
155203 ;;
156204
157205 console)
206+ # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
207+ bootstrapd $@
208+
158209 RES=` ping_node`
159210 if [ " $? " -eq 0 ]; then
160211 echo " Node is already running - use '$SCRIPT attach' instead"
@@ -198,7 +249,11 @@ case "$1" in
198249 # Start the VM
199250 exec $CMD
200251 ;;
252+
201253 top)
254+ # Bootstrap command (simply drop to $RUNNER_USER)
255+ bootstrap $@
256+
202257 # Make sure the local node IS running
203258 node_up_check
204259
@@ -212,20 +267,34 @@ case "$1" in
212267 -node $NODE_NAME \
213268 $* -tracing off
214269 ;;
270+
215271 ertspath)
216272 echo $ERTS_PATH
217273 ;;
274+
218275 chkconfig)
276+ # Bootstrap command (simply drop to $RUNNER_USER)
277+ bootstrap $@
278+
219279 check_config
220280 ;;
281+
221282 escript)
283+ # Bootstrap command (simply drop to $RUNNER_USER)
284+ bootstrap $@
285+
222286 shift
223287 $ERTS_PATH /escript " $@ "
224288 ;;
289+
225290 version)
226291 echo $APP_VERSION
227292 ;;
293+
228294 getpid)
295+ # Bootstrap command (simply drop to $RUNNER_USER)
296+ bootstrap $@
297+
229298 # Get the PID from nodetool
230299 get_pid
231300 ES=$?
0 commit comments