@@ -71,8 +71,8 @@ echoYellow() { echo $'\e[0;33m'$1$'\e[0m'; }
71
71
72
72
# Utility functions
73
73
checkPermissions () {
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 ; }
76
76
}
77
77
78
78
isRunning () {
@@ -115,40 +115,40 @@ command="$javaexe -jar -Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPT
115
115
start () {
116
116
if [[ -f " $pid_file " ]]; then
117
117
pid=$( cat " $pid_file " )
118
- isRunning $pid && { echoYellow " Already running [$pid ]" ; exit 0; }
118
+ isRunning $pid && { echoYellow " Already running [$pid ]" ; return 0; }
119
119
fi
120
120
pushd $( dirname " $jarfile " ) > /dev/null
121
121
if [[ -n " $run_user " ]]; then
122
122
mkdir " $PID_FOLDER " & > /dev/null
123
- checkPermissions
123
+ checkPermissions || return $?
124
124
chown " $run_user " " $PID_FOLDER "
125
125
chown " $run_user " " $pid_file "
126
126
chown " $run_user " " $log_file "
127
127
su -c " $command &> \" $log_file \" & echo \$ !" $run_user > " $pid_file "
128
128
pid=$( cat " $pid_file " )
129
129
else
130
- checkPermissions
130
+ checkPermissions || return $?
131
131
$command & > " $log_file " &
132
132
pid=$!
133
133
disown $pid
134
134
echo " $pid " > " $pid_file "
135
135
fi
136
- [[ -z $pid ]] && { echoRed " Failed to start" ; exit 1; }
136
+ [[ -z $pid ]] && { echoRed " Failed to start" ; return 1; }
137
137
echoGreen " Started [$pid ]"
138
138
}
139
139
140
140
stop () {
141
- [[ -f $pid_file ]] || { echoRed " Not running (pidfile not found)" ; exit 1; }
141
+ [[ -f $pid_file ]] || { echoRed " Not running (pidfile not found)" ; return 1; }
142
142
pid=$( cat " $pid_file " )
143
143
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; }
148
148
sleep 1
149
149
done
150
150
echoRed " Unable to kill process ${pid} " ;
151
- exit 3;
151
+ return 3;
152
152
}
153
153
154
154
restart () {
@@ -157,31 +157,33 @@ restart() {
157
157
}
158
158
159
159
status () {
160
- [[ -f $pid_file ]] || { echoRed " Not running" ; exit 1; }
160
+ [[ -f $pid_file ]] || { echoRed " Not running" ; return 1; }
161
161
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 ; }
163
163
echoGreen " Running [$pid ]"
164
- exit 0
164
+ return 0
165
165
}
166
166
167
167
run () {
168
168
pushd $( dirname " $jarfile " ) > /dev/null
169
169
exec $command
170
+ result = $?
170
171
popd
172
+ return $result
171
173
}
172
174
173
175
# Call the appropriate action function
174
176
case " $action " in
175
177
start)
176
- start " $@ " ;;
178
+ start " $@ " ; exit $? ; ;
177
179
stop)
178
- stop " $@ " ;;
180
+ stop " $@ " ; exit $? ; ;
179
181
restart)
180
- restart " $@ " ;;
182
+ restart " $@ " ; exit $? ; ;
181
183
status)
182
- status " $@ " ;;
184
+ status " $@ " ; exit $? ; ;
183
185
run)
184
- run " $@ " ;;
186
+ run " $@ " ; exit $? ; ;
185
187
* )
186
188
echo " Usage: $0 {start|stop|restart|status|run}" ; exit 1;
187
189
esac
0 commit comments