Automatically restart NXLog Agent

At NXLog, we realize that our agent can be critical for our customers, and we make every effort to ensure its quality and reliability. However, we all know that bug-free software does not exist. Below, we provide some options to restart NXLog Agent automatically in case of failure.

Using Monit

Monit is an open-source utility that can monitor and recover a service in case of a crash. You can install Monit on macOS, Solaris, and many Linux distributions. Refer to the Monit wiki for Installation instructions.

Monit supports various types of checks and actions. The steps below guide you in adding a simple service check to start NXLog Agent if it stops unexpectedly.

  1. Open the Monit control file, /etc/monit/monitrc by default, with a text editor.

  2. Add the following service check:

    For systems using Init
    check process nxlog with pidfile /opt/nxlog/var/run/nxlog/nxlog.pid
       start program = "/etc/init.d/nxlog start"
       stop program  = "/etc/init.d/nxlog stop"
    For systems using Systemd
    check process nxlog with pidfile /opt/nxlog/var/run/nxlog/nxlog.pid
       start program = "/bin/systemctl start nxlog"
       stop program  = "/bin/systemctl stop nxlog"
  3. Save your changes and restart Monit.

    $ sudo systemctl restart monit
  4. Simulate an NXLog Agent crash by terminating the nxlog process to test the Monit check. Retrieve the nxlog process ID from /opt/nxlog/var/run/nxlog/nxlog.pid and execute the following command. Replace <PID> with the actual process ID.

    $ kill -9 <PID>

    The NXLog Agent service should start again automatically, most probably with a different process ID.

    The steps above use the default NXLog Agent installation path. Change the path accordingly if you installed NXLog Agent in a different location.

Using Windows Service Control Manager

For NXLog Agent on Windows, the Service Control Manager (SCM) provides automatic recovery options. Follow these steps to configure the NXLog Agent service to restart automatically after a failure:

  1. Open the Services console (services.msc).

  2. Locate the nxlog service and right-click on it.

  3. Choose Properties.

    NXLog Agent service properties
  4. Switch to the Recovery tab. NXLog Agent enables automatic recovery during installation, as displayed in the image below. Change these settings according to your requirements if necessary.

    NXLog Agent service recovery options
  5. Click Apply, then OK.

  6. Simulate an NXLog Agent crash by terminating the nxlog process to test the configuration. Retrieve the nxlog process ID from Task Manager and execute the following PowerShell command. Replace <PID> with the actual process ID.

    PS> Taskkill /PID <PID> /F

    The NXLog Agent service should start again automatically, most probably with a different process ID.