开发者

Running rake task on ubuntu startup

开发者 https://www.devze.com 2023-03-10 00:48 出处:网络
Hi I\'m having a bit of trouble with setting up a rake task to run on startup/reboot of a ubuntu instance on Amazon EC2.

Hi I'm having a bit of trouble with setting up a rake task to run on startup/reboot of a ubuntu instance on Amazon EC2.

I need to make my instance start a simple delayed jobs "rake jobs:work" command when a new instance is launched, without me having to login using ssh, and run the command manually. The problem is - I can't get it to execute the command. It works fine from terminal开发者_开发技巧, but not by it self on startup. I have tried to follow the instructions in this link, but nothing seems to work.

I'm on a Natty 11.04 instance and I have installed ruby and gems through rvm.


You'll need to call something in a bash script that looks like this:

su - deploy -c "cd $RAILS_ROOT && rake RAILS_ENV=development jobs:work" >> $RAILS_ROOT/log/myjob.log 2>&1

Then call it from from your /etc/init.d/mystartup_filename. The file could look something like:

#! /bin/sh
RAILS_ROOT="/home/deploy/rails_root"
ENV="development"

case "$1" in
    start)
    echo -n "Starting my job: "
    su - deploy -c "cd $RAILS_ROOT && rake RAILS_ENV=$ENV jobs:work" >> $RAILS_ROOT/log/myjob.log 2>&1
    echo "done."
    ;;
    stop)
    echo -n "Stopping my job: "
    su - deploy -c "cd $RAILS_ROOT && rake RAILS_ENV=$ENV jobs:stopwork" >> $RAILS_ROOT/log/myjob.log 2>&1
    echo "done."
    ;;
    *)
    echo "Usage: $N {start|stop}" >&2
    exit 1
    ;;
esac

exit 0
0

精彩评论

暂无评论...
验证码 换一张
取 消