I have ngrok running on a server I remote into.
I start it by using the obvious, ngrok.exe http 80
. The problem is that when I sign off on that particular server, ngrok will close out and I will lose my tunnel. Is there a way I can keep the ngrok tunnel running even when I have signed off the machine? I understand if the machine is shut down there is nothing I can do to keep the tunnel running, that is obvious. Any ideas?
Thanks in advance.
As you've said If the machine is shutdown there will be no way keep the process running. There are a number of methods to do this. In each of these methods I'm assuming you already have the following config file:
config.yml
authtoken: <your-auth-token>
tunnels:
default:
proto: http
addr: 80
With ngrok link simply run the following commands:
ngrok service install -config /path/to/your/config.yml
ngrok service start
You should then be able to manage ngrok as you would any other service running on your given operating system.
The nohup command normally comes installed by default on mac os and linux. To run the command as such:
nohup ngrok start --all --config="path/to/config.yml" &
Running in a screen should also achieve the same effect here.
To create the service you will need to download a program for creating services from non service executables. Here I'm going to how to do this with NSSM (Non-Sucking Service Manager).
Run to following command:
nssm.exe install ngrok
select the ngrok executable in the window that appears and add the following to the arguments, then press 'Install service'.
start --all --config="C:\path\to\my\config.yml"
The service can now be managed from service manager. To start it open an admin terminal and run the following:
sc start ngrok
Requires root.
cd into /etc/systemd/system/
Create the following file:
ngrok.service
[Unit]
Description=Ngrok
After=network.service
[Service]
type=simple
User=<your_user_name>
WorkingDirectory=/home/<your_user_name>
ExecStart=/usr/bin/ngrok start --all --config="/path/to/config.yml"
Restart=on-failure
[Install]
WantedBy=multi-user.target
Then run the following command to start and enable the service
systemctl enable ngrok.service && systemctl start ngrok.service
sources:
https://ngrok.com/docs/ngrok-link#service
https://www.freedesktop.org/software/systemd/man/systemd.unit.html