Systemd is a system manager and init system that is becoming a new standard for Linux operating systems. This guide show how to start Apache Tomcat8 with the
A running Linux maschine with systemd enabled, installed Java JDK, an Apache Tomcat 8 and for security reasons an unprivileged tomcat user.
Create a systemd Service File
To run Tomcat as a service, a systemd service file is needed. We also have to know where the Java JDK is installed.
As the user root, create a
tomcat8.service file in the
$ vi /etc/systemd/system/tomcat8.service
The following content has to be in the service file. You can modify the environment variables for your needs.
[Unit] Description=Apache Tomcat Web Application Container After=network.target [Service] Type=forking Environment=JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre Environment=CATALINA_PID=/var/run/tomcat8.pid Environment=CATALINA_HOME=/opt/tomcat8 Environment=CATALINA_BASE=/opt/tomcat8 Environment='CATALINA_OPTS=-Xms512M -Xmx=1024M -server \ -XX:+UseParallelGC' Environment='JAVA_OPTS=-Djava.awt.headless=true \ -Djava.security.egd=file:/dev/./urandom' ExecStart=/opt/tomcat8/bin/startup.sh ExecStop=/opt/tomcat8/bin/shutdown.sh User=tomcat8 Group=tomcat8 RestartSec=10 Restart=always [Install] WantedBy=multi-user.target
Start the Tomcat service
After editing the file, reload the
systemd daemon so that it knows about the new service file.
$ systemctl daemon-reload
Start the Tomcat service by typing
$ systemctl start tomcat8
Show the status that it was started
$ systemctl status tomcat8
Open your webbrowser and go to