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

Daemon / Silent Mode #57

Closed
patrickheeney opened this issue Nov 23, 2013 · 22 comments
Closed

Daemon / Silent Mode #57

patrickheeney opened this issue Nov 23, 2013 · 22 comments

Comments

@patrickheeney
Copy link

I am running ngrok in a vagrant box via puppet and it seems to error out when I start the service which I assume is because of the interface being returned. It would be great to run ngrok --daemon 80 or --silent which would only return a 0 status if successful or the error. If such an option does already exist I didnt see it on the help pages or in the code anywhere.

@inconshreveable
Copy link
Owner

I thought I'd replied to this. ngrok does let you supply -log=stdout which will turn off the console interface and just display streaming log output over stdout. There is no daemon mode and I don't intend on adding one. I think daemonizing services is almost always better left to a supervising framework like runit/upstart/supervisor/etc.

@patrickheeney
Copy link
Author

You did, this was posted before your reply. Thanks for the tip.

@jfelchner
Copy link

@inconshreveable I'd be fine if this solution actually let you run the thing in the background, but running something like:

ngrok -log="$HOME/ngrok.log" 80 &

doesn't even allow you to background the job. It fails with a:

suspended (tty output)  ngrok -log="$HOME/ngrok.log" 80

If I have a config file, I need zero output from ngrok on what it's doing 99% of the time. The -log should disable the "dashboard" screen on what is connected, for how long and on which interfaces. Either that or there should be a -quiet option which does the equivalent thing.

@jfelchner
Copy link

@inconshreveable also, I can see where you're coming from regarding "daemonizing", however, you have to consider your tool may be used by those who:

a. cannot understand how those services work (eg, explaining to a non-technical QA person how to set it up)
b. don't need the overhead of a "supervising framework" when all they want to do is run ngrok in the background for a few hours so they can pair with someone

I'm currently trying to work on my shellfiles so they can be used by our developers to abstract away whether they are using localtunnel, ngrok, pagekite, etc. All of the other services offer some sort of "run this thing without any terminal output" except for ngrok. So if I'm to support ngrok, I not only have to know if ngrok is installed, but I also have to check to see which type of "supervising framework" they have installed, figure out whether it's configured to run ngrok, and finally execute the proper command for that framework to start ngrok.

That's a lot of extra work for something that is as simple as "route all output to a log file" and optionally "drop a PID file somewhere".

@inconshreveable
Copy link
Owner

@jfelchner That's good feedback. I think you can get what you want now with:

ngrok -log=stdout 80 > /dev/null &

Or if you want a log:

ngrok -log=stdout 80 > ngrok.log &

This is a very unintuitive UI. "-log=stdout" really means "disable the terminal UI", which is surprising and not well documented.

I've recently discovered that it's possible for a program to detect whether it's attached to a tty or not and adjust its UI accordingly. I'll probably use that in the next version of ngrok to disable the terminal UI when run under supervisors or in the background, as well as possibly splitting out "do I run the terminal ui" into a separate option (or at least configuration file parameter).

With regard to a daemonization: it seems like if the "&" operator works as you expect it to, that it becomes unnecessary to have a daemon option. Do you disagree?

@jfelchner
Copy link

@inconshreveable if the & option works and I can get everything logged to a file, then I don't think a -daemon option is necessary.

I'll try out your solution above and get back with you.

Thanks for the reply!

@rwestergren
Copy link

This worked for me!

ngrok -log=stdout 80 > /dev/null &

@jfelchner
Copy link

@rwestergren me too. :)

As soon as Github actually gets a "here is a list of all the issues you're subscribed to", stuff like this won't fall through the cracks.

@tosh
Copy link

tosh commented Aug 21, 2014

Just wanted to let you know that I've run into the same UX issue and a --quiet or similar flag would have been more obvious.

@mint5auce
Copy link

'scuse my probably stupidity, but how would I get -log=stdout > /dev/null & to work with ssh forwarding, for example, something like this:

./ngrok -subdomain=foo -authtoken barxyz -proto=tcp 22

I can't figure out where the 'tcp' declaration would go.

@larsfk
Copy link

larsfk commented Feb 25, 2015

Someone know how to log -proto=tcp 22 ?

@AndySedano
Copy link

I was successful using a tunnel for ssh in the config file and running
ngrok -log=stdout > /dev/null start ssh &

my config file looks like this

tunnels:
  ssh:
    remote_port: 50800
    proto:
      tcp: 22

@selfagency
Copy link

When I try ngrok -log=stdout 80 > ~/ngrok.log & with v2.0.19, the output I get is the command instructions as though I entered an invalid parameter.

@dragondgold
Copy link

@selfagency same issue here, the -log is the problem, how to achieve the same thing with the new version?

@huygn
Copy link

huygn commented Mar 7, 2016

As of version 2.0.24, ngrok http 80 --log=stdout > ngrok.log & did the trick.

@IgorGanapolsky
Copy link

@gnhuy91 Doesn't this fill up the log file and cause waste of memory? I mean, does log rotation need to be turned on??

@huygn
Copy link

huygn commented Jul 18, 2016

@IgorGanapolsky yea you should bring up your own solution, but anw above command no longer available.

@stas00
Copy link

stas00 commented Mar 4, 2021

This solution no longer works (w/ 2.3.35). Incorrect Usage: flag provided but not defined: -log

@GuillaumeDesforges
Copy link

The right command is now

ngrok http 80 --log=stdout > ngrok.log &

@zentyk
Copy link

zentyk commented Aug 24, 2022

it works! now... how can i stop it?

@MarvinXu
Copy link

MarvinXu commented Oct 30, 2022

it works! now... how can i stop it?

kill -9 "$(pgrep ngrok)"

@TheGithubJoshua
Copy link

This is stupid, the ngrok team should really have a --daemon flag, because i'm sshing into my Raspberry Pi to run ngrok, except when I shut the terminal, the agent stops, so now I have to have my laptop running when when I'm using my Raspberry Pi with OMV.

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