1. 编写ngrok 启动脚本,
/path/to/ngrokd -tlsKey=/path/to/server.key -tlsCrt=/path/to/server.crt -domain="findhao.com" -httpAddr=":8000" -httpsAddr=":443"
存储为start.sh, 放置在ngrok 安装目录下, 更改文件权限
chmod 755 start.sh
2. 编写ngrok开机启动脚本, 存放在/etc/init.d/ngrok
ubuntu
#!/bin/sh
### BEGIN INIT INFO
# Provides: ngrok
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start or stop the ngrok Proxy.
### END INIT INFO
ngrok_path=/usr/local/ngrok
case "$1" in
start)
echo "start ngrok service.."
sh ${ngrok_path}/start.sh
;;
*)
exit 1
;;
esac
centos
#!/bin/sh
#chkconfig:2345 70 30
#description:ngrok
ngrok_path=/usr/appdata/ngrok
case "$1" in
start)
echo "start ngrok service.."
sh ${ngrok_path}/start.sh
;;
*)
exit 1
;;
esac
更改文件权限
chmod 755 ngrok
3. 注册开机启动
- ubuntu
$ cd /etc/init.d/
$ sudo update-rc.d ngrok defaults 90
- centos
chkconfig --add ngrok
测试服务是否能启动成功
service ngrok start
检查自启动的服务
chkconfig