Mac OS X: Setting up a Rails Development Server to Always Run on Startup
I was searching for a way to have projects I’m working on always run in development as I have multiple small apps that I’m using to supplement my work at Flatiron school. We have an instructor app that is deployed, but changes there are often more involved and may take longer to implement. Also, I know that there are certain things I want to see that probably aren’t worth the trouble of deploying as they’re only important to me at the moment.
I spent quite a while searching for a way to do this without finding anything. I was messing around with launchd, creating plist files, wandering around stack overflow trying to figure out why I could use one of those plist files to start a rails server. Finally, I stumbled upon a project on github that seemed to fit the bill. It’s called Puma-dev, it’s not too involved to configure and I got it running in a few minutes, but there were a few things that weren’t quite obvious to me reading through the docs so I figured I’d add a quick start guide here to summarize those.
- The basic idea of puma-dev is to symlink different rack projects on your machine to ~/.puma-dev. After this is done, you’ll be able to visit name_of_project_folder.test in your browser and you’ll see the dev server running there without having to manually start it up in a terminal. Puma-dev adds a command line tool that makes these symlinks super easy to create.
- Your project must have gem ‘puma’ in the Gemfile and Puma-dev must be installed.
- To install puma-dev, the README on GitHub provides clear instructions. It also works on Linux, but here are the two commands I used on Mac OS X (10.12.6)
brew install puma/puma/puma-dev
Then after the brew was finished updating and installing, there are a couple of commands that we can use to finish the setup:
# Configure some DNS settings that have to be done as root
sudo puma-dev -setup
# Configure puma-dev to run in the background on ports 80 and 443 with the domain `.test`.
4. Finally, cd into your project directory and run
puma-dev link .
5. Visit student_progress_rails.test in the browser and you’ll see your development server running there! Also, since this is a dev server, it does respond to changes in code (running migrations or changing your view code will effect the running server)
6. If you change configuration files or gem dependencies and you do need to restart a particular app server, you can cd to that app’s directory and run
This is just an absolute beginner’s guide here, but puma-dev seems to be exactly what I needed for running a Rails Server in the background on startup. It’s also supposed to add https support, but at the moment Chrome doesn’t trust the certificate it generated so I’m currently just using http. I know some users mentioned having issues with all of the apps running on the same version of ruby, but puma-dev does support rvm for running apps using different versions of ruby.