How to create an automatic resque process on boot?

Ok, I'm making my first ruby ​​app. Who knows that everything is redone for "production", so complicated. So far, I have been struggling to configure the passenger to start it at startup, and then run redis to start at startup.

My last task is to add 1 employee at startup. Right now, I have to execute ssh and run the rake command rake workers:start. Obviously, this is not good when I want to close ssh .., so I just don’t know how and what the next step is.

I tried copying resque default config to config.ru, and it just blows up Passenger with errors. I also looked into the resc pool, which some people talked about, but this is above my head.

all i need to do is add 1 worker at boot time. It is not that a serious application so simple would be better at the moment.

+5
source share
2 answers

During production, you must use god to view your processes. Even if this project is small, I highly recommend investing your time and setting it up.

Another big a must is Capistrano .

So, if you used God, here is a configuration file that will help you.

rake resque:work , script /etc/init.d/ /etc/init/ ( ). , ( , ).

, , . : , , rake deploy . , , , -, .

+4

, (1) , , , (2) Linux (Ubuntu) , .

Resque

/etc/rc.local . :

# Start Resque
su -l deploy -c "/home/deploy/start-resque-workers"
su -l deploy -c "/home/deploy/start-resque-webui"

ruby ​​ rake:

# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
  # First try to load from a user install
  source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
  # Then try to load from a root install
  source "/usr/local/rvm/scripts/rvm"
else
  printf "ERROR: An RVM installation was not found.\n"
fi

# Use rvm to switch to the default ruby. 
rvm use default

# Now launch the app
cd /home/deploy/app-name-here/current
nohup rake QUEUE=* RAILS_ENV=production environment resque:work &

, . . (, ), .

, capistrano .

+6

All Articles