Search code examples
ruby-on-railsupstartforeman

Upstart script exported by Foreman not working properly, respawning too fast


The only error I could find out was looking at dmesg

[  603.598951] init: thx4-web-1 main process ended, respawning
[  603.607935] init: thx4-web-1 main process (3901) terminated with status 127
[  603.607988] init: thx4-web-1 main process ended, respawning
[  603.616866] init: thx4-web-1 main process (3903) terminated with status 127
[  603.616917] init: thx4-web-1 respawning too fast, stopped

OS: Debian 7 , chruby (2.1.2), upstart (1.6.1-1) and foreman (0.74.0)

Only one process, to simplify the debug process in Procfile.staging :

web: RAILS_ENV=staging bundle exec puma -e staging -C config/puma.rb

Generated files by foreman:

# /etc/init/thx4.conf
start on runlevel [2345]
stop on runlevel [!2345]

# /etc/init/thx4-web.conf
start on starting thx4
stop on stopping thx4

# /etc/init/thx4-web-1.conf
start on starting thx4-web
stop on stopping thx4-web
respawn
env PORT=5000
setuid deployer
chdir /home/deployer/apps/thx4/releases/20140707183433
exec RAILS_ENV=staging bundle exec puma -e staging -C config/puma.rb

When i run $ foreman start -f Procfile.staging inside app folder, all it works fine.


Solution

  • How I solved:

    I created a .env file inside project root

    # .env
    PATH=/home/user/.gem/ruby/2.1.2/bin:/home/user/.rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/bin:/home/user/.rubies/ruby-2.1.2/bin:
    RAILS_ENV=staging
    
    # Procfile
    web: bundle exec puma -e staging -C config/puma.rb
    

    Exported file:

    # /etc/init/app-web-1.conf
    start on starting app-web
    stop on stopping app-web
    respawn
    
    env PORT=5000
    env PATH='/home/user/.gem/ruby/2.1.2/bin:/home/user/.rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/bin:/home/user/.rubies/ruby-2.1.2/bin'
    env RAILS_ENV='staging'
    
    setuid user
    
    chdir /home/user/apps/app/releases/20140709064220
    
    exec bundle exec puma -e staging -C config/puma.rb
    

    Important I had to install gem bundler as root (i don't know), like i did with foreman here: https://github.com/postmodern/chruby/issues/276 $ sudo chruby-exec ruby-2.1.2 -- gem install bundler