start delayed job on reboot [sh script]


Short way:
Making script run at boot time at Debian

Manual Way:

cd /etc/init.d && sudo nano delayed_job_script

Paste following code to delayed_job_script:
Note: change RAILS_ROOT and ENV variables according to your setup.


#!/bin/sh
RAILS_ROOT="/home/deploy/apps/ProjectFolder/current"
ENV="production"

case "$1" in
    start)
    echo -n "Starting Delayed Jobs: "
    su - deploy -c "cd $RAILS_ROOT && RAILS_ENV=$ENV ruby script/delayed_job start -n 3"
    echo "done."
    ;;
    stop)
    echo -n "Stopping Delayed Jobs: "
    su - deploy -c "cd $RAILS_ROOT && RAILS_ENV=$ENV ruby script/delayed_job stop -n 3"
    echo "done."
    ;;
    *)
    echo "Usage: $N {start|stop}" >&2
    exit 1
    ;;
esac

exit 0

Make file executable:

sudo chmod +x /etc/init.d/delayed_job_script

Create links in Linux Runlevels for delayed_job_script:


sudo ln -s /etc/init.d/delayed_job_script /etc/rc0.d/K80delayed_job_script
sudo ln -s /etc/init.d/delayed_job_script /etc/rc1.d/K80delayed_job_script
sudo ln -s /etc/init.d/delayed_job_script /etc/rc1.d/etc/rc2.d/S80delayed_job_script
sudo ln -s /etc/init.d/delayed_job_script /etc/rc1.d/etc/rc3.d/S80delayed_job_script
sudo ln -s /etc/init.d/delayed_job_script /etc/rc1.d/etc/rc4.d/S80delayed_job_script
sudo ln -s /etc/init.d/delayed_job_script /etc/rc1.d/etc/rc5.d/S80delayed_job_script
sudo ln -s /etc/init.d/delayed_job_script /etc/rc6.d/K80delayed_job_script

Naming convention for link file names
In rc0.d, rc1.d and rc6.d link name starts from K which means kill command will execute. In other run levels link file name starts with S which means start process. After S/K there is number 80 which is just process priority number. After that you can write any name of your choice.

Intro to Run Levels

Advertisements

I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Tagged with: , ,
Posted in Ubuntu

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

StackOverFlow
Categories
Archives
%d bloggers like this: