nick.recoil.org

Mongrel init.d script

I’ve slightly modified Bojan Mihelac’s Mongrel init.d script to cope with the situation where there are stale PID files left from a server failure.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

#!/bin/env ruby
#
# mongrel Startup script for Mongrel by Tim Morgan, modified by bmihelac and Nick Ludlam
# Originally from http://source.mihelac.org/2007/3/27/customized-mongrel-startup-script
#
# chkconfig: 2345 85 15
# description: mongrel manages Mongrel
#

apps = [
  {:app => 'app1'},
  {:app => 'app2'},
  {:app => 'app3'}
]

default_port = 8000
default_options = {
  :app_dir => '/var/www',  :environment => 'production'
}

pid_location = "log/mongrel.pid"

if ['stop', 'restart'].include? ARGV.first
  apps.each do |app|
    options = default_options.merge(app)
    path = File.join options[:app_dir], options[:app], "current"
    puts "Stopping #{path}..."
    `/usr/local/bin/mongrel_rails stop -c #{path} -P #{pid_location}`
  end
end

if ['start', 'restart'].include? ARGV.first
  apps.each do |app|
    options = default_options.merge(app)
    path = File.join options[:app_dir], options[:app], "current"
    port = options[:port] || default_port
    pid_file = File.join path, pid_location

    # Check and remove stale PID file. Platform needs "ps -p" support
    if File.exists?(pid_file)
      old_pid = File.read(pid_file)
      `ps -p #{old_pid}`
      if old_pid.to_i > 0 && $?.exitstatus == 1
        puts "Removing stale PID file"
        File.unlink(pid_file)
      end
    end

    puts "Starting #{options[:app]} on #{port}..."
    `/usr/local/bin/mongrel_rails start -d -p #{port} -e #{options[:environment]} -c #{path} -P log/mongrel.pid`
    default_port = port + 1

  end
end

unless ['start', 'stop', 'restart'].include? ARGV.first
    puts "Usage: mongrel {start|stop|restart}"
    exit
end

Flickr photostream

Nick Ludlam posted a photo:Sitting in the Whole Foods cafe in Clapham Junction, this is the list of available WiFi networksNick Ludlam posted a photo:Ordered yesterday, arrived today. The lovely people at Square Mile Coffee are great! Not entirely sure how to prepare this coffee though..Nick Ludlam posted a photo:Calibration of the compass seems necessary, although sometimes I get the "wave in a figure 8" message, and sometimes not.Nick Ludlam posted a photo:At the top of Roche De Mio in La Plagne, 2700m up. In the distance is Mont Blanc. This pic is augmented with the "Peaks" iPhone application. It almost lines up, and was good enough to use it to identify the individual peaks.Nick Ludlam posted a photo:At the top of Roche De Mio in La Plagne, 2700m up. In the distance is Mont Blanc.Nick Ludlam posted a photo:The view of distant peaks from Plagne Centre.Nick Ludlam posted a photo:Mike's talk on Core Data in the Main HallNick Ludlam posted a photo:Mike's talk on Core Data in the Main HallNick Ludlam posted a photo:Hovering very low over Balham, like some massive sinister wasp.

Delicious links