Systemd for voipmonitor service management: Difference between revisions

From VoIPmonitor.org
Jump to navigation Jump to search
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
== systemd ==
This is valid only for system that use systemd as manager for services.
===beware of use the service command===
'''We don't recommend to use the service command in systemd environment for manage the sniffer service state!!
The systemd can lose track of the sensor daemon.'''
==systemd's service file for voipmonitor==
Create file /etc/systemd/system/voipmonitor.service
[Unit]
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
===service file and db host===
NOTICE: line 'After=mysql.service' gives a sense only if your mysql is installed locally.
===service file and napatech drivers===
Add into service file follwing lines to make sure napatech drivers are initialized before start of the sniffer service.
Before=network-pre.target
Wants=network-pre.target
After=ntservice.service
Requires=ntservice.service
==reload systemd==
Don't forget systemd reload after change.
systemctl daemon-reload
toto je puvodni wikimedia stranka
a toto je nova wikimedia stranka
{{DISPLAYTITLE:Managing the Sniffer Service with systemd}}
{{DISPLAYTITLE:Managing the Sniffer Service with systemd}}


'''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.'''
'''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 ==
== 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.
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.
'''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 ==
== Step 1: Create the systemd Unit File ==
Create a new service file for VoIPmonitor using a text editor:
Create a new service file for VoIPmonitor using a text editor:
<pre>
<pre>
sudo nano /etc/systemd/system/voipmonitor.service
sudo nano /etc/systemd/system/voipmonitor.service
</pre>
</pre>


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.
 
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>
<pre>
Line 27: Line 77:


[Service]
[Service]
Type=simple
Type=forking
User=root
User=root
Group=root
Group=root
Line 33: Line 83:
# The command to start the sniffer.
# The command to start the sniffer.
# The -f flag is important to keep the process in the foreground for systemd.
# The -f flag is important to keep the process in the foreground for systemd.
ExecStart=/usr/local/sbin/voipmonitor -f -c /etc/voipmonitor.conf
ExecStart=/usr/local/sbin/voipmonitor --config-file /etc/voipmonitor.conf -v1


# Restart the service automatically if it fails
# Restart the service automatically if it fails
Line 47: Line 97:


== Step 2: Optional Customizations ==
== 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.
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:
;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.
: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:
;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.
: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 ==
== Step 3: Reload systemd and Enable the Service ==
After creating or modifying the unit file, you must tell `systemd` to reload its configuration.
After creating or modifying the unit file, you must tell systemd to reload its configuration.
 
<pre>
<pre>
sudo systemctl daemon-reload
sudo systemctl daemon-reload
</pre>
</pre>
Next, enable the service to ensure it starts automatically every time the server boots.
Next, enable the service to ensure it starts automatically every time the server boots.
<pre>
<pre>
sudo systemctl enable voipmonitor.service
sudo systemctl enable voipmonitor.service
</pre>
</pre>


== Step 4: Managing the Service ==
== Step 4: Managing the Service ==
You can now manage the VoIPmonitor sensor using the standard `systemctl` commands.
You can now manage the VoIPmonitor sensor using the standard systemctl commands.


;To start the service:
;To start the service:
<pre>sudo systemctl start voipmonitor</pre>
<pre>sudo systemctl start voipmonitor</pre>


;To stop the service:
;To stop the service:
<pre>sudo systemctl stop voipmonitor</pre>
<pre>sudo systemctl stop voipmonitor</pre>


;To restart the service after a configuration change:
;To restart the service after a configuration change:
<pre>sudo systemctl restart voipmonitor</pre>
<pre>sudo systemctl restart voipmonitor</pre>


;To check the current status and view recent logs:
;To check the current status and view recent logs:
<pre>sudo systemctl status voipmonitor</pre>
<pre>sudo systemctl status voipmonitor</pre>


;To disable the service from starting on boot:
;To disable the service from starting on boot:
<pre>sudo systemctl disable voipmonitor</pre>
<pre>sudo systemctl disable voipmonitor</pre>


== AI Summary for RAG ==
== 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.
'''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`
'''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:'''
'''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 manage the VoIPmonitor sniffer service on a modern Linux system?
* How do I make the VoIPmonitor sensor start automatically on boot?
 
* Why shouldn't I use the `service voipmonitor start` command?
What is the correct systemd unit file for VoIPmonitor?
* 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 make the VoIPmonitor sensor start automatically on boot?
* How do I check the status and logs of the sniffer service with `systemctl`?
 
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?
 
a pise mi kolega:
 
Ahoj, tenhle service file mi funguje na almaliux 9.5
ten novy (upraveny) nespusti sluzbu: (overil jsem a svem almalinux 9.5)
 
potrebuju, abys mi tu wikimedia stranku opravil tak, aby se to drzelo toho puvodniho, ktery fungoval - dej mi to opet ve wikimedia formatu

Latest revision as of 18:04, 30 July 2025

systemd

This is valid only for system that use systemd as manager for services.

beware of use the service command

We don't recommend to use the service command in systemd environment for manage the sniffer service state!! The systemd can lose track of the sensor daemon.

systemd's service file for voipmonitor

Create file /etc/systemd/system/voipmonitor.service [Unit] 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

  1. Place temp files in a secure directory, not /tmp?

PrivateTmp=false [Install] WantedBy=multi-user.target

service file and db host

NOTICE: line 'After=mysql.service' gives a sense only if your mysql is installed locally.

service file and napatech drivers

Add into service file follwing lines to make sure napatech drivers are initialized before start of the sniffer service. Before=network-pre.target Wants=network-pre.target After=ntservice.service Requires=ntservice.service

reload systemd

Don't forget systemd reload after change. systemctl daemon-reload

toto je puvodni wikimedia stranka

a toto je nova wikimedia stranka


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=forking
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 --config-file /etc/voipmonitor.conf -v1

# 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?

a pise mi kolega:

Ahoj, tenhle service file mi funguje na almaliux 9.5 ten novy (upraveny) nespusti sluzbu: (overil jsem a svem almalinux 9.5)

potrebuju, abys mi tu wikimedia stranku opravil tak, aby se to drzelo toho puvodniho, ktery fungoval - dej mi to opet ve wikimedia formatu