All threads / How to start and stop ngrok with Thin server?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to start and stop ngrok with Thin server?

Daniel Weaver asked in Servers
I'm using the basic Thin server on my dev machine and I'd like to start and stop ngrok automatically with `rails s` - how do I do that?

I found several articles but they all involve more complex setups running unicorn, or another server, or using the ngrok-tunnel gem. I'm looking for a simpler solution. I was hoping I could write a simple rake task like:

desc 'Starts rails server and ngrok'
task :start do
  Process.exec("thin start")
  Process.exec("ngrok http 3000 -subdomain=mysubdomain")
end

Then just `rake start`, but of course only the first process runs and ngrok never starts.

Foreman is built for this. I use it to start rails, sidekiq and guard-rspec.

https://github.com/ddollar/foreman

Install the gem, and add a Procfile(.dev)

web:    bundle exec thin start -p $PORT
worker: bundle exec rake resque:work QUEUE=*
Great, thanks. I was hoping for a solution that didn't require another gem but I'll give this a try. 
Unfortunately using a gem in this case is one of the best solution.
Agreed on using foreman.  It's the easiest way, unless you want to setup some bash script as your entry point that launches both.  In this case foreman is great as the other posters have mentioned.
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.