centos7開始,從/etc/init.d腳本改為了systemctl管理服務(wù)。今天主要記錄一下怎么把Tomcat8加入systemd管理的步驟。
以下基于centos7.3進(jìn)行測(cè)試驗(yàn)證。
1、首先,需要為tomcat配置pid。
# cd /home/tomcat8090/bin # ls

編輯 catalina.sh腳本文件
# vim catalina.sh

添加 CATALINA_PID="/var/run/tomcat.pid",如上圖
2、創(chuàng)建tomcat.service文件
# 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

3、設(shè)置為開機(jī)啟動(dòng)
# systemctl enable tomcat.service
4.修改tomcat.service文件后需要執(zhí)行下面命令使其生效:
# systemctl daemon-reload
5、維護(hù)命令
啟動(dòng)tomcat服務(wù)
systemctl start tomcat.service
設(shè)置開機(jī)自啟動(dòng)
systemctl enable tomcat.service
停止開機(jī)自啟動(dòng)
systemctl disable tomcat.service
查看服務(wù)當(dāng)前狀態(tài)
systemctl status tomcat.service
重新啟動(dòng)服務(wù)
systemctl restart tomcat.service
查看所有已啟動(dòng)的服務(wù)
systemctl list-units --type=service
