TongWeb在Linux下設定開機自啟動

realwangpu發表於2020-11-16

TongWeb在Linux下設定開機自啟動:

1. 在專用機下TongWeb安裝完成即是開機自啟動,無需設定。

2. 在TongWeb  bin目錄下installservice.sh命令可做成自啟動,具體請看doc目錄下TongWeb使用者手冊。

若以上方式無效,可手工配置開機自啟動:

方式一:

在/etc/rc.d/rc.local檔案中加入TongWeb的啟動命令即可。rc.local要有x許可權,內容如下:

#切到TongWeb使用者

su - {TongWeb使用者名稱}

#設定JAVA_HOME, 設了環境變數也要設,因為這時環境變數還沒生效

export JAVA_HOME=/home/jdk7

#進入tongweb目錄啟動

cd /home/tongweb7/bin

nohup ./startserver.sh &

 

#這樣寫指令碼最簡單。rc.d的目錄受啟動級別的影響。有的linux下不能換行寫,這樣寫一行

su - root -c  "export JAVA_HOME=/home/jdk7 ; cd /home/tongweb7/bin ; nohup ./startserver.sh &"

方式二:以systemd⽅式管理TongWeb服務

1. systemd的Unit(服務描述⽂件)放在/usr/lib/systemd/system⽬錄下。我們要做的就是編寫一個TongWeb的服務描述⽂件tongweb.service並放到/usr/lib/systemd/system⽬錄,然後以systemctl命令來管理TongWeb。內容如下:

[Unit]
Description=TongWeb Server

[Service]
Type=forking
#ExecStart=/opt/TongWeb/bin/startserver.sh restart
ExecStart=/opt/TongWeb/bin/boot.sh 
ExecStop=/opt/TongWeb/bin/stopserver.sh
PrivateTmp=false

# Disable service start and stop timeout logic of systemd for tongweb service.
TimeoutSec=0

[Install]
WantedBy=multi-user.target

 

注意:修改其中的TongWeb的指令碼路徑為伺服器上的真實指令碼路徑,相關引數參考systemd說明。

2. 啟⽤tongweb服務後TongWeb即可開機⾃啟動:sudo systemctl enable tongweb
3. 啟動服務: sudo systemctl start tongweb
 

 

相關文章