Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable tomcat failed: Invalid section header '[Unit] Description=Apache Tomcat'

Tags:

java

tomcat

I am trying to enable the tomcat server by default. I followed this method for installation of tomcat 9. my tomcat.service file looks like,

[Unit] Description=Apache Tomcat
After=syslog.target network.target
[Service] Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/apache-tomcat-9.0.8/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat/apache-tomcat-9.0.8
Environment=CATALINA_BASE=/opt/tomcat/apache-tomcat-9.0.8
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
WorkingDirectory=/opt/tomcat/apache-tomcat-9.0.8
ExecStart=/opt/tomcat/apache-tomcat-9.0.8/bin/startup.sh
ExecStop=/opt/tomcat/apache-tomcat-9.0.8/bin/shutdown.sh
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
[Install] WantedBy=multi-user.target

I checked my tomcat server which is running on the port 8080 https://localhost:8080. But I am unable to enable the Tomcat server.

The command sudo systemctl enable tomcat returns following error.

● tomcat.service
   Loaded: error (Reason: Bad message)
   Active: inactive (dead)

พ.ค. 11 14:35:04 portal-gic systemd[1]: /etc/systemd/system/tomcat.service:1: Invalid section header '[Unit] Description=Apache Tomcat'
พ.ค. 11 14:35:05 portal-gic systemd[1]: /etc/systemd/system/tomcat.service:1: Invalid section header '[Unit] Description=Apache Tomcat'
พ.ค. 11 14:35:10 portal-gic systemd[1]: /etc/systemd/system/tomcat.service:1: Invalid section header '[Unit] Description=Apache Tomcat'
พ.ค. 11 14:43:02 portal-gic systemd[1]: /etc/systemd/system/tomcat.service:1: Invalid section header '[Unit] Description=Apache Tomcat'
พ.ค. 11 14:43:55 portal-gic systemd[1]: /etc/systemd/system/tomcat.service:1: Invalid section header '[Unit] Description=Apache Tomcat'
พ.ค. 11 14:46:02 portal-gic systemd[1]: /etc/systemd/system/tomcat.service:1: Invalid section header '[Unit] Description=Apache Tomcat'
พ.ค. 11 14:47:53 portal-gic systemd[1]: /etc/systemd/system/tomcat.service:1: Invalid section header '[Unit] Description=Apache Tomcat'
พ.ค. 12 19:22:44 portal-gic systemd[1]: /etc/systemd/system/tomcat.service:1: Invalid section header '[Unit] Description=Apache Tomcat'
พ.ค. 12 19:23:55 portal-gic systemd[1]: /etc/systemd/system/tomcat.service:1: Invalid section header '[Unit] Description=Apache Tomcat'
พ.ค. 12 19:25:17 portal-gic systemd[1]: /etc/systemd/system/tomcat.service:1: Invalid section header '[Unit] Description=Apache Tomcat'

like image 253
dhiraj Avatar asked Sep 21 '26 23:09

dhiraj


1 Answers

as @andreswjames said, the error is arising through first line. And you should break [Unit] and Description=Apache Tomcat line. Also do same for the [Service] and [Install] line. The final output will looks like this,

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

[Service] 
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/apache-tomcat-9.0.8/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat/apache-tomcat-9.0.8
Environment=CATALINA_BASE=/opt/tomcat/apache-tomcat-9.0.8
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
WorkingDirectory=/opt/tomcat/apache-tomcat-9.0.8
ExecStart=/opt/tomcat/apache-tomcat-9.0.8/bin/startup.sh
ExecStop=/opt/tomcat/apache-tomcat-9.0.8/bin/shutdown.sh
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install] 
WantedBy=multi-user.target

After editing this file you should run following command,

systemctl daemon-reload

This will help the system to recognize our changes.

After that you can enable and check the status of tomcat.

sudo systemctl enable tomcat
sudo systemctl status tomcat

Hope this will helps you!

like image 141
Tekson Avatar answered Sep 26 '26 08:09

Tekson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!