Some users need to start the service when the system is powered on. This article will explain how to start the Ngrok client automatically when the system is powered on under Linux.
This article supports Ubuntu, raspberry pie, Centos7, Debian series of systems.
If the Centos system does not have start stop daemon installed, see Centos install start stop daemon
Operation steps
- 1. Download client
- 2. Script
- 3. Test script
- 4. Set startup
1. Download client
It goes without saying that everyone knows how to operate this step. After the download is completed, move the client execution file to the / use/local/bin directory and give the executable permission.
sudo mv sunny /usr/local/bin/sunny sudo chmod +x /usr/local/bin/sunny
2. Writing startup scripts
sudo vim /etc/init.d/sunny
/etc/init.d/sunny startup script code
#!/bin/sh -e ### BEGIN INIT INFO # Provides: ngrok.cc # Required-Start: $network $remote_fs $local_fs # Required-Stop: $network $remote_fs $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: autostartup of ngrok for Linux ### END INIT INFO NAME=sunny DAEMON=/usr/local/bin/$NAME PIDFILE=/var/run/$NAME.pid [ -x "$DAEMON" ] || exit 0 case "$1" in start) if [ -f $PIDFILE ]; then echo "$NAME already running..." echo -e "\033[1;35mStart Fail\033[0m" else echo "Starting $NAME..." start-stop-daemon -S -p $PIDFILE -m -b -o -q -x $DAEMON -- clientid Tunnel id || return 2 echo -e "\033[1;32mStart Success\033[0m" fi ;; stop) echo "Stoping $NAME..." start-stop-daemon -K -p $PIDFILE -s TERM -o -q || return 2 rm -rf $PIDFILE echo -e "\033[1;32mStop Success\033[0m" ;; restart) $0 stop && sleep 2 && $0 start ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 ;; esac exit 0
Replace the [tunnel id] in the code with its own tunnel id
3. Test executable code
sudo chmod 755 /etc/init.d/sunny sudo /etc/init.d/sunny start sudo /etc/init.d/sunny start #start-up sudo /etc/init.d/sunny stop #Stop it sudo /etc/init.d/sunny restart #restart
4. Set startup
Ubuntu, raspberry pie, Debian series of systems
cd /etc/init.d sudo update-rc.d sunny defaults 90 #chkconfig mysqld on sudo update-rc.d -f sunny remove #Cancel startup
Centos 7 operating system
sudo chkconfig --add sunny #Add system service sudo chkconfig --del sunny #Delete system service sudo chkconfig --list #View system services sudo chkconfig sunny on #Set startup sudo chkconfig sunny off #Set to cancel startup service sunny start #start-up service sunny stop #Close service sunny restart #restart
Centos install start stop daemon
wget http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz tar -xzvf apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz # Then go to the path after decompression and cd to the directory where start-stop-daemon.c is located cc start-stop-daemon.c -o start-stop-daemon cp start-stop-daemon /usr/bin/start-stop-daemon