Difference between revisions of "Tomcat Systemd"

From Dogtag
Jump to: navigation, search
m (Unit File)
m (Systemd Unit File)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
= Systemd Unit File =
 
= Systemd Unit File =
  
The Systemd unit file for Tomcat is located at /lib/systemd/system/tomcat@.service:
+
The Systemd unit file for default Tomcat instance is located at /lib/systemd/system/tomcat.service:
 +
 
 +
<pre>
 +
[Unit]
 +
Description=Apache Tomcat Web Application Container
 +
After=syslog.target network.target
 +
 
 +
[Service]
 +
Type=simple
 +
EnvironmentFile=/etc/tomcat/tomcat.conf
 +
Environment="NAME="
 +
EnvironmentFile=-/etc/sysconfig/tomcat
 +
ExecStart=/usr/libexec/tomcat/server start
 +
SuccessExitStatus=143
 +
User=tomcat
 +
Group=tomcat
 +
 
 +
[Install]
 +
WantedBy=multi-user.target
 +
</pre>
 +
 
 +
The Systemd unit file for non-default Tomcat is located at /lib/systemd/system/tomcat@.service:
  
 
<pre>
 
<pre>
Line 26: Line 47:
  
 
* [https://src.fedoraproject.org/rpms/tomcat/blob/master/f/tomcat-9.0.service tomcat-9.0.service]
 
* [https://src.fedoraproject.org/rpms/tomcat/blob/master/f/tomcat-9.0.service tomcat-9.0.service]
 +
 +
= Creating Non-Default Instance =
 +
 +
To create a non-default instance:
 +
 +
* create Tomcat directory structure in /var/lib/tomcats/<instance>
 +
* systemctl enable tomcat@<instance>.service
  
 
= Configuration =
 
= Configuration =

Latest revision as of 01:09, 16 August 2019

Systemd Unit File

The Systemd unit file for default Tomcat instance is located at /lib/systemd/system/tomcat.service:

[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=simple
EnvironmentFile=/etc/tomcat/tomcat.conf
Environment="NAME="
EnvironmentFile=-/etc/sysconfig/tomcat
ExecStart=/usr/libexec/tomcat/server start
SuccessExitStatus=143
User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

The Systemd unit file for non-default Tomcat is located at /lib/systemd/system/tomcat@.service:

[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=simple
EnvironmentFile=/etc/tomcat/tomcat.conf
Environment="NAME=%I"
EnvironmentFile=-/etc/sysconfig/tomcat@%I
ExecStart=/usr/libexec/tomcat/server start
ExecStop=/usr/libexec/tomcat/server stop
SuccessExitStatus=143
User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

See also:

Creating Non-Default Instance

To create a non-default instance:

  • create Tomcat directory structure in /var/lib/tomcats/<instance>
  • systemctl enable tomcat@<instance>.service

Configuration

  • /etc/sysconfig/tomcat
  • /etc/tomcat/tomcat.conf
  • /etc/tomcat/conf.d

Starting Service

To start Tomcat service:

$ systemctl start tomcat

Stopping Service

To stop Tomcat service:

$ systemctl stop tomcat

Checking Status

To check Tomcat status:

$ systemctl status tomcat

To list ports used by Tomcat:

$ lsof -Pan -p <Tomcat PID> -i
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/13079/gvfs
      Output information may be incomplete.
COMMAND   PID   USER   FD   TYPE    DEVICE SIZE/OFF NODE NAME
java    24364 tomcat   51u  IPv6 377096101      0t0  TCP *:8080 (LISTEN)
java    24364 tomcat   56u  IPv6 377096105      0t0  TCP *:8009 (LISTEN)
java    24364 tomcat   75u  IPv6 377096117      0t0  TCP 127.0.0.1:8005 (LISTEN)

To list ports used by all processes:

$ netstat -tulpn

To run Tomcat in foreground:

$ /usr/libexec/tomcat/server start

See Also