DEV Community

Cover image for Using Foreman to start services in development
Fernando Shayani
Fernando Shayani

Posted on


Using Foreman to start services in development

In any development environment it's usually needed to start many background services to be able to code properly.

I don't like to keep all necessary services running in my machine all the time to save resources, so I start them only when needed; and starting them one-by-one it's too much work.

Comes Foreman to the rescue! Foreman is a gem (for Ruby, but it already ported to many others languages) that will load a Procfile and start/stop the services configured by demand.

For example, every time I start coding in a project, I need to run all those services:

  • PostgreSQL
  • Redis
  • Webpacker
  • Rails server
  • Rails worker

Automation of this procedure is simple. Lets first create a Procfile and save it on the project root directory.


postgres: postgres -D /usr/local/var/postgres
redis: redis-server /usr/local/etc/redis.conf
webpacker: bundle exec bin/webpack-dev-server
rails: bundle exec rails server
worker: bundle exec rails jobs:work
Enter fullscreen mode Exit fullscreen mode

As you can see, it's easy. Just follow this simple rule:

service_name: command to run it
Enter fullscreen mode Exit fullscreen mode

Then type:

$ foreman start

20:30:42 postgres.1 | started with pid 42458
20:30:42 rails.1    | started with pid 42459
20:30:42 worker.1   | started with pid 42460
20:30:42 redis.1    | started with pid 42461
20:30:42 webpack.1  | started with pid 42462
Enter fullscreen mode Exit fullscreen mode

and you are ready to go!

Thanks David Dollar for this awesome gem.

Top comments (0)

Welcome! 👋 New to DEV? Head over to our Welcome Thread and tell us what you're working on!