1. 程式人生 > >Centos 7 ngrok 加入系統服務,支援開啟和關閉服務

Centos 7 ngrok 加入系統服務,支援開啟和關閉服務

在CentOS 7上利用systemctl新增自定義系統服務。

使linux服務開機自啟動,注意下列指令中的配置檔案需要寫絕對路徑。

[Unit]
Description=Share local port(s) with ngrok
After=syslog.target network.target

[Service]
PrivateTmp=true
Type=simple
Restart=always
RestartSec=1min
StandardOutput=null
StandardError=null
ExecStart=/usr/local/ngrok/bin/ngrokd -tlsKey=/usr/local/ngrok/assets/server/tls/snakeoil.key -tlsCrt=/usr/local/ngrok/assets/server/tls/snakeoil.crt -domain=xxx網址 -httpAddr=:8081 -httpsAddr=:443 -tunnelAddr=:8083 %i
ExecStop=/usr/bin/killall ngrok

[Install]
WantedBy=multi-user.target

將上面的指令儲存為ngrok.service並移動到  /usr/lib/systemd/system/

systemctl enable ngrok.service //加入開機啟動
systemctl daemon-reload  //重新載入 systemd,掃描新的或有變動的單元
systemctl 是管制服務的主要工具, 它整合了chkconfig 與 service功能於一體。

systemctl is-enabled iptables.service
systemctl is-enabled servicename.service #查詢服務是否開機啟動
systemctl enable *.service #開機執行服務
systemctl disable *.service #取消開機執行
systemctl start *.service #啟動服務
systemctl stop *.service #停止服務
systemctl restart *.service #重啟服務
systemctl reload *.service #重新載入服務配置檔案
systemctl status *.service #查詢服務執行狀態
systemctl --failed #顯示啟動失敗的服務

注:*代表某個服務的名字,如http的服務名為httpd