Making Mongrel ignore stale PID files with SMF

2008 November 17
by willcannings

Mongrel has an annoying ‘feature’ where it will bail out of startup if it finds a PID file already existing where it wants to write one. Without checking if the PID is actually stale or not, it will assume a server already exists and exit. Mongrel cluster has a –clean flag that will remove all existing PID files, but using Mongrel cluster makes it difficult to use SMF to keep all individual Mongrel instances up.

To get around this, we need to remove the PID file as part of the start script in our SMF manifest. e.g:

rm -f /path/to/pid/file

Unfortunately, chaining commands together with ‘;’ will cause SMF to think the script is exiting prematurely – rm will return 0 and exit, making SMF think the service has died. Instead we need to ‘hack’ it to work. Mongrel ignores anything on STDIN, so we can pipe the rm command to Mongrel, and all will work nicely:

rm -f /path/to/pid/file | /opt/local/bin/mongrel start ...
4 Responses leave one →
  1. 2009 March 10
    Ben permalink

    Can’t use && or || ?

  2. 2009 March 10
    Ben permalink

    Also, really old post is really old as I just realised.

  3. 2009 March 10
    Ben permalink

    Also your nice buttons seem to break theme when I click them (Firefox 3).

  4. 2009 June 25
    Ferdinand Svehla permalink

    I highly recommend writing a script to execute in your “start” method

    #!/usr/bin/ksh93
    
    rm -f /path/to/pid/file
    /opt/local/bin/mongrel start ..

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS