Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set auto run after boot on raspberry pi? #345

Closed
asukiaaa opened this issue Jun 6, 2016 · 5 comments

Comments

@asukiaaa
Copy link

commented Jun 6, 2016

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.

@asukiaaa

This comment has been minimized.

Copy link
Author

commented Jun 7, 2016

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.

@asukiaaa asukiaaa closed this Jun 7, 2016

@inconshreveable

This comment has been minimized.

Copy link
Owner

commented Jun 7, 2016

glad you got it figured out!

@asukiaaa

This comment has been minimized.

Copy link
Author

commented Jun 11, 2016

Thanks!

@transfluxus

This comment has been minimized.

Copy link

commented Sep 15, 2017

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
@mrded

This comment has been minimized.

Copy link

commented May 17, 2018

Check out this rep. Clean native solution.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.