书写systemctl配置文件管理tomcat
要使用systemctl
管理Tomcat,你需要创建一个名为tomcat.service
的服务单元文件。以下是一个基本的示例,假设你的Tomcat安装在/opt/tomcat
目录下:
- 创建一个名为
tomcat.service
的文件在/etc/systemd/system/
目录下。
[Unit]
Description=Tomcat Web Application Container
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
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
- 重新加载
systemctl
配置:
sudo systemctl daemon-reload
- 启动、停止、启用或禁用Tomcat服务:
sudo systemctl start tomcat
sudo systemctl stop tomcat
sudo systemctl enable tomcat
sudo systemctl disable tomcat
确保替换环境变量中的JAVA_HOME
和Tomcat的安装路径/opt/tomcat
为你的实际路径。如果你的Tomcat版本或安装路径与上述示例不同,请相应修改配置文件。
评论已关闭