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

Feature Request : Make it possible to run multiple instances of localtunnel at the same time in the background. #605

Open
Runner-coder opened this issue Jun 11, 2023 · 1 comment

Comments

@Runner-coder
Copy link

Runner-coder commented Jun 11, 2023

Hi,

I have been using the localtunnel for a while and it has been working just fine for my projects up until recently where I had to run two servers on my Linux machine. I first tried the following to store the URL in a variable but it didn't work.

var=$(lt --port 8080)

Then I tried to run it in the background as following but it didn't work either.

lt --port 8080 &

But if I redirect stderr and stdout to a file it works.

lt --port 8080 >output.txt 2>&1 &

I also tried to write the output URL to a file and read it and it works fine but the terminal would stays blank until I press "ctrl+c" to close the program.

And obviously the problem seems to be that the localtunnel stays running until I close it. Like it's waiting for a user input. However I was able to archive what I want with start-stop-daemon by running the localtunnel in the background and writing the output to a file .

PIDFILE="$HOME/lt.pid";USER="root";start-stop-daemon --start --quiet --oknodo --background --pidfile $PIDFILE --make-pidfile --user $USER --chuid $USER --exec /bin/bash -- -c "/usr/bin/lt --port 8081 >$HOME/output.txt 2>&1"

This way I could run multiple instances of localtunnel with no problem by using different PID file names.
But when I want to close a specific instance of localtunnel I have to run several commands to find the PID and kill it.I eventually ended up writing a little bash script to handle this job in a user friendly way.But I wish if localtunnel had this feature by default.

I don't know if not being able to run localtunnel in the background by default is a feature or a safety measure to prevent any malicious acts but I would like to be able to run the localtunnel in the background by default and have a specific instance number for each instance. But it should still output the URL .So then I can call the localtunnel again with a kill argument and the instance number to kill that specific instance or kill all the instances if I choose to. I'm not a programmer, so I don't know if this is even possible but anyway I'm going to list the hypothetical features below that I want in the localtunnel by default. I don't know if these features are already present in localtunnel but I couldn't find any on the internet.

To run localtunnel instance in the background.

lt --port 8080

This should output the URL and the instance number which we can later use to kill the instance.

To kill the specified instance

lt -k 5

To kill all the instances

lt -k -a

Overall I want the localtunnel to run in background but still output to stdout in a way that I can store it inside a variable.

Finally I want to thank you for making such great,very useful and free tool that everyone can use. I hope best of luck for your future projects and plans.(I apologize if I have written an entire essay , but I had to say what I needed to say :)

Have a nice day !

@Parking-Master
Copy link

Parking-Master commented Jun 26, 2023

This is a great request, but there is already an NPM package called "forever" that lets you run Node.js in the background, and it handles errors automatically.

So basically what you can do is move localtunnel to Node.js instead of using the "lt" command in your terminal.

This way you could just do "forever start this.js && forever start that.js" to start multiple instances of localtunnel.

I'll leave you a link to forever and a sample of code to start localtunnel in Node.js.

(async () => {
  const tunnel = await localtunnel({ port: 8080, host: "http://loca.lt" });

  console.log(tunnel.url);

  tunnel.on("close", () => {
    console.log("\nTunnel closed");
  });

  process.on("SIGINT", () => {
    tunnel.close();
    process.exit(0);
  });
})();

app.listen(8080); // Or whatever port you want to use

Put that code at the end of your Javascript file (the one that hosts the public site). Then start your server using "forever start server.js" (where "server.js" is the file you put that code on).

Once that works, feel free to start a couple more scripts with forever!

https://www.npmjs.com/package/forever

Happy coding :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants