需要在啟動時自動執行init_frpc.sh腳本,以下為腳本內容
cd [dir of frpc config files]
#使用nohup保證frpc在后台運行
nohup ./frpc -c ./frpc.ini &
1.復制或軟連接腳本到/etc/init.d/目錄下
2.將腳本添加到初始化執行的隊列中去
注意如果腳本需要用到網絡,則NN需設置一個比較大的數字,如99。
命令:update-rc.d filename defaults NN命令 #(NN為啟動順序)
ubuntu 18.04中一定要在shell腳本頭上加上以下LSB信息,不然放入啟動腳本的時候會報錯無法開機啟動。
#!/bin/bash
### BEGIN INIT INFO
# Provides: init_frpc.sh
# Required-start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the init_frpc.sh daemon
# Description: starts init_frpc.sh using start-stop-daemon
### END INIT INFO
3.設置腳本文件的權限
$ sudo chmod 755 /etc/init.d/init_frpc.sh (注意一定要設置權限rwxr-xr-x,不然開機不會啟動)
4.執行如下命令將腳本放到啟動腳本中去:
$ cd /etc/init.d
$ sudo update-rc.d init_frpc.sh defaults 95
注:其中數字95是腳本啟動的順序號,按照自己的需要相應修改即可。在你有多個啟動腳本,而它們之間又有先后啟動的依賴關系時你就知道這個數字的具體作用了。
5.卸載啟動腳本的方法:
$ cd /etc/init.d
$ sudo update-rc.d -f init_frpc.sh remove