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:	From the Android supplement from The Guardian on 29/08/2010. I was interviewed for a piece on the future trends in Mobile apps. www.guardian.co.uk/lg-talking-technology/the-future-of-apps			Nick Ludlam posted a photo:	My wonderful colleagues at BERG bought lots of cake for my birthday. And not just any old cake! This was from Konditor and Cook. It was delicious!We get bonus points for having to cut it with a craft knife, since it was either that or a scalpel.			Nick Ludlam posted a photo:	I've set up a custom Ruby script to scrape my balance information from the Three.co.uk website, and a custom app to receive the notifications. I've set it up to tell me my balance every day, since there is no automatic notification on Three as there is with O2.			Nick Ludlam posted a photo:	Just up the road from BRIG. Lovely coffee, and nice people serving it. The map shows you where it is!			Nick Ludlam posted a photo:	An image of an advertisement in the Sun Newspaper for Android phones sold by Carphone Warehouse here in the UK.Underneath is a section which lists 10 apps that "you need to get through the day". 8 are free, 1 is £1, and the last one did not even seem to be listed when I searched. "Where's The Train", the only non-free app, is listed as having "100 - 500 downloads"This is very typical of my experience with the Android Market. Unless your business model can support free applications, with your revenue coming from advertising, a website or service you sell, then you are unlikely to be able to recoup the time spent developing quality applications.			Nick Ludlam posted a photo:	I love their spoons. As you pull the spoon out of your mouth, you can feel the texture of the detailing on your top lip			Nick Ludlam posted a photo:	The girls pose for a quick picture before heading off to the race start line			Nick Ludlam posted a photo:	That 'Touch here if bicycle is damaged' button will be too tempting			Nick Ludlam posted a photo:	The new bike stands have just appeared on Shoreditch High St.

Delicious links