DEV Community

Cover image for Stopping a runaway Rails server
Andrew Mason
Andrew Mason

Posted on • Updated on • Originally published at andrewm.codes

Stopping a runaway Rails server

Many of us have been there. You hit ctrl-c on you Ruby on Rails server, but nothing happens. No matter what keys you hit on your keyboard, the Rails server is still running, and you can't stop it. You have a runaway train on your hands.

The Problem

If you have ever developed with Ruby on Rails, there is a good chance you have encountered a runaway Rails server. This is basically an instance of the Ruby on Rails server that you cannot easily stop.

Two examples of when you may need this is if you try to start your Rails server and get an error message that one is already running, or you get into a weird state with pry and ctrl-c won't stop the server in a timely manner.

Regardless of how you got to this point isn't really important, you have a runaway train on your hands, and you need to stop it.

Here is how you can do that:

Shutup

shutup is a gem to help you quickly stop a running Rails server.

To install the gem, make sure you have Ruby installed.

Type the following into your command line:

gem install shutup
Enter fullscreen mode Exit fullscreen mode

Now, whenever you have a Rails server you want to stop, just type the following in your command line to shut it down:

shutup
Enter fullscreen mode Exit fullscreen mode

If the command succeeded, you should see something like this:

โžœ shutup
Killed process id: 46707
Enter fullscreen mode Exit fullscreen mode

If it fails, you will see:

โžœ shutup
Error reading the pid file.
Enter fullscreen mode Exit fullscreen mode

Conclusion

You could achieve the same effect with Bash or ZSH aliases, or just running the entire process by hand, but this gem removes the need to do that. It's a simple gem, but it's one I install whenever I install a new version of Ruby.

Check it out at: lorenzosinisi/shutup

Happy coding!!

Top comments (2)

Collapse
 
hopsoft profile image
Hopsoft

I use an alias for kill-rails

kill-rails: aliased to lsof -t -i tcp:3000 | xargs kill -KILL

This isn't quite the same as it will kill anything running on port 3000 which is great if you work on multiple Rails projects across tmux sessions and then forget which one is actually running.

Collapse
 
bizzibody profile image
Ian bradbury

I had just this happen yesterday. Thanks!