centos7开始,从/etc/init.d脚本改为了systemctl管理服务。今天主要记录一下怎么把Tomcat8加入systemd管理的步骤。
以下基于centos7.3进行测试验证。
# cd /home/tomcat8090/bin # ls
编辑 catalina.sh脚本文件
# vim catalina.sh
添加 CATALINA_PID="/var/run/tomcat.pid",如上图
# vim /usr/lib/systemd/system/tomcat.service
[Unit] Description=Tomcat After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking Environment="JAVA_HOME=/usr/local/jdk" PIDFile=/home/tomcat8090/tomcat.pid ExecStart=/home/tomcat8090/bin/startup.sh ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
# systemctl enable tomcat.service
# systemctl daemon-reload
启动tomcat服务
systemctl start tomcat.service
设置开机自启动
systemctl enable tomcat.service
停止开机自启动
systemctl disable tomcat.service
查看服务当前状态
systemctl status tomcat.service
重新启动服务
systemctl restart tomcat.service
查看所有已启动的服务
systemctl list-units --type=service