Developing software in the Real World

Setting up mailcatcher as a service in Debian/Ubuntu

I’ve recently been changing‘s Vagrant system to use Debian and one issue I came across was getting Mailcatcher to start on boot and integrate property with the service command.

To do this, I created an init script which is based off the skeleton and then stored this in /etc/init.d and then ran update-rc.d mailcatcher defaults to set up the correct links in the various rc.d directories.

This is the init script:


As you can probably tell, it’s very obviously a tweaked version of /etc/init.d/skeleton, but there are some important changes:

Path to binary
As Mailcatcher is a ruby app, the correct path to the binary is actually /usr/local/rvm/wrappers/default/mailcatcher which is not where which tells you it is. I suspect that my lack of knowledge about Ruby environments is showing…

The do_start() function calls through to start-stop-daemon to start mailcatcher. However this doesn’t create a pid file in /var/run for us, so we create it ourselves using:

Mailcatcher is intended to be stopped by pressing the Quit button in the HTML interface, so the default code in skeleton doesn’t work. I rewrote it to simply kill the process if the pid file exists:

That’s it. The most important thing about these changes is that service mailcatcher status now works as expected and so Puppet’s ensure => 'running' test actually works correctly.

2 thoughts on “Setting up mailcatcher as a service in Debian/Ubuntu

  1. Thanks Rob.

    I had to make some adjustments to make it work for me. Don't know if it's because I installed mailcatcher without RVM.

    I used the path /usr/local/bin/, as which was telling me.

    Replaced pidof mailcatcher >> $PIDFILE with the --make-pidfile option on start-stop-daemon in do_start() to create the pidfile.

    By adding the --foreground option on mailcatcher (added to DAEMON_ARGS I was able to get the correct pid in the pidfile. This was necessary because the mailcatcher command spawns a ruby process.

    I used the standard do_stop() method as provided by the skeleton.

    For convenience I also added the --background option on start-stop-daemon to start the service in the background.

Comments are closed.