Align launch.script with the init script spec
The init script spec [1] describes a number of requirements with which our launch.script did not comply. This commit makes the following corrections: - Add support for force-reload which should be implemented by all init scripts - Don't fail restart if the service is already stopped or not running - Consider stop to be successful if the service is already stopped - Exit with 1 if stop fails (indicating a generic or unspecified error) rather than 3 (unimplemented feature) - Report a status of 1 if app is not running but the pid file exists - Report a status of 3 if the app is not running (no pid file) Closes gh-4231 [1] http://refspecs.linuxbase.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
This commit is contained in:
parent
1d3386ba3f
commit
d071db8cc9
|
@ -118,6 +118,10 @@ start() {
|
||||||
pid=$(cat "$pid_file")
|
pid=$(cat "$pid_file")
|
||||||
isRunning $pid && { echoYellow "Already running [$pid]"; return 0; }
|
isRunning $pid && { echoYellow "Already running [$pid]"; return 0; }
|
||||||
fi
|
fi
|
||||||
|
do_start
|
||||||
|
}
|
||||||
|
|
||||||
|
do_start() {
|
||||||
pushd $(dirname "$jarfile") > /dev/null
|
pushd $(dirname "$jarfile") > /dev/null
|
||||||
if [[ -n "$run_user" ]]; then
|
if [[ -n "$run_user" ]]; then
|
||||||
mkdir "$PID_FOLDER" &> /dev/null
|
mkdir "$PID_FOLDER" &> /dev/null
|
||||||
|
@ -152,27 +156,40 @@ start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
[[ -f $pid_file ]] || { echoRed "Not running (pidfile not found)"; return 1; }
|
[[ -f $pid_file ]] || { echoYellow "Not running (pidfile not found)"; return 0; }
|
||||||
pid=$(cat "$pid_file")
|
pid=$(cat "$pid_file")
|
||||||
rm -f "$pid_file"
|
rm -f "$pid_file"
|
||||||
isRunning $pid || { echoRed "Not running (process ${pid} not found)"; return 1; }
|
isRunning $pid || { echoYellow "Not running (process ${pid} not found)"; return 0; }
|
||||||
kill -HUP $pid &> /dev/null || { echoRed "Unable to kill process ${pid}"; return 3; }
|
do_stop $pid $pid_file
|
||||||
|
}
|
||||||
|
|
||||||
|
do_stop() {
|
||||||
|
kill -HUP $1 &> /dev/null || { echoRed "Unable to kill process $1"; return 1; }
|
||||||
for i in $(seq 1 60); do
|
for i in $(seq 1 60); do
|
||||||
isRunning ${pid} || { echoGreen "Stopped [$pid]"; rm -f $pid_file; return 0; }
|
isRunning $1 || { echoGreen "Stopped [$1]"; rm -f $2; return 0; }
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
echoRed "Unable to kill process ${pid}";
|
echoRed "Unable to kill process $1";
|
||||||
return 3;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
restart() {
|
restart() {
|
||||||
stop && start
|
stop && start
|
||||||
}
|
}
|
||||||
|
|
||||||
status() {
|
force_reload() {
|
||||||
[[ -f $pid_file ]] || { echoRed "Not running"; return 1; }
|
[[ -f $pid_file ]] || { echoRed "Not running (pidfile not found)"; return 7; }
|
||||||
pid=$(cat "$pid_file")
|
pid=$(cat "$pid_file")
|
||||||
isRunning $pid || { echoRed "Not running (process ${pid} not found)"; return 3; }
|
rm -f "$pid_file"
|
||||||
|
isRunning $pid || { echoRed "Not running (process ${pid} not found)"; return 7; }
|
||||||
|
do_stop $pid $pid_file
|
||||||
|
do_start
|
||||||
|
}
|
||||||
|
|
||||||
|
status() {
|
||||||
|
[[ -f $pid_file ]] || { echoRed "Not running"; return 3; }
|
||||||
|
pid=$(cat "$pid_file")
|
||||||
|
isRunning $pid || { echoRed "Not running (process ${pid} not found)"; return 1; }
|
||||||
echoGreen "Running [$pid]"
|
echoGreen "Running [$pid]"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -193,12 +210,14 @@ stop)
|
||||||
stop "$@"; exit $?;;
|
stop "$@"; exit $?;;
|
||||||
restart)
|
restart)
|
||||||
restart "$@"; exit $?;;
|
restart "$@"; exit $?;;
|
||||||
|
force-reload)
|
||||||
|
force_reload "$@"; exit $?;;
|
||||||
status)
|
status)
|
||||||
status "$@"; exit $?;;
|
status "$@"; exit $?;;
|
||||||
run)
|
run)
|
||||||
run "$@"; exit $?;;
|
run "$@"; exit $?;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: $0 {start|stop|restart|status|run}"; exit 1;
|
echo "Usage: $0 {start|stop|restart|force-reload|status|run}"; exit 1;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue