Bluepill init script for Monitoring Delayed Job on Linux openSUSE
-Monday, February 01, 2010 By: Jon Kinney
I recently moved a long running request in my application to delayed job (the collectiveidea fork) and it went really well. However, after some time the delayed job process died and my users couldn't use an essential part of the application. I knew it was time for a process monitor. I probably should have put one in to begin with, but I was new to delayed job (really to background processing in general) and the though hadn't crossed my mind.
I googled around and found several articles that told me exactly how to get bluepill to monitor delayed job and even one for monitoring apache, but none of them seemed to give me a way to create an init script that would ensure that if the server rebooted, bluepill would start up and make sure delayed job continued to work.
It took a while but I finally found this post in the bluepill google group asking about documentation and an init script. The author (Carl) later answered his own post with this gist containing an init script for bluepill! I thought I was set, so I set out to figure out how to create an init script for openSUSE, the flavor of Linux my company uses. A simple google search yielded this great post about creating your own init script in openSUSE.
I followed it's directions and was very happy to find that issuing the following command "/etc/init.d/bluepill restart" resulted in bluepill being started and then executing "bluepill status" revealed that the delayed job process was indeed "UP" meaning that bluepill was doing it's job. Then I rebooted the machine and what happened next isn't for the faint of heart... after the machine rebooted and I SSH'd back into the box to check the bluepill log and I was devastated. The logs were reporting that bluepill couldn't start!
1 Mar 3 18:32:02 if-suse11-stage bluepilld[2344]: [application_name:delayed_job] Start command execution returned non-zero exit code:
2 Mar 3 18:32:02 if-suse11-stage bluepilld[2344]: [application_name:delayed_job] {:stdout=>"", :stderr=>"script/delayed_job:3:in 'require': no such file to load -- rubygems (LoadError)\n\tfrom script/delayed_job:3\n", :exit_code=>1}
3 Mar 3 18:32:02 if-suse11-stage bluepilld[2344]: [application_name:delayed_job] Going from down => starting
Ok, so maybe it's not that bad but I'm not a Linux expert (I'm decent, but only because I need to know Linux to host rails) and this was my first init script so I was pretty sunk. Having nowhere else to go, I turned to the author of bluepill himself, Arya. He was very helpful in answering my questions and as it turned out, my environment variables were not setup properly. Well, really the problem was that I had two installations of Ruby (apparently) and so the script was trying to start under the wrong one (I guess). Ayra's suggestion in the issues section of his github page was to add this code:
1 export PATH="/usr/local/bin:$PATH"
It worked and I haven't bothered to investigate much further. Here is my full init script, hopefully this will help someone else in the future!
1 #!/bin/sh
2
3 # Author: Jon Kinney
4 # Based on the opensuse skeleton /etc/init.d/skeleton init script
5
6 ### BEGIN INIT INFO
7 # Provides: bluepill
8 # Required-Start:
9 # Required-Stop:
10 # Default-Start: 2 3 4 5
11 # Default-Stop: 0 1 6
12 # Short-Description: bluepill daemon, providing process monitoring
13 # Description: bluepill is a monitoring tool. More info at http://github.com/arya/bluepill.
14 ### END INIT INFO
15
16 export PATH="/usr/local/bin:$PATH"
17
18 # Check for missing binaries
19 BLUEPILL_BIN=/usr/local/bin/bluepill
20 test -x $BLUEPILL_BIN || { echo "$BLUEPILL_BIN not installed";
21 if [ "$1" = "stop" ]; then exit 0;
22 else exit 5; fi; }
23
24 # Check for existence of needed config file and read it
25 BLUEPILL_CONFIG=/srv/www/app_name/shared/config/delayed_job.pill
26 test -r $BLUEPILL_CONFIG || { echo "$BLUEPILL_CONFIG not existing";
27 if [ "$1" = "stop" ]; then exit 0;
28 else exit 6; fi; }
29
30 case "$1" in
31 start)
32 echo -n "Starting bluepill "
33 $BLUEPILL_BIN load $BLUEPILL_CONFIG
34 ;;
35 stop)
36 echo -n "Shutting down bluepill "
37 $BLUEPILL_BIN quit
38 ;;
39 restart)
40 ## Stop the service and regardless of whether it was
41 ## running or not, start it again.
42 $0 stop
43 $0 start
44 ;;
45 *)
46 echo "Usage: $0 {start|stop|restart}"
47 exit 1
48 ;;
49 esac
News & Events
Tech Review: Web Design For Developers - June 2009
A friend of mine in the web development community is releasing a book called "Web Design for Developers: A Programmer's Guide to Design Tools and Techniques". I was asked to do a tech review of the book and will be sharing my thoughts as well as some cool info presented in the book in a short series of upcoming blog posts. If you want to grab a beta copy of the book head over to my favorite publisher The Pragmatic Programmers.
First Class Audio Production - March 1st 2009
My most recent studio project was mixing and producing the latest a cappella album to come out of Eau Claire, WI. Until Proven Guilty is the Innocent Men's 4th studio album and marks a huge leap forward in recording and production quality for the group. Check back for demos of the mastered songs very soon! http://theinnocentmen.com.
Rate This Post: 5.0 (average)


