Create file tomcat-systemd on /etc/systemd/system/tomcat-systemd.service
nano /etc/systemd/system/tomcat-systemd.servicee
# Systemd unit file for tomcat [Unit] Description=Apache Tomcat Web Application Container After=syslog.target network.target [Service] Type=forking Environment=JAVA_HOME=/opt/tomcat/jdk1.8.0_121 Environment=CATALINA_PID=/opt/tomcat/apache-tomcat-7.0.75/temp/tomcat.pid Environment=CATALINA_HOME=/opt/tomcat/apache-tomcat-7.0.75/ Environment=CATALINE_BASE=/opt/tomcat/apache-tomcat-7.0.75/ Environment='CATALINE_OPTS=-Xms1G -Xmx1G -Djava.net.preferIPv4Stack=true' Environment='JAVA_OPTS=-Djava.awt.haedless=true -Djava.security.egd=file:/dev/./urandom' ExecStart=/opt/tomcat/apache-tomcat-7.0.75/bin/startup.sh ExecStop=/opt/tomcat/apache-tomcat-7.0.75/bin/shutdown.sh #ExecStop=/bin/kill -15 $MAINPID User=tomcat Group=tomcat [Install] WantedBy=multi-user.target
Enable and start service
systemctl enable tomcat-systemd.service systemctl start tomcat-systemd.service
We can test OK with:
ps -ef |grep java systemctl status tomcat-systemd.service
Thanks to https://gist.github.com/obatiuk/15c84fb25826d4f39a303a454087e85a for systemd Script.