Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagetext
titleExample for systemd service file
linenumberstrue
collapsetrue
[Unit]
Description=Jetty for SOS JS7 JOC Cockpit
After=syslog.target
After=network.target

[Service]
# Set JAVA_HOME environment variable if necessary
# Environment="JAVA_HOME=/opt/java/jdk-17.0.2"
# Environment="JAVA=/opt/java/jdk-17.0.2/bin/java"
# Environment="JAVA_OPTIONS="
Environment="JETTY_RUN=/var/run/js7"
Environment="JETTY_PID=/var/run/js7/js7_joc_1.pid"
Type=forking
PIDFile=/var/run/js7/joc.pid
ExecStartPre=+/bin/mkdir -p /var/run/js7
ExecStartPre=+/bin/chown ap:ap /var/run/js7
ExecStartPost=/bin/sleep 1
ExecStart=/bin/sh -c "/home/js/joc/jetty/bin/jetty.sh start"
ExecStop=/bin/sh -c "/home/js/joc/jetty/bin/jetty.sh stop"
ExecReload=/bin/sh -c "/home/js/joc/jetty/bin/jetty.sh restart"
User=js
StandardOutput=journal+console
StandardError=journal+console
SuccessExitStatus=143
TimeoutStopSec=60

[Install]
WantedBy=multi-user.target

...

  • Sub-directories in the /var/run directory are ephemeral, i.e. they will be dropped on reboot of the server. If a sub-directory such as js7 is used then it has to be created by the service file. 
  • Jetty Environment Variables
    • Configuration
      • Environment="JETTY_RUN=/var/run/js7"
      • Environment="JETTY_PID=/var/run/js7/js7_joc_1.pid"
    • The variables specify the directory and the path of the PID file used by Jetty.
  • PID FileDirectory
    • Configuration 
      • PIDFile=/var/run/js7/joc.pid
      • ExecStartPre=+/bin/mkdir -p /var/run/js7
      • ExecStartPre=+/bin/chown js:js /var/run/js7
    • The + preceeding the commends indicates that they will be executed by the root account.
    • The commands create the js7 sub-directory and hand-over ownership to the js account and group.

...