Auto start ngrok Topic is solved

Having issues with your DietPi installation or found a bug? Post it here.
Post Reply
raj9119
Posts: 2
Joined: Tue Apr 06, 2021 9:40 am

Auto start ngrok

Post by raj9119 »

hi folks,

here is the problem,

I use Ngrok to access next cloud as I cant do port forwarding on the router.
now running ngrok is simple, after boot, i use ssh and type the following command
"./ngrok http 80"
if you have already setup an ngrok account all works well. I can go to my ngrok page and grab the url to acess next cloud easliy

Problem is that how can I make ngrok auto start on dietpi.

I know it has to be a custom script and I am really a noob trying to run something that he does not fully understand.
can someone please tell me what and how, it will be greatly appreciated.
and if you have any other service that does exactly the same, I can happily test it out.
old service that i used was tonido ;) ;)
User avatar
Joulinar
Posts: 4249
Joined: Sat Nov 16, 2019 12:49 am

Re: Auto start ngrok

Post by Joulinar »

you could try using root crontab to execute your command on boot. A one liner could looks like this.

Code: Select all

crontab -l > file; echo "@reboot /path/to/ngrok http 80" >> file; crontab file; rm file;
Maybe you will get an error message about not existing root crontab, but this is fine.
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
raj9119
Posts: 2
Joined: Tue Apr 06, 2021 9:40 am

Re: Auto start ngrok

Post by raj9119 »

ah I figured something out

Step 1: Place ngrok in /opt/ngrok/.

Step 2: Get authtoken from ngrok website, then add it to /opt/ngrok/ngrok.yml.

Step 3. Modify your own configrations in /opt/ngrok/ngrok.yml.

Step 4: Add ngrok.service to /lib/systemd/system/.

Step 5: Start ngrok service by typing:

systemctl enable ngrok.service
systemctl start ngrok.service


so now everytime it boots up it automatically logs in and i can get url from ngrok.

-------------------------------------------------------
ngrok.service file should look like this
---------------------------------------------------------

Code: Select all

[Unit]
Description=ngrok
After=network.target

[Service]
ExecStart=/opt/ngrok/ngrok start --all --config /opt/ngrok/ngrok.yml
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
IgnoreSIGPIPE=true
Restart=always
RestartSec=3
Type=simple

[Install]
WantedBy=multi-user.target
-------------------------------------------------
yml file should be like this
-------------------------------------------------

Code: Select all

authtoken: (put in the code from ngrok)
tunnels:
  ssh:
    proto: tcp
    addr: 22
  dashboard:
    proto: http
    addr: 80
  vnc:
    proto: tcp
    addr: 5900
User avatar
Joulinar
Posts: 4249
Joined: Sat Nov 16, 2019 12:49 am

Re: Auto start ngrok

Post by Joulinar »

yep using systemd is another alternative
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
User avatar
WarHawk
Posts: 719
Joined: Thu Jul 20, 2017 8:55 am

Re: Auto start ngrok

Post by WarHawk »

Very interesting...

Thanks for this!!!!

Such as this
Warning a bit o' language
Post Reply