CentOS7开始,从/etc/init.d脚本改为了systemctl管理服务。
亲自测试成功。
1.首先,需要为tomcat配置pid。
# Copy CATALINA_BASE from CATALINA_HOME if not already set
[ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME"
# 设置pid。一定要加在CATALINA_BASE定义后面,要不然pid会生成到/下面
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
2.创建tomcat.service文件
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment="JAVA_HOME=/home/jdk/jdk1.7.0_79"
PIDFile=/home/tomcat/apache-tomcat-7.0.47/tomcat.pid
ExecStart=/home/tomcat/apache-tomcat-7.0.47/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3.设置为开机启动
systemctl enable tomcat.service
4.其它
systemctl daemon-reload
启动nginx服务
systemctl start nginx.service
设置开机自启动
systemctl enable nginx.service
停止开机自启动
systemctl disable nginx.service
查看服务当前状态
systemctl status nginx.service
重新启动服务
systemctl restart nginx.service
查看所有已启动的服务
systemctl list-units --type=service