以ngrok為例,在centos7上寫一個服務
首先要先編輯你要的服務 服務通常會在/etc/systemd/system/底下 vim /etc/systemd/system/ngrok.service 寫入: [Unit] Description=ngrokd Daemon after=network.target [Service] Type=forking ExecStart=/home/ngrokd-start.sh ExecStop=/home/ngrokd-stop.sh StandardOutput=tty [Install] WantedBy=multi-user.target 回到home目錄 創建ngrokd-start.sh 跟 ngrokd-stop.sh (別忘了要chmod改一下權限) ngrokd-start.sh 內容: #!/bin/sh /home/ngrok http 1880 -log=./log.txt & ngrokd-stop.sh 內容: #!/bin/sh ps aux | grep ngrok | awk '{print $2}' | xargs kill -9 記得寫完要 systemctl daemon-reload