centos7配置tomcat为系统服务(systemctl进行管理)
一 在tomcat的bin目录下新建setenv.sh
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
二 在tomcat所在目录下新建tomcat.pid文件
三 在/lib/systemd/system目录下新建tomcat.service文件
1 [Unit] 2 Description=tomcat service 3 After=tomcat.service 4 5 [Service] 6 Type=forking 7 User=root 8 Group=root 9 PIDFile=/usr/share/tomcat/tomcat.pid 10 ExecStart=/usr/share/tomcat/bin/startup.sh 11 ExecStop=/usr/share/tomcat/bin/shutdown.sh 12 PrivateTmp=true 13 14 [Install] 15 WantedBy=multi-user.target
四 执行以下命令使配置生效
systemctl daemon-reload
五 systemctl相关命令
# 设置开机自启动
systemctl enable tomcat.service
# 停止开机自启动
systemctl disable tomcat.service
# 启动tomcat服务
systemctl start tomcat.service
# 停止tomcat服务
systemctl stop tomcat.service
# 重新启动服务
systemctl restart tomcat.service
# 查看服务当前状态
systemctl status tomcat.service
# 查看所有已启动的服务
systemctl list-units --type=service