5

For production purposes I need three processes running. This is my procfile and I use Foreman to start them:

web: bundle exec rails s Puma -p $PORT
queuing: bundle exec clockwork clock.rb
workers: bundle exec rake resque:workers

For deployment I'm using Mina. What's the appropriate way to start Foreman at the end of deploy task? Currently I'm starting like this:

desc "Deploys the current version to the server."
  task :deploy => :environment do
    deploy do
      invoke :'git:clone'
      invoke :'deploy:link_shared_paths'
      invoke :'bundle:install'
      invoke :'rails:db_migrate'
      invoke :'rails:assets_precompile'

      to :launch do
        queue "touch #{deploy_to}/tmp/restart.txt"
        queue "bundle exec foreman start"
      end
   end
 end

... but I don't think that's the proper way since the "mina deploy" command never successfully exits and the local console just starts outputting whatever these processes are doing.

Question number two: How do I initialize logging for each of these three processes separately in separate files?

And how do I prevent killing all of these three processes when one of them crashes? How do I make the process restart when it crashes?

Thanks!

Matic Jurglič
  • 831
  • 9
  • 26

1 Answers1

0

OK, so that's 3 questions.

1) I think you want to detach foreman process from the terminal. That way the deployment process will finish and foreman process will be running even after you have disconnected from the server. nohup is great for that, e.g. this will launch your app and pipe all logs to server.log file:

nohup foreman start > server.log 2>&1 &

2) AFAIK, foreman doesn't let you do that. You should probably use another process management service (e.g. systemd, upstart). Thankfully, foreman lets you easily export your config to different process management formats (http://ddollar.github.io/foreman/#EXPORTING).

3) Again, you probably want to separate your processes and manage them separately via upstart, systemd, etc.

matb
  • 851
  • 13
  • 23