Ubuntu 伺服器採用Systemed管理Tomcat服務自動啟動

戴晶晶發表於2024-05-22

1、 新建Systemed配置檔案 參考以下配置檔案樣例

sudo vim /lib/systemd/system/tomcat.service

2、 重新載入Systemed配置資訊

sudo systemctl daemon-reload

3、 開啟自動啟動Tomcat

sudo systemctl enable tomcat.service

4、 啟動Tomcat

sudo systemctl start tomcat.service

5、 停止Tomcat

sudo systemctl stop tomcat.service

6、 檢視Tomcat執行情況

sudo systemctl status tomcat.service Systemed

配置檔案樣例【需要修改路徑地址】

[Unit]
Description=Tomcat
After=syslog.target network.target mysqld.service

[Service]
Type=forking

WorkingDirectory=/usr/local/tomcat/

Environment="JAVA_HOME=/usr/local/jdk/default"

Environment="CATALINA_PID=/usr/local/tomcat/run/tomcat.pid"
Environment="CATALINA_BASE=/usr/local/tomcat"
Environment="CATALINA_HOME=/usr/local/tomcat"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh

#RestartSec=10
#Restart=always

[Install]
WantedBy=multi-user.target

相關文章