无法在 Ubuntu 中将 Jetty9 安装为服务

Unable to install Jetty9 as a service in Ubuntu

我已经按照 docs 安装 Jetty9 作为服务,但每当我 运行

service jetty start

如果没有消息,它会失败,我的 JETTY_HOME/opt/jetty9,包含版本 9.4.14 的 home distribution。我还在 /usr/share/jetty9 使用我的网络应用程序和模块创建了我的 JETTY_BASE

Jetty Home 和 Base 都属于用户 jetty。然后我将我的 init.d 文件夹符号链接为:

ln -s /opt/jetty9/bin/jetty.sh /etc/init.d/jetty

然后我创建了一个 /etc/default/jetty 文件,内容如下:

# change to 1 to prevent Jetty from starting
NO_START=0

# change to 'no' or uncomment to use the default setting in /etc/default/rcS
VERBOSE=yes

# Run Jetty as this user ID (default: jetty)
# Set this to an empty string to prevent Jetty from starting automatically
JETTY_USER=jetty

# The home directory of the Java Runtime Environment (JRE). You need at least
# Java 6. If JAVA_HOME is not set, some common directories for OpenJDK and
# the Oracle JDK are tried.
#JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

# Extra options to pass to the JVM
#JAVA_OPTIONS="-Xmx256m -Djava.awt.headless=true"

# Timeout in seconds for the shutdown of all webapps
#JETTY_SHUTDOWN=30

# Additional arguments to pass to Jetty
#JETTY_ARGS=

# Jetty uses a directory to store temporary files like unpacked webapps
TMPDIR=/opt/jetty9/tmp
JETTY_HOME=/opt/jetty9
JETTY_BASE=/usr/share/jetty9

# Default for number of days to keep old log files in /var/log/jetty9/
#LOGFILE_DAYS=14

# If you run Jetty on port numbers that are all higher than 1023, then you # do not need authbind. It is used for binding Jetty to lower port numbers.
# (yes/no, default: no)
#AUTHBIND=yes
JETTY_HOST=0.0.0.0

如果我在我的基础文件夹中使用 java -jar $JETTY_HOME/start.jar 启动 Jetty,它可以正常工作。另外,如果我 运行

service jetty supervise

它也 运行 没有问题,但是当我调用 start 时它失败了:

root@app:/usr/share/jetty9# service jetty start
Job for jetty.service failed because the control process exited with error code.
See "systemctl status jetty.service" and "journalctl -xe" for details.
root@app:/usr/share/jetty9# service jetty status
● jetty.service - LSB: Jetty start script.
   Loaded: loaded (/etc/init.d/jetty; generated)
   Active: failed (Result: exit-code) since Mon 2018-12-03 15:05:26 UTC; 14s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 21162 ExecStop=/etc/init.d/jetty stop (code=exited, status=0/SUCCESS)
  Process: 21202 ExecStart=/etc/init.d/jetty start (code=exited, status=1/FAILURE)

Dec 03 15:05:22 app systemd[1]: Stopped LSB: Jetty start script..
Dec 03 15:05:22 app systemd[1]: Starting LSB: Jetty start script....
Dec 03 15:05:26 app jetty[21202]: Starting Jetty: FAILED Mon Dec  3 15:05:26 UTC 2018
Dec 03 15:05:26 app systemd[1]: jetty.service: Control process exited, code=exited status=1
Dec 03 15:05:26 app systemd[1]: jetty.service: Failed with result 'exit-code'.
Dec 03 15:05:26 app systemd[1]: Failed to start LSB: Jetty start script..

这是service jetty check的输出:

root@app:/usr/share/jetty9# service jetty check
Jetty NOT running

JAVA                  =  /usr/bin/java
JAVA_OPTIONS          =  -Djetty.home=/opt/jetty9 -Djetty.base=/usr/share/jetty9 -Djava.io.tmpdir=/opt/jetty9/tmp
JETTY_HOME            =  /opt/jetty9
JETTY_BASE            =  /usr/share/jetty9
START_D               =  /usr/share/jetty9/start.d
START_INI             =  /usr/share/jetty9/start.ini
JETTY_START           =  /opt/jetty9/start.jar
JETTY_CONF            =  /opt/jetty9/etc/jetty.conf
JETTY_ARGS            =  jetty.state=/usr/share/jetty9/jetty.state jetty-started.xml
JETTY_RUN             =  /var/run/jetty
JETTY_PID             =  /var/run/jetty/jetty.pid
JETTY_START_LOG       =  /var/run/jetty/jetty-start.log
JETTY_STATE           =  /usr/share/jetty9/jetty.state
JETTY_START_TIMEOUT   =  60
RUN_CMD               =  /usr/bin/java -Djetty.home=/opt/jetty9 -Djetty.base=/usr/share/jetty9 -Djava.io.tmpdir=/opt/jetty9/tmp -jar /opt/jetty9/start.jar jetty.state=/usr/share/jetty9/jetty.state jetty-started.xml

有什么想法吗?

更新

/etc/default/jetty 中的用户更改为 root 可以解决问题,但这不是解决方案,不是吗?

# Run Jetty as this user ID (default: jetty)
# Set this to an empty string to prevent Jetty from starting automatically
JETTY_USER=root

我终于成功了,jetty 用户应该有权访问以下文件夹,并且 /usr/sbin/nologin as shell 如 here 所述.

JETTY_HOME
JETTY_BASE
/var/run/jetty   <-- couldn't find a reference to this folder in the docs

并将以下内容添加到您的/etc/default/jetty

JETTY_SHELL=/bin/sh
JETTY_LOGS=/usr/share/jetty9/logs
JETTY_START_LOG=/usr/share/jetty9/logs/jetty-start-log.log

您还应该仔细检查您的文件夹中除了 jetty 之外没有其他用户拥有的剩余日志文件。