Community
Participate
Working Groups
The jetty.sh script included with jetty 9.1.0 uses the following statement to see if jetty is running: if [ -f "$JETTY_PID" ] then echo "Jetty running pid=$(< "$JETTY_PID")" exit 0 fi exit 1 fi This will always give a positive result if the PID file exists, even if the jetty server is not running. If jetty.sh is setup as an init.d service then the OS will not suspect that jetty is not running. A more robust alternative would be to open the PID file and check if the pid is running, i.e. if [ -f "$JETTY_PID" ] then local PID=$(< "$JETTY_PID") local PID_EXISTS=$(ps -p $PID 2>&1 ) local PID_EXISTS_STATUS=$? if [[ $PID_EXISTS_STATUS -eq 0 ]]; then echo "Jetty running pid=$PID" exit 0 fi exit 1 fi (One other thing, the jetty script does contain a utility function "running" which uses a "kill -0 <pid>" check in some cases. This is not as flexible as using "ps -p" since it will fail if you are not root or the jetty user)
Small error in my proposed fix, here is an improved version: if [ -f "$JETTY_PID" ] then local PID=$(< "$JETTY_PID") local PID_EXISTS PID_EXISTS=$(ps -p $PID 2>&1 ) if [[ "$?" -eq 0 ]]; then echo "Jetty running pid=$PID" exit 0 fi exit 1 fi
Already fixed in 9.1.x but thanks anyway.
Hi, Where has this been fixed ? The newest changeset in github still has this issue: https://github.com/eclipse/jetty.project/blob/master/jetty-distribution/src/main/resources/bin/jetty.sh#L553
sorry, bad link, here is a more appropriate one: https://github.com/eclipse/jetty.project/blob/9f76856fcff767e0d8a91ef5a311fcc498dd2a26/jetty-distribution/src/main/resources/bin/jetty.sh#L553
with commit ce5af1d I have improved the running function and used it throughout the shell script: running() { if [ -f "$1" ] then local PID=$(cat "$1" 2>/dev/null) || return 1 kill -0 "$PID" 2>/dev/null return fi rm -f "$1" return 1 } thanks