如何让systemctl命令可以控制tomcat
时间: 2024-02-16 22:29:19 浏览: 120
systemctl 管理tomcat.txt
要使systemctl命令可以控制Tomcat,需要创建一个systemd服务单元文件。
以下是一个示例systemd服务单元文件,用于启动、停止和重启Tomcat:
```
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
```
将此文件保存为`/etc/systemd/system/tomcat.service`,然后运行以下命令:
```
sudo systemctl daemon-reload
sudo systemctl enable tomcat
sudo systemctl start tomcat
```
现在,您可以使用以下命令控制Tomcat:
```
sudo systemctl start tomcat
sudo systemctl stop tomcat
sudo systemctl restart tomcat
sudo systemctl status tomcat
```
阅读全文