Starting with version 7, CentOS is now using systemd as a service manager. Adding a new service is no longer done by creating a SH script in the /etc/init.d folder.

  • First, create a new file /etc/systemd/system/tomcat.service with the following content:
[Unit]
Description=Tomcat
After=syslog.target network.target

[Service]
Type=forking
Environment=CATALINA_BASE=/usr/local/tomcat
Environment=CATALINA_PID=/var/run/tomcat/tomcat.pid
Environment=TOMCAT_HOME=/usr/local/apache-tomcat-8.0.45
ExecStart=/usr/local/apache-tomcat-8.0.45/bin/startup.sh
ExecStop='/usr/local/apache-tomcat-8.0.45/bin/shutdown.sh -force'
User=nobody
Group=nobody
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

We are using the nobody user to execute Tomcat. If there is the error ̀”This account is currently not available”, that means the nobody user does not have a tty (/sbin/nologin).

You will need to change the file /etc/passwd and put /bin/bash as the default tty for the nobody user:

nobody❌99:99:Nobody:/:/bin/bash
  • Reload systemd:
sudo systemctl daemon-reload
  • You can start the service with the following command:
sudo systemctl start tomcat
  • You can enable the service so that the service will start up automatically on each reboot:
sudo systemctl enable tomcat