Systemd for voipmonitor service management: Difference between revisions

From VoIPmonitor.org
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
This is valid only for system that use systemd as manager for services. (After following this you will be able to use systemctl or service commands also in your OS with systemd)
{{DISPLAYTITLE:Managing the Sniffer Service with systemd}}


'''We don't recommend to use the service command in systemd environment!! The systemd can lose track of the sensor daemon.'''
'''This guide provides the modern, recommended method for managing the VoIPmonitor sensor service using `systemd`. A properly configured `systemd` unit file ensures that the sensor starts correctly on boot and can be managed reliably with standard system commands.'''


Create file /etc/systemd/system/voipmonitor.service
== Overview ==
[Unit]
Modern Linux distributions (including recent versions of Debian, Ubuntu, CentOS, RHEL, and AlmaLinux) use `systemd` as the primary service manager. While the legacy `/etc/init.d/voipmonitor` script may still work, creating a dedicated `systemd` unit file is a more robust and reliable approach. It provides better dependency management, process tracking, and integration with system logging.
Description=VoIPmonitor sniffer
After=syslog.target
After=network.target
After=mysql.service
[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SuccessExitStatus=5 6
ExecStart=/etc/init.d/voipmonitor start
ExecStop=/etc/init.d/voipmonitor stop
#Place temp files in a secure directory, not /tmp?
PrivateTmp=false
[Install]
WantedBy=multi-user.target


NOTICE: line 'After=mysql.service' gives a sense only if your mysql is installed locally.
'''Warning:''' It is strongly recommended to use the `systemctl` command exclusively to manage the service. Using the older `service` command (e.g., `service voipmonitor start`) can cause `systemd` to lose track of the process's state.


Don't forget systemd reload after change.
== Step 1: Create the systemd Unit File ==
Create a new service file for VoIPmonitor using a text editor:
<pre>
sudo nano /etc/systemd/system/voipmonitor.service
</pre>


systemctl daemon-reload
Copy and paste the following content into the file. This template is a modern replacement for the old `init.d` script and calls the binary directly.
 
<pre>
[Unit]
Description=VoIPmonitor Sniffer Service
Wants=network-online.target
After=network-online.target syslog.target
 
# --- Optional: Add dependencies below if needed ---
# After=mysql.service mariadb.service      # If the database is on the same server
# After=ntservice.service                  # If you use Napatech cards
 
[Service]
Type=simple
User=root
Group=root
 
# The command to start the sniffer.
# The -f flag is important to keep the process in the foreground for systemd.
ExecStart=/usr/local/sbin/voipmonitor -f -c /etc/voipmonitor.conf
 
# Restart the service automatically if it fails
Restart=on-failure
RestartSec=5s
 
# It's good practice to define a clean stop command
ExecStop=/bin/kill -s TERM $MAINPID
 
[Install]
WantedBy=multi-user.target
</pre>
 
== Step 2: Optional Customizations ==
The provided template should work for most installations. However, if you have a special setup, you may need to uncomment or add dependency lines in the `[Unit]` section.
 
;If the database runs on the same server:
:Uncommenting `After=mysql.service mariadb.service` ensures that VoIPmonitor will only start after the database service is fully up and running.
 
;If you use Napatech hardware acceleration cards:
:Uncommenting `After=ntservice.service` ensures the Napatech driver service is started before VoIPmonitor attempts to use the card.
 
== Step 3: Reload systemd and Enable the Service ==
After creating or modifying the unit file, you must tell `systemd` to reload its configuration.
<pre>
sudo systemctl daemon-reload
</pre>
Next, enable the service to ensure it starts automatically every time the server boots.
<pre>
sudo systemctl enable voipmonitor.service
</pre>
 
== Step 4: Managing the Service ==
You can now manage the VoIPmonitor sensor using the standard `systemctl` commands.
 
;To start the service:
<pre>sudo systemctl start voipmonitor</pre>
 
;To stop the service:
<pre>sudo systemctl stop voipmonitor</pre>
 
;To restart the service after a configuration change:
<pre>sudo systemctl restart voipmonitor</pre>
 
;To check the current status and view recent logs:
<pre>sudo systemctl status voipmonitor</pre>
 
;To disable the service from starting on boot:
<pre>sudo systemctl disable voipmonitor</pre>
 
== AI Summary for RAG ==
'''Summary:''' This guide provides a best-practice tutorial for managing the VoIPmonitor sensor service using `systemd` on modern Linux distributions. It explains why using `systemctl` is superior to the legacy `service` command and `init.d` scripts. The core of the article is a modern, recommended `voipmonitor.service` unit file template that calls the sniffer binary directly with the `-f` flag to run it in the foreground. The guide is structured as a step-by-step process: 1) Creating the `/etc/systemd/system/voipmonitor.service` file. 2) Explaining optional customizations, such as adding dependencies for a local MySQL/MariaDB database or Napatech drivers. 3) Reloading the `systemd` daemon and enabling the service to start on boot with `systemctl daemon-reload` and `systemctl enable`. 4) Listing and explaining the standard `systemctl` commands (`start`, `stop`, `restart`, `status`) for day-to-day service management.
'''Keywords:''' systemd, systemctl, service, daemon, init.d, unit file, `voipmonitor.service`, start on boot, enable, restart, status, dependency, `After=`, `Wants=`, `ExecStart`, `Type=simple`
'''Key Questions:'''
* How do I manage the VoIPmonitor sniffer service on a modern Linux system?
* What is the correct `systemd` unit file for VoIPmonitor?
* How do I make the VoIPmonitor sensor start automatically on boot?
* Why shouldn't I use the `service voipmonitor start` command?
* How can I make the VoIPmonitor service wait for the MySQL database to be ready before starting?
* What is the difference between an `init.d` script and a `systemd` service file?
* How do I check the status and logs of the sniffer service with `systemctl`?

Latest revision as of 22:48, 30 June 2025


This guide provides the modern, recommended method for managing the VoIPmonitor sensor service using `systemd`. A properly configured `systemd` unit file ensures that the sensor starts correctly on boot and can be managed reliably with standard system commands.

Overview

Modern Linux distributions (including recent versions of Debian, Ubuntu, CentOS, RHEL, and AlmaLinux) use `systemd` as the primary service manager. While the legacy `/etc/init.d/voipmonitor` script may still work, creating a dedicated `systemd` unit file is a more robust and reliable approach. It provides better dependency management, process tracking, and integration with system logging.

Warning: It is strongly recommended to use the `systemctl` command exclusively to manage the service. Using the older `service` command (e.g., `service voipmonitor start`) can cause `systemd` to lose track of the process's state.

Step 1: Create the systemd Unit File

Create a new service file for VoIPmonitor using a text editor:

sudo nano /etc/systemd/system/voipmonitor.service

Copy and paste the following content into the file. This template is a modern replacement for the old `init.d` script and calls the binary directly.

[Unit]
Description=VoIPmonitor Sniffer Service
Wants=network-online.target
After=network-online.target syslog.target

# --- Optional: Add dependencies below if needed ---
# After=mysql.service mariadb.service       # If the database is on the same server
# After=ntservice.service                   # If you use Napatech cards

[Service]
Type=simple
User=root
Group=root

# The command to start the sniffer.
# The -f flag is important to keep the process in the foreground for systemd.
ExecStart=/usr/local/sbin/voipmonitor -f -c /etc/voipmonitor.conf

# Restart the service automatically if it fails
Restart=on-failure
RestartSec=5s

# It's good practice to define a clean stop command
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

Step 2: Optional Customizations

The provided template should work for most installations. However, if you have a special setup, you may need to uncomment or add dependency lines in the `[Unit]` section.

If the database runs on the same server
Uncommenting `After=mysql.service mariadb.service` ensures that VoIPmonitor will only start after the database service is fully up and running.
If you use Napatech hardware acceleration cards
Uncommenting `After=ntservice.service` ensures the Napatech driver service is started before VoIPmonitor attempts to use the card.

Step 3: Reload systemd and Enable the Service

After creating or modifying the unit file, you must tell `systemd` to reload its configuration.

sudo systemctl daemon-reload

Next, enable the service to ensure it starts automatically every time the server boots.

sudo systemctl enable voipmonitor.service

Step 4: Managing the Service

You can now manage the VoIPmonitor sensor using the standard `systemctl` commands.

To start the service
sudo systemctl start voipmonitor
To stop the service
sudo systemctl stop voipmonitor
To restart the service after a configuration change
sudo systemctl restart voipmonitor
To check the current status and view recent logs
sudo systemctl status voipmonitor
To disable the service from starting on boot
sudo systemctl disable voipmonitor

AI Summary for RAG

Summary: This guide provides a best-practice tutorial for managing the VoIPmonitor sensor service using `systemd` on modern Linux distributions. It explains why using `systemctl` is superior to the legacy `service` command and `init.d` scripts. The core of the article is a modern, recommended `voipmonitor.service` unit file template that calls the sniffer binary directly with the `-f` flag to run it in the foreground. The guide is structured as a step-by-step process: 1) Creating the `/etc/systemd/system/voipmonitor.service` file. 2) Explaining optional customizations, such as adding dependencies for a local MySQL/MariaDB database or Napatech drivers. 3) Reloading the `systemd` daemon and enabling the service to start on boot with `systemctl daemon-reload` and `systemctl enable`. 4) Listing and explaining the standard `systemctl` commands (`start`, `stop`, `restart`, `status`) for day-to-day service management. Keywords: systemd, systemctl, service, daemon, init.d, unit file, `voipmonitor.service`, start on boot, enable, restart, status, dependency, `After=`, `Wants=`, `ExecStart`, `Type=simple` Key Questions:

  • How do I manage the VoIPmonitor sniffer service on a modern Linux system?
  • What is the correct `systemd` unit file for VoIPmonitor?
  • How do I make the VoIPmonitor sensor start automatically on boot?
  • Why shouldn't I use the `service voipmonitor start` command?
  • How can I make the VoIPmonitor service wait for the MySQL database to be ready before starting?
  • What is the difference between an `init.d` script and a `systemd` service file?
  • How do I check the status and logs of the sniffer service with `systemctl`?