Using supervisord and rvm to run rubyonrails

I have a RubyOnRails 3 project and I am using rvm. I want to switch from sysvinit script to supervisor. Sysvinit script can run the software only in case of an error, when it will be killed and restarted on $ something. Mostly me.

There is a .ruby-version and .ruby-gemset file in the project folder so that the correct loading of the ruby ​​version and gemset is automatically loaded. Then the application starts with a shell script that looks like this:

 #!/bin/bash RAILS_ENV="production" rails server -d 

My init script looks and works, except for restarting and stopping:

 #!/bin/sh ### BEGIN INIT INFO # Provides: myapp # Required-Start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts myapp # Description: starts the myapp software ### END INIT INFO USER=myuser PATH=$PATH DAEMON=go.sh DAEMON_OPTS="" NAME=myapp DESC="myapp for $USER" PID=/home/$USER/myapp/tmp/pids/server.pid case "$1" in start) CD_TO_APP_DIR="cd /home/$USER/myapp" START_DAEMON_PROCESS="$DAEMON $DAEMON_OPTS" echo -n "Starting $DESC: " if [ $(whoami) = root ]; then su - $USER -c "$CD_TO_APP_DIR > /dev/null 2>&1 && ./$START_DAEMON_PROCESS &" else $CD_TO_APP_DIR > /dev/null 2>&1 && ./$START_DAEMON_PROCESS & fi echo "$NAME." ;; stop) echo -n "Stopping $DESC: " kill -QUIT `cat $PID` echo "$NAME." ;; restart) echo -n "Restarting $DESC: " kill -USR2 `cat $PID` echo "$NAME." ;; reload) echo -n "Reloading $DESC configuration: " kill -HUP `cat $PID` echo "$NAME." ;; *) echo "Usage: $NAME {start|stop|restart|reload}" >&2 exit 1 ;; esac exit 0 

The configuration of my dispatcher is as follows:

 [program:myapp] directory=/home/myuser/myapp/ command=/home/myuser/.rvm/wrappers/ ruby-2.1.5@myapp /rails server -d environment=RAILS_ENV="production" autostart=true autorestart=true 

The problem is that there are no binary rails in the shell. so the command does not work. What is the right way to do this? I have no ideas and will start to put some really ugly bash scripts together, which does the job very badly and badly, but it does. Btw I found the rails in the stones folder.

 $ ls /home/myuser/.rvm/wrappers/ ruby-2.1.5@myapp / bundle bundler erb executable-hooks-uninstaller gem irb rake rdoc ri ruby testrb $ which rails /home/ffwi/.rvm/gems/ ruby-2.1.5@ffwi-extern /bin/rails 
+6
source share
1 answer

Try installing rvm in your script (the link describes usecases as yours).

You need to manually load the RVM into the shell of your script:

  source "$HOME/.rvm/scripts/rvm" 

It is activated only for interactive login shells.

From now on, you can cd in the directory, and rvm should do its business.

0
source

All Articles