Starting NRPE via launchd : arfore dot com

Last week I posted on how to setup NRPE on Mac OS X Server.  Here is what you need to do to make it start up at system boot.

On a Linux or Solaris machine you can just include the call to the daemon in an init script like rc.local and it will be started when the OS boots.  Unfortunately, Apple has made this a little more difficult on Mac OS X with Tiger and Leopard.  The standard startup processes (cron, inetd, xinetd, etc.) have been rolled into a single process known as launchd.

The first step is to create a symbolic link to the NRPE config file from the default location to the root of the NRPE directory.

  1. cd /usr/local/nagios/
  2. ln -s etc/nrpe.cfg nrpe.cfg

The next setp is to ensure that the NRPE daemon will be able to connect with Nagios server.  There are two ways to do this.  One way is to add a line to the /etc/services file to allow for an open port for NRPE.  The second way is to open the port as part of the launchd process.

Method One – edit the /etc/services file

  1. cd /etc/
  2. sudo vi /etc/services
  3. add the following line to the end of the file:
    5666/tcp # Nagios NRPE client

Method Two – use the launchd process

This method involves including a dictionary key into the launchd plist file that sets the socket type and port number for the NRPE service to use for listening.  The plist code is shown below:

Sockets Listeners SockServiceName 5666 SockType stream SockFamily IPv4

The rest of setting up the plist is required to make the process work.  Here is a copy of my entire plist:

KeepAlive NetworkState UserName nagios GroupName nagios Program /usr/local/nagios/bin/nrpe ProgramArguments -c /usr/local/nagios/etc/nrpe.cfg -i Sockets Listeners SockServiceName 5666 SockType stream SockFamily IPv4 inetdCompatibility Wait Label org.nagios.nrpe

Copy the above code into a text file and name it nrpe.plist and copy it into the /Library/LaunchDaemons/ directory.  You can manually start the service by executing the following commands:

  1. sudo launchctl load /Library/LaunchDaemons/nrpe.plist
  2. sudo launchctl start org.nagios.nrpe

Download the plist file here

%d bloggers like this: