Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upstart task generated by foreman doesn't find file?

I used foreman to export my Procfile to an upstart task.

Procfile:

web: bundle exec rails server
websocket: bundle exec rails runner websocket-server/em_websocket.rb

One of the upstart tasks (they are very alike and fail with the same error):

start on starting app-web
stop on stopping app-web
respawn

env PORT=5000

setuid app

chdir /var/www/app

exec bundle exec rails server

And the error (I got it via dmesg):

[35207.676836] init: Failed to spawn app-websocket-1 main process: unable to execute: No such file or directory
[35207.679577] init: Failed to spawn app-web-1 main process: unable to execute: No such file or directory

When I switch to the app user, I am actually able to run bundle exec rails server from the given directory.

Is there any way to pin down the error a little more? I didn't find any related logs in /var/log/upstart/.

like image 312
Gregor Weber Avatar asked Sep 30 '22 03:09

Gregor Weber


2 Answers

If you installed ruby via RVM it may be possible that the init is run before the rvm script runs. Did you try using absolute references to the bundle bin?

whereis bundle 

to obtain it

RVM was apparently not initialized or is not available in the upstart enviroment. Luckily rvm has wrappers for this case: https://rvm.io/integration/init-d

like image 86
Luca B. Avatar answered Oct 03 '22 09:10

Luca B.


You can run bundle in another way. Instead of:

web: bundle exec rails server

You need to run:

web: bash -c '~/.rvm/bin/rvm default do bundle exec rails server'

Note: ~/.rvm/bin/rvm - can be replaced with actual path of rvm installation on your server.

like image 43
Mike P. Avatar answered Oct 03 '22 10:10

Mike P.