How to run localtunnel automatically?

miniit25

New Member
Credits
15
Hello,

I am looking for a solution to make a website on my raspberry pi available over internet. I tried localtunnel to do it and it works perfectly. But I have one problem. I don't know, how to start localtunnel automatically on startup an for example rebuild tunnel if something goes wrong. (localtunnel on Github)

I can run localtunnel from console. But then console is locked until I press Ctrl+C. After pressing Ctrl+C tunnel is closed.

How can I achive a solution where localtunnel is started automatically on startup in background?

Best regards
miniit25
 


f33dm3bits

Gold Member
Gold Supporter
Credits
16,431
You could try creating a systemd unit file that may look something like this.
Code:
[Unit]
Description=Localtunnel Daemon
After=syslog.target network.target

[Service]
# Change the user variable here according to your needs
User=username

Type=simple

ExecStart=lt --port 8000
TimeoutStopSec=20
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target
Don't forget to replace username with the user you want to run it as.
1. Place the file here with this name: /etc/systemd/system/localtunnel.service
2. sudo systemctl daemon-reload
3. sudo systemctl start localtunnel
4. Check if it's running: systemctl status localtunnel
5. If it's running enable it at boot: sudo systemctl enable localtunnel
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Members online


Top