Search code examples
ruby-on-railsbashpumaguard

Which processes do I need to kill in order to get a clean slate with Rails?


When I'm making rails applications I like to generate/scaffold quick examples to test an idea.

Naively, I've been expecting that if I end my rails server and guard sessions I should be able to fire up another rails app.

But I find that I get unexpected results. Sometimes the server won't start, sometimes a model/controller/scaffold won't generate, sometimes guard won't work.

I'm not sure why this is and end up spending around 1-5 minutes hacking around pkilling until I'm back to a "clean" state where I can build a new app. It seems like rails and/or guard, puma, webbrick, and/or spring leave daemons going all over the place.

So far this is the processes I see that hang around, and how I kill them:

ps aux | grep ruby
ps aux | grep web
ps aux | grep puma
ps aux | grep spring

pkill -f ruby
pkill -f web
pkill -f puma
pkill -f spring

Is there a better approach to "reset my dev environment" so I can start developing another app?

Ideally what I'm looking for is a set of commands I can dump into a bash script named reset_rails that I can run and know with confidence that I'll be able to start my server, generate my scaffolds/models/controllers, and run my guard sessions.


Solution

  • Skipping spring has been working well so far. Make it the default with by adding it to your ~/.railsrc file with:

    echo "--skip-spring" >> ~/.railsrc
    

    or

    echo "--skip-spring" > ~/.railsrc
    

    If it doesn't already exist.