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:
- 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
As you can see, it's easy. Just follow this simple rule:
service_name: command to run it
$ 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
and you are ready to go!
Thanks David Dollar for this awesome gem.