Wednesday, October 16, 2013

Creating custom tomcat systemcrtl daemon


This post will guide you to create new systemctrl daemon for apache tomcat which replaces service concept in older linux box.

Running Tomcat instance on different port other than default 8080:

If the port 8080 is not available or some security reasons we can change default port to other port
or better create a new instance of tomcat on another port by follow below steps.

Copy existing tomcat.service(usr/lib/systemd|systemctrl) to new service file ex: cus_tomcat.service and modify as below
# Systemd unit file for customized tomcat
#
# To create clones of this service:
# 1) By default SERVICE_NAME=tomcat. When cloned, the value must be defined
# before tomcat-sysd is called.
# 2) Create /etc/sysconfig/${SERVICE_NAME} from /etc/sysconfig/tomcat
# to override tomcat defaults
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/sbin/cus_tomcat-sysd start
ExecStop=/usr/sbin/cus_tomcat-sysd stop
SuccessExitStatus=143
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target

Copy the original configuration from  /usr/sbin/tomcat-sysd,  /etc/sysconfig/tomcat and paste it in /usr/sbin/cus_tomcat-sysd and /etc/sysconfig/cus_tomcat and modify location of tomcat files as necessary.

Our tomcat is located in /opt/tomcat, Modify the new tomcat conf/server.xml file with new port such that it should not conflict with existing services here it's 8085.

connectionTimeout="20000"
redirectPort="8443" />

<!--
port="8085" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
~

Enable the service
systemctrl enable cus_tomcat.service

Start the service
systemctrl start cus_tomcat.service.

No comments:

Post a Comment