Main menu

create systemd service for tomcat

In my previous article we have created a init service file for tomcat, that’s was pretty easy and also work with newer SystemD. But let’s move forward and create SystemD service for tomcat with less lines and managed way.
We already know that If you are installing Tomcat from archive, probably you have to start and stop the service through tomcat bin directory. It’s works fine, but for day to day use it’s convenient to use a service file. This way you can start, stop, restart and schedule it at boot time.

Create a service file /usr/lib/systemd/system/tomcat8@.service and append the code below

# vi /usr/lib/systemd/system/tomcat8@.service
[Unit]
Description=Redmine server
After=syslog.target network.target

[Service]
Type=simple
User=tomcat
Group=tomcat
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-abort
TimeoutSec=300
SyslogIdentifier=tomcat-%i
EnvironmentFile=/opt/tomcat/conf/tomcat.conf
SuccessExitStatus=143


[Install]
WantedBy=multi-user.target

Create a tomcat.conf inside /opt/tomcat/conf/tomcat.conf and append the tomcat configuration here.

# vi /opt/tomcat/conf/tomcat.conf
JAVA_OPTS
CATALINA_HOME="/opt/tomcat/"
JAVA_HOME="/opt/java/jre/"
CATALINA_TMPDIR="/opt/tomcat/tmp/"
LANG="en_US"

Now you can manage your service with newer SystemD

Start tomcat service

# systemctl start tomcat8

Stop service

# systemctl stop tomcat8

Enable at boot time

# systemctl enable tomcat8

This is a very managed and newer way in SystemD for managing services. This way you can install as many tomcat in your Linux distribution with different setting and different java versions.

 

 

  • Douglas Giovani Oechsler

    helllo!
    How are you?

    Do you think is this works on Opensuse 42.2 64 bits?

    Thanks you

FacebookTwitterGoogle+RSS