jetty / jetty.project

Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
https://eclipse.dev/jetty
Other
3.86k stars 1.91k forks source link

Why does Jetty.sh rely on start-stop-Daemon #5495

Closed james-z-repo closed 2 years ago

james-z-repo commented 4 years ago

Jetty version jetty-distribution-9.4.19.v20190610 Java version 1.8 Question

I use Jetty on an ARM64 server with a built-in start-stop-daemon 1.19.7. This version never stops Jetty until I replace it. Does Jetty have to rely on start-stop-daemon?

stop jetty log: start-stop-daemon: matching only on non-root pidfile /usr/local/jetty/jetty.pid is insecure

gregw commented 4 years ago

@zhengshundong01 it is difficult to make a jetty.sh that will work on all flavours of unix. Even if we wrote it entirely ourselves with no dependencies, there is a wide variation of the ways that unix will start and stop jetty.

Starting/stopping jetty is fundamentally pretty simple: cd $JETTY_BASE; java -jar $JETTY_HOME/start.jar and then signal the PID when you want it to stop. The jetty.sh script is rather more complex than that as it is trying to adapt to lots of different ways of configuring etc.

If you have a very specific usage/OS, it may well be simpler to just write your own custom script.

However, @olamy could you look at writing an absolute minimal version of jetty.sh that avoids /etc *.conf complexities. Even if this just becomes and example in the doco, it may be a better place to start than our current scripts. Actually we should probably review the whole need for a conf mechanism as that has really been replaced by jetty-base concept. Perhaps we should quickly simplified for 10? @joakime your thoughts too?

joakime commented 4 years ago

Do you have systemd?

If so, skip the jetty.sh and just use a systemd service file to start/stop/restart Jetty ...

Here's a minimal example (and it doesn't use start-stop-daemon)

jetty-server.sh

#!/bin/sh 
SERVICE_NAME=JettyServer
JETTY_HOME=/opt/web/jetty-home-9.4.33.v20201020
JETTY_BASE=/opt/web/mybase
PID_PATH_NAME=/var/run/${SERVICE_NAME}.pid
JAVA_OPTS="-Djetty.home=$JETTY_HOME -Djetty.base=$JETTY_BASE"

case $1 in
start)
    if [ ! -f $PID_PATH_NAME ]; then
        startJetty
    else
      echo "$SERVICE_NAME is already running ..."
    fi
;;
stop)
    if [ -f $PID_PATH_NAME ]; then
        stopJetty
    else          
        echo "$SERVICE_NAME is not running ..."   
    fi    
;;    
restart) 
    if [ -f $PID_PATH_NAME ]; then 
        stopJetty
        startJetty
    else           
        echo "$SERVICE_NAME is not running ..."    
    fi
;;
esac

function startJetty {
    echo "$SERVICE_NAME starting ..."  
    nohup java $JAVA_OPTS -jar $JETTY_HOME/start.jar 2>> /dev/null >>/dev/null &
          echo $! > $PID_PATH_NAME  
    echo "$SERVICE_NAME started ..."    
}

function stopJetty {
    PID=$(cat $PID_PATH_NAME);
    echo "$SERVICE_NAME stopping ..."
    nohup java $JAVA_OPTS -jar $JETTY_HOME/start.jar --stop
    echo "$SERVICE_NAME stopped ..." 
    rm $PID_PATH_NAME       
}

jetty-server.service

[Unit]
Description = Jetty Service
After = syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type = forking
Restart = always
RestartSec = 1
# SuccessExitStatus = 143
ExecStart = /usr/local/bin/jetty-server.sh start
ExecStop = /usr/local/bin/jetty-server.sh stop
ExecReload = /usr/local/bin/jetty-server.sh restart

[Install]
WantedBy = multi-user.target
github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has been a full year without activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 2 years ago

This issue has been closed due to it having no activity.