@@ -71,8 +71,8 @@ echoYellow() { echo $'\e[0;33m'$1$'\e[0m'; }
7171
7272# Utility functions
7373checkPermissions () {
74- touch " $pid_file " & > /dev/null || { echoRed " Operation not permitted (cannot access pid file)" ; exit 1 ; }
75- touch " $log_file " & > /dev/null || { echoRed " Operation not permitted (cannot access log file)" ; exit 1 ; }
74+ touch " $pid_file " & > /dev/null || { echoRed " Operation not permitted (cannot access pid file)" ; return 4 ; }
75+ touch " $log_file " & > /dev/null || { echoRed " Operation not permitted (cannot access log file)" ; return 4 ; }
7676}
7777
7878isRunning () {
@@ -115,40 +115,40 @@ command="$javaexe -jar -Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPT
115115start () {
116116 if [[ -f " $pid_file " ]]; then
117117 pid=$( cat " $pid_file " )
118- isRunning $pid && { echoYellow " Already running [$pid ]" ; exit 0; }
118+ isRunning $pid && { echoYellow " Already running [$pid ]" ; return 0; }
119119 fi
120120 pushd $( dirname " $jarfile " ) > /dev/null
121121 if [[ -n " $run_user " ]]; then
122122 mkdir " $PID_FOLDER " & > /dev/null
123- checkPermissions
123+ checkPermissions || return $?
124124 chown " $run_user " " $PID_FOLDER "
125125 chown " $run_user " " $pid_file "
126126 chown " $run_user " " $log_file "
127127 su -c " $command &> \" $log_file \" & echo \$ !" $run_user > " $pid_file "
128128 pid=$( cat " $pid_file " )
129129 else
130- checkPermissions
130+ checkPermissions || return $?
131131 $command & > " $log_file " &
132132 pid=$!
133133 disown $pid
134134 echo " $pid " > " $pid_file "
135135 fi
136- [[ -z $pid ]] && { echoRed " Failed to start" ; exit 1; }
136+ [[ -z $pid ]] && { echoRed " Failed to start" ; return 1; }
137137 echoGreen " Started [$pid ]"
138138}
139139
140140stop () {
141- [[ -f $pid_file ]] || { echoRed " Not running (pidfile not found)" ; exit 1; }
141+ [[ -f $pid_file ]] || { echoRed " Not running (pidfile not found)" ; return 1; }
142142 pid=$( cat " $pid_file " )
143143 rm -f " $pid_file "
144- isRunning $pid || { echoRed " Not running (process ${pid} not found)" ; exit 1; }
145- kill -HUP $pid & > /dev/null || { echoRed " Unable to kill process ${pid} " ; exit 1 ; }
146- for i in $( seq 1 20 ) ; do
147- isRunning ${pid} || { echoGreen " Stopped [$pid ]" ; rm -f $pid_file ; exit 0; }
144+ isRunning $pid || { echoRed " Not running (process ${pid} not found)" ; return 1; }
145+ kill -HUP $pid & > /dev/null || { echoRed " Unable to kill process ${pid} " ; return 3 ; }
146+ for i in $( seq 1 60 ) ; do
147+ isRunning ${pid} || { echoGreen " Stopped [$pid ]" ; rm -f $pid_file ; return 0; }
148148 sleep 1
149149 done
150150 echoRed " Unable to kill process ${pid} " ;
151- exit 3;
151+ return 3;
152152}
153153
154154restart () {
@@ -157,31 +157,33 @@ restart() {
157157}
158158
159159status () {
160- [[ -f $pid_file ]] || { echoRed " Not running" ; exit 1; }
160+ [[ -f $pid_file ]] || { echoRed " Not running" ; return 1; }
161161 pid=$( cat " $pid_file " )
162- isRunning $pid || { echoRed " Not running (process ${pid} not found)" ; exit 1 ; }
162+ isRunning $pid || { echoRed " Not running (process ${pid} not found)" ; return 3 ; }
163163 echoGreen " Running [$pid ]"
164- exit 0
164+ return 0
165165}
166166
167167run () {
168168 pushd $( dirname " $jarfile " ) > /dev/null
169169 exec $command
170+ result = $?
170171 popd
172+ return $result
171173}
172174
173175# Call the appropriate action function
174176case " $action " in
175177start)
176- start " $@ " ;;
178+ start " $@ " ; exit $? ; ;
177179stop)
178- stop " $@ " ;;
180+ stop " $@ " ; exit $? ; ;
179181restart)
180- restart " $@ " ;;
182+ restart " $@ " ; exit $? ; ;
181183status)
182- status " $@ " ;;
184+ status " $@ " ; exit $? ; ;
183185run)
184- run " $@ " ;;
186+ run " $@ " ; exit $? ; ;
185187* )
186188 echo " Usage: $0 {start|stop|restart|status|run}" ; exit 1;
187189esac
0 commit comments