Puppet service config for ejabberd

Posted: 2013-12-13

I have an issue getting a working puppet service config for ejabberd on debian.

The init.d script supports the following options:

Usage: /etc/init.d/ejabberd {start|stop|restart|force-reload|live}

So - it has restart but not status. That means setting hasstatus to false and giving it a status command.

OK - let's fall back to a ps based status - we want to look for the ejabberd process (beam).

ps -ef | grep beam

We're not interested in the grep processes

ps -ef | grep beam | grep -v grep

But we also want a return status - not output

ps -ef | grep beam | grep -qv grep

This should set the return status correctly.

In fact I can test too:

$ ps -ef | grep beam | grep -qv grep
$ echo $?
0

And if I change to grep after a non-existant process (just to test)

$ ps -ef | grep beamx | grep -qv grep
$ echo $?
1

So I created the following service definition:

class ejabberd::service {
  service { 'ejabberd':
    ensure     => running,
    hasstatus  => false,
    hasrestart => true,
    status     => 'ps -ef | grep beam | grep -qv grep',
    enable     => true,
    require    => Class['ejabberd::config'],
  }
}

This worked to start with - but recently it suddenly started restarting the process every puppet run - here's the output from logcheck:

--------------------- Puppet Begin ------------------------


Service starts:
    ejabberd: 143 Time(s)

---------------------- Puppet End -------------------------

And I can't for the life of me see why.