使用 systemctl
管理 tomcat
环境说明
- 操作系统为 CentOS 7.2
- JDK 版本为 1.8
- JDK 安装目录为
/usr/local/jdk1.8.0_181
- tomcat 版本为 8
- tomcat 安装目录为
/usr/local/apache-tomcat-8.5.33
安装 systemd 单元文件使 systemctl
命令可用
-
创建文件
/etc/systemd/system/tomcat.service
[Unit] Description=Apache Tomcat Web Application Container After=network.target syslog.target [Service] Type=forking Environment=JAVA_HOME=/usr/local/jdk1.8.0_181 ExecStart=/usr/local/apache-tomcat-8.5.33/bin/startup.sh ExecStop=/usr/local/apache-tomcat-8.5.33/bin/shutdown.sh [Install] WantedBy=multi-user.target
-
重新加载 systemd 配置文件
systemctl daemon-reload
-
启动命令
systemctl start tomcat
-
停止命令
systemctl stop tomcat
-
查看状态
systemctl status tomcat
-
设置开机启动
systemctl enable tomcat
-
取消开机启动
systemctl disable tomcat