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.
-
Open the Monit control file,
/etc/monit/monitrc
by default, with a text editor. -
Add the following service check:
For systems using Initcheck 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 Systemdcheck process nxlog with pidfile /opt/nxlog/var/run/nxlog/nxlog.pid start program = "/bin/systemctl start nxlog" stop program = "/bin/systemctl stop nxlog"
-
Save your changes and restart Monit.
$ sudo systemctl restart monit
-
Simulate an NXLog Agent crash by terminating the
nxlog
process to test the Monit check. Retrieve thenxlog
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:
-
Open the Services console (services.msc).
-
Locate the nxlog service and right-click on it.
-
Choose Properties.
-
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.
-
Click Apply, then OK.
-
Simulate an NXLog Agent crash by terminating the
nxlog
process to test the configuration. Retrieve thenxlog
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.