Ngrok: How to set auto run after boot on raspberry pi?

Created on 6 Jun 2016  路  5Comments  路  Source: inconshreveable/ngrok

I tried to run ngrok after boot on raspberry pi by the following way but failed.
Is there any idea to do this?

Auto run setting that I tried

1. Create a sh file.

/home/pi/run_after_boot.sh

##! /bin/sh
ngrok start --all \
  --config=/home/pi/.ngrok2/ngrok.yml \
  --log=stdout \
  > /home/pi/ngrok.log &

I checked ngrok works by manual running of this sh file.

2. Add a command to /etc/rc.local before exit.

..
..

/home/pi/run_after_boot.sh

exit 0

I checked ngrok works by manual running of this file (/etc/rc.local).

3. Remove a log file created by nglok.

sudo rm /home/pi/ngrok.log

4. Reboot

$ sudo reboot

5. Check log file and process

$ sudo less /home/pi/ngrok.log

The log file is created but nothing is written.

$ ps aux | grep ngrok

ngrok does not run.

etc

I also tried the following but the result of logfile is same.

Add sleep before ngrok

/home/pi/run_after_boot.sh

##! /bin/sh
(sleep 10 &&
  ngrok start --all \
  --config=/home/pi/.ngrok2/ngrok.yml \
  --log=stdout \
  > /home/pi/ngrok.log) &

crontab

@reboot /home/pi/run_after_boot.sh

Version info

$ ngrok -v
ngrok version 2.1.1
$ uname -a
Linux raspberrypi 3.18.7+ #755 PREEMPT Thu Feb 12 17:14:31 GMT 2015 armv6l GNU/Linux

Thanks.

Most helpful comment

Check out this rep. Clean native solution.

https://github.com/vincenthsu/systemd-ngrok

All 5 comments

Sorry, it was my failure.
I succeeded in running ngrok after boot with calling it by absolute path.
/usr/local/bin is not included just after boot.

ngrok -> /usr/local/bin/ngrok

A command after modification.

/usr/local/bin/ngrok start --all \
  --config=/home/pi/.ngrok2/ngrok.yml \
  --log=stdout \
  > /dev/null

Thanks.

glad you got it figured out!

Thanks!

I'm trying something similar (or the same).
I want to start ngrok whenever the raspberry boots

this is a script, which has been added to /etc/init.d with update-rc.d startup defaults
you see all the lines commented out. that's all the crap I tried :) nothing really worked...
ngrok however starts and remains for many cases if I login and run the script

#! /bin/sh
# /etc/init.d/ngrok

#screen -D -R
# ngrok  tcp 22 > ~/ngrok.out.txt 
#ngrok -log=stdout tcp 22 > ngrok.out.txt &

/usr/local/bin/ngrok authtoken I_REMOVED_MYTOKEN >> /home/pi/ngrok.out.txt
#sudo ngrok tcp 22 -log=stdout > ngrok.out.txt &

sudo echo 'init' > /home/pi/ngrok.out.txt
#cd 
#screen -D -R
/usr/local/bin/ngrok  tcp 22 -log=stdout >> ngrok.out.txt &
#screen -dm ngrok tcp 22
#su - pi -c /usr/bin/screen -dm ngrok tcp 22
sudo echo 'done' >> /home/pi/ngrok.out.txt
#sleep 360

Check out this rep. Clean native solution.

https://github.com/vincenthsu/systemd-ngrok

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cleocn picture cleocn  路  6Comments

Conansoloman picture Conansoloman  路  7Comments

wujunze picture wujunze  路  9Comments

IngwiePhoenix picture IngwiePhoenix  路  7Comments

jabooth picture jabooth  路  5Comments