Using Foreman with service oriented architecture
I’ve been working with some friends on a fun side-project lately - AppShape. It’s a product that will allow users to constantly monitor their applications health from both technical and business perspective.
We decided to split the product into 3 separate applications
- appshape - user facing web application running on Ruby On Rails
- appshape-runner - runs user-defined checks against their applications, written in Ruby
- appshape-reporter - reports results of this checks back to main application, written in
This means launching 6 processes in 6 different terminal windows, constantly switching between them to check logs…
I’ve had to come up with something better.
I like the simplicity of the
Procfile approach provided by Foreman. It’s just one command and you get colorized output,
all logs in one window and ability to kill all your processes with
CTL+C. I wanted that for my project!
Unfortunately Foreman doesn’t support the way we’ve structured AppShape:
- it doesn’t handle running processes from a different directory
- it doesn’t support different RVM’s which we are using for handling multiple ruby versions/gemsets
After short googling I’ve found subcontractor - nice gem that is supposed to handle all of this.
Let’s take a look at
subcontractor commands included:
The usage is pretty simple
--rvm- sets ruby version and gemset
--signal- which signal should be send to the process
--chdir- to where change directory
-- bundle exec ruby main.rb- command that should be executed
With this setup I was able to start foreman as usual with
foreman start and I could see all my processes running.
I would be perfectly happy with the above but I’ve noticed that sometimes processes started via
subcontractor were not killed.
After few hours of work and multiple restarts I executed
ps aux | grep ruby and saw about 20 running ruby processes.
I haven’t been able to fix the issue in a reasonable amount of time so I’ve decided to try another approach.
Back in the old days I was using
bash -lc when I wanted to run some of my
ruby programs via
non-interactive login shell and executes given command. The trick here is that
login option. Amongst other things it will
.profile files so
RVM will be available!
Here’s my modified
All process are being killed after
Foreman stops and I can benefit from “one command to start them all ™” setup :)