views:

253

answers:

0

Hi all I've been trying to build a robust /etc/init.d/delayed_job script. Below is my naive attempt which is failing in the case of the daemon already running.

#! /bin/sh
...
# return 1 if already running
do_start()
{
        /path/to/current/script/delayed_job start
        if [ "$?" -ne "0" ]; then
                echo "delayed_job is already running."
                return 1
        fi
        return 0
}

Following the flow the code should return 1 but I'm doing something wrong because its not ever printing the message.

daemons 1.0.10/lib/daemons/application_group.rb

...

def new_application(add_options = {})
...
    raise RuntimeException.new('there is already one or more instance(s) of the program running') unless @applications.empty?
  end
...

This I believe is caught here:

delayed_job/lib/command.rb

rescue => e
  Rails.logger.fatal e
  STDERR.puts e.message
  exit 1
end

It suggests this isn't the exit 1 that is called. Any thoughts?