Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Foreman exit when I add a rake assets:precompile task to my Procfile?

My Ruby on Rails application uses foreman (https://github.com/ddollar/foreman) to manage the processes that need to be started when the app is run.

My Procfile looks like this:

precompile: bundle exec rake assets:precompile
web: bundle exec puma -e $PUMA_ENV
worker: bundle exec rake jobs:work
search: bundle exec rake sunspot:solr:run

Running $ foreman start worked as expected until I added the first line (the precompile task).

When I run $ foreman start my output looks like this:

$ foreman start -e .env.dev
10:30:20 precompile.1 | started with pid 7309
10:30:20 web.1        | started with pid 7310
10:30:20 worker.1     | started with pid 7311
10:30:20 search.1     | started with pid 7312
10:30:22 web.1        | [7310] Puma starting in cluster mode...
10:30:22 web.1        | [7310] * Version 2.8.2 (ruby 2.1.0-p0), codename: Sir Edmund Percival Hillary
10:30:22 web.1        | [7310] * Min threads: 4, max threads: 16
10:30:22 web.1        | [7310] * Environment: development
10:30:22 web.1        | [7310] * Process workers: 2
10:30:22 web.1        | [7310] * Phased restart available
10:30:22 web.1        | [7310] * Listening on tcp://0.0.0.0:3000
10:30:22 web.1        | [7310] Use Ctrl-C to stop
10:30:23 web.1        | [7313] + Gemfile in context: /Users/username/rails_projects/lcms/Gemfile
10:30:23 web.1        | [7314] + Gemfile in context: /Users/username/rails_projects/lcms/Gemfile
10:30:30 web.1        | [7310] - Worker 1 (pid: 7314) booted, phase: 0
10:30:30 worker.1     | [Worker(host:MacBook-Pro.local pid:7311)] Starting job worker
10:30:30 web.1        | [7310] - Worker 0 (pid: 7313) booted, phase: 0
10:30:32 precompile.1 | exited with code 0
10:30:32 system       | sending SIGTERM to all processes
SIGTERM received
10:30:32 web.1        | [7310] - Gracefully shutting down workers...
10:30:32 worker.1     | [Worker(host:MacBook-Pro.local pid:7311)] Exiting...
10:30:32 search.1     | exited with code 143
10:30:32 web.1        | [7310] - Goodbye!
10:30:32 web.1        | exited with code 0
10:30:33 worker.1     | exited with code 0

I don't know how to get more details on the problem. I've added $stdout.sync = true to my config/environments/development.rb, and the output is the same as without.

I've also tried both appending and prepending RAILS_ENV=development and RAILS_ENV=production to the precompile task.

How can I get my foreman/Procfile setup to precompile assets successfully, and then continue with the other tasks that start the app?

like image 226
sealocal Avatar asked Oct 20 '25 09:10

sealocal


2 Answers

I've decided that my best option is to use a syntax that will execute my rake assets tasks prior to booting Puma and only if precompiling is successful.

So, running the commands in order with && between them seems to achieve the result that I desire

web: bundle exec rake assets:clean RAILS_ENV=$FOREMAN_ENV && bundle exec rake assets:precompile RAILS_ENV=$FOREMAN_ENV && bundle exec puma -e $FOREMAN_ENV
worker: bundle exec rake jobs:work
search: bundle exec rake sunspot:solr:run
like image 102
sealocal Avatar answered Oct 22 '25 03:10

sealocal


The problem is that as soon as one of the processes in foreman exists, all do. I assume this is by design which makes sense. The application is the combination of running services.

If you want to run one-off tasks you can use foreman run.

like image 24
Dan Draper Avatar answered Oct 22 '25 04:10

Dan Draper