Tropical Software Observations

28 November 2011

Posted by Yasith Fernando

at 8:42 AM

0 comments

Labels: , ,

Notes about Delayed Job and Upstart

Upstart?

If you've been working with Linux systems for a while might have heard about upstart. As the upstart project’s home page describes, it's an event-based replacement for the System V init daemon.

Basically upstart takes care of starting and stopping services and ad hoc tasks when events happen such as when your system boots up or shuts down. And more!

Why Upstart?

As the saying goes: “don’t fix things it they aren’t broken,” so why would we bother with upstart in the first place when SysV init has been working fine for decades? Well, for one thing Ubuntu, Fedora, and others are moving to it! And upstart is event-based so you can easily write scripts to handle specific events. For example, it's trivial to run a script after the network services started. With init we have to rely on the static priorities of the scripts, which can get pretty messy and inflexible over time. Upstart is much more than what's described here and has a many more features as described in the project's feature highlights.

Delayed Job, RVM, and Upstart

Recently I needed to write a basic script to make sure that delayed_job gets started when the server is rebooted. Since I was using rvm to manage all the ruby processes on the server, I needed to make sure that rvm is properly loaded before actually running the delayed_job process.

There are enough articles out there about getting your scripts to run with RVM. However I keep running into problems with this very thing all the time!

Finally this is the script I came up with. It's a fairly simple script to get the delayed_job process started.





Notes


  • I decided to keep the /etc/init/file.conf simple and put most of the code in my external script file

  • the ‘task’ parameter can be used when you just want to do something simple like launch the daemon (and not creating a deamon for upstart to watch and restart...etc)

  • ‘start on runlevel [2345]’ tells upstart to start your task on runlevels 2,3,4, and 5

  • you can write your script inside the script…end script block. Here I'm just calling my external script

  • if you're running a Ruby script and have your Ruby set up via rvm be sure to include the two lines:

    • rvm_path=/home/deployer/.rvm

    • source "/home/deployer/.rvm/scripts/rvm"

    • this needs to be changed according to your rvm installation path

  • I'm also keeping a custom log that will have an entry for each time the task is run

0 comments: