Systemd for voipmonitor service management: Difference between revisions

From VoIPmonitor.org
(Add troubleshooting section for systemd unit file errors - fix for Assignment outside of section)
(Review: cleanup duplicate content, remove test text, fix formatting (pre->syntaxhighlight), keep proven init.d wrapper config)
Line 1: Line 1:
== systemd ==
{{DISPLAYTITLE:Managing the Sniffer Service with systemd}}
This is valid only for system that use systemd as manager for services.
[[Category:Configuration]]
[[Category:Installation]]
 
'''This guide provides the recommended method for managing the VoIPmonitor sensor service using systemd on modern Linux distributions.'''
 
== Overview ==
 
Modern Linux distributions (Debian, Ubuntu, CentOS, RHEL, AlmaLinux) use systemd as the primary service manager. The recommended approach is to create a systemd unit file that wraps the reliable <code>/etc/init.d/voipmonitor</code> script, ensuring compatibility across various distributions.
 
{| class="wikitable" style="background:#fff3cd; border:1px solid #ffc107;"
|-
! style="background:#ffc107;" | Important Warning
|-
| '''Always use <code>systemctl</code> commands to manage the service.''' Do not use the legacy <code>service</code> command (e.g., <code>service voipmonitor start</code>) as systemd may lose track of the process state.
|}


===beware of use the service command===
== Unit File Configuration ==
'''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 <code>/etc/systemd/system/voipmonitor.service</code>:
Create file /etc/systemd/system/voipmonitor.service
 
<syntaxhighlight lang="ini">
[Unit]
[Unit]
Description=VoIPmonitor sniffer
Description=VoIPmonitor sniffer
Line 25: Line 38:
ExecStart=/etc/init.d/voipmonitor start
ExecStart=/etc/init.d/voipmonitor start
ExecStop=/etc/init.d/voipmonitor stop
ExecStop=/etc/init.d/voipmonitor stop
#Place temp files in a secure directory, not /tmp?
PrivateTmp=false
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}}
'''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.'''
== Important: Service Not Starting vs Connection Failures ==
Before troubleshooting systemd issues, identify whether the problem is with the systemd service OR with network connectivity to the central server.
{| class="wikitable" style="background:#fff3cd; border:1px solid #ffc107;"
|-
! colspan="2" style="background:#ffc107;" | Identify the Problem Type
|-
| style="vertical-align: top;" | '''Service fails to start (systemctl fails):'''
| System reports the service cannot start. Symptoms: <code>systemctl start voipmonitor</code> returns error, service shows <code>failed</code> status, or service exits immediately. Continue with this guide.
|-
| style="vertical-align: top;" | '''Service starts but cannot connect to central server:'''
| Service shows as <code>active (running)</code> but logs show "cannot connect to server", "connection refused", or "timeout". THIS IS NOT A SYSTEMD ISSUE. Go to [[Sniffer_distributed_architecture#Troubleshooting_Connection_Failures|Distributed Architecture: Troubleshooting Connection Failures]].
|}
For sensors that cannot connect to a central server (error messages about connection failures, time synchronization, or packet buffering), see [[Sniffer_distributed_architecture#Troubleshooting_Connection_Failures|this troubleshooting section]] for network connectivity diagnostics including:
* Testing connectivity with <code>nc -zv &lt;server_ip&gt; &lt;port&gt;</code>
* Firewall configuration
* Port verification (server_bind_port matches server_destination_port)
* MySQL database connectivity
== 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:
<pre>
sudo nano /etc/systemd/system/voipmonitor.service
</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.
<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=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]
[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
</pre>
</syntaxhighlight>


== Step 2: Optional Customizations ==
== Dependency Customization ==
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:
=== MySQL/MariaDB ===
: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:
The line <code>After=mysql.service</code> is only required if the database is installed locally on the same server. If your database runs on a remote server, you can remove this line.
: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 ==
=== Napatech Cards ===
After creating or modifying the unit file, you must tell systemd to reload its configuration.


<pre>
If you use Napatech hardware acceleration cards, add the following lines to the <code>[Unit]</code> section to ensure drivers load before VoIPmonitor starts:
sudo systemctl daemon-reload
</pre>


<syntaxhighlight lang="ini">
Before=network-pre.target
Wants=network-pre.target
After=ntservice.service
Requires=ntservice.service
</syntaxhighlight>


Next, enable the service to ensure it starts automatically every time the server boots.
== Activation and Management ==


<pre>
=== Reload systemd after changes ===
sudo systemctl enable voipmonitor.service
</pre>


<syntaxhighlight lang="bash">
systemctl daemon-reload
</syntaxhighlight>


== Step 4: Managing the Service ==
=== Enable start on boot ===
You can now manage the VoIPmonitor sensor using the standard systemctl commands.


;To start the service:
<syntaxhighlight lang="bash">
systemctl enable voipmonitor
</syntaxhighlight>


<pre>sudo systemctl start voipmonitor</pre>
=== Standard management commands ===


<syntaxhighlight lang="bash">
# Start the service
systemctl start voipmonitor


;To stop the service:
# Stop the service
systemctl stop voipmonitor


<pre>sudo systemctl stop voipmonitor</pre>
# Restart the service
systemctl restart voipmonitor


# Check status and view recent logs
systemctl status voipmonitor
</syntaxhighlight>


;To restart the service after a configuration change:
== Troubleshooting ==


<pre>sudo systemctl restart voipmonitor</pre>
=== Service Not Starting vs Connection Failures ===


Before troubleshooting systemd issues, identify whether the problem is with the systemd service OR with network connectivity:


;To check the current status and view recent logs:
{| class="wikitable"
 
|-
<pre>sudo systemctl status voipmonitor</pre>
! Problem Type !! Symptoms !! Solution
 
|-
 
| '''Service fails to start''' || <code>systemctl start voipmonitor</code> returns error, service shows <code>failed</code> status || Continue with this guide
;To disable the service from starting on boot:
|-
 
| '''Service starts but cannot connect''' || Service shows <code>active (running)</code> but logs show "cannot connect to server" || See [[Sniffer_distributed_architecture#Troubleshooting_Connection_Failures|Distributed Architecture Troubleshooting]]
<pre>sudo systemctl disable voipmonitor</pre>
|}
 


== Troubleshooting: Systemd Unit File Errors ==
=== Unit File Syntax Errors ===


If you encounter systemd errors when trying to start the voipmonitor service, such as:
If you encounter errors like:


<pre>Error: Assignment outside of section. Ignoring.
<syntaxhighlight lang="text">
Error: Assignment outside of section. Ignoring.
Job for voipmonitor.service failed because the control process exited with error code.
Job for voipmonitor.service failed because the control process exited with error code.
</pre>
</syntaxhighlight>
 
This indicates that the systemd unit file (/etc/systemd/system/voipmonitor.service) has syntax errors. In this situation, you can bypass the faulty systemd unit and start the service directly using the init.d script.


=== Identifying and Removing the Problematic Processes ===
This indicates syntax errors in the unit file. To bypass and fix:


First, identify any existing voipmonitor processes:
<syntaxhighlight lang="bash">
 
# 1. Identify existing processes
<pre>
ps aux | grep voipmonitor
ps aux | grep voipmonitor
</pre>
You will typically see:
- The main voipmonitor process binary
- A watchdog process (monitors the main process and restarts it if it crashes)
=== Stopping Processes and Bypassing Systemd ===
Follow these steps to manually stop and restart the service using the init.d script:


<pre>
# 2. Kill the watchdog process first (find its PID from ps output)
# 1. Kill the watchdog process first (find its PID from ps aux output)
kill <PID_WATCHDOG>
kill <PID_WATCHDOG>


# 2. Kill the main voipmonitor process (use -9 to force if needed)
# 3. Kill the main voipmonitor process
kill -9 <PID_VOIPMONITOR>
kill -9 <PID_VOIPMONITOR>


# 3. Stop the service using the init.d script (cleans up any remaining artifacts)
# 4. Stop using init.d script
/etc/init.d/voipmonitor stop
/etc/init.d/voipmonitor stop


# 4. Start the service using the init.d script (bypasses the broken systemd unit)
# 5. Start using init.d script (bypasses broken systemd unit)
/etc/init.d/voipmonitor start
/etc/init.d/voipmonitor start
</pre>
</syntaxhighlight>
 
=== Fixing the Systemd Unit File ===
 
Once the service is running via the init.d script, permanently fix the systemd unit file:


<pre>
=== Common Unit File Errors ===
# 1. Check the unit file for syntax errors
systemctl status voipmonitor.service


# 2. Review the unit file contents
* Missing <code>[Unit]</code>, <code>[Service]</code>, or <code>[Install]</code> section headers
cat /etc/systemd/system/voipmonitor.service
* Assignments placed outside of their proper sections
* Typos in directive names (e.g., <code>ExecStar</code> instead of <code>ExecStart</code>)
* Missing equals (<code>=</code>) signs between directive and value


# 3. Common errors include:
After fixing the unit file:
#    - Missing [Unit], [Service], or [Install] section headers
#    - Assignments placed outside of their proper sections
#    - Typos in directive names (e.g., ExecStar instead of ExecStart)
#    - Missing equals (=) signs between directive and value


# 4. After fixing the unit file, reload systemd
<syntaxhighlight lang="bash">
sudo systemctl daemon-reload
sudo systemctl daemon-reload
# 5. Now you can use systemctl again
sudo systemctl start voipmonitor
sudo systemctl start voipmonitor
</pre>
</syntaxhighlight>


=== Using the Legacy Init.d Service Configuration ===
== AI Summary for RAG ==


If you prefer to stick with the init.d wrapper approach (which some users find more stable on certain distributions like AlmaLinux), use this systemd unit file instead:
'''Summary:''' This guide provides the stable method for managing the VoIPmonitor sensor using systemd by wrapping the legacy init.d script in a unit file. This approach ensures compatibility across various distributions including AlmaLinux 9.5. The unit file configuration uses <code>Type=forking</code> with <code>RemainAfterExit=yes</code> and calls <code>/etc/init.d/voipmonitor start/stop</code> directly. Key dependencies include <code>After=mysql.service</code> for local databases and <code>After=ntservice.service</code> with <code>Requires=ntservice.service</code> for Napatech hardware. The guide emphasizes using <code>systemctl</code> commands exclusively (never the legacy <code>service</code> command) for reliable process tracking. Troubleshooting covers distinguishing between systemd failures and network connectivity issues, and provides steps to bypass a faulty unit file using the init.d script directly.


<pre>
'''Keywords:''' systemd, systemctl, voipmonitor.service, init.d wrapper, unit file, Type=forking, RemainAfterExit, dependency, After=mysql.service, Napatech, AlmaLinux, service management, daemon-reload, enable on boot
[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
PrivateTmp=false
[Install]
WantedBy=multi-user.target
</pre>
This configuration calls the /etc/init.d/voipmonitor script directly, which has been tested and proven to work reliably on various distributions.
== 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. 5) Troubleshooting systemd unit file errors: when encountering errors like "Assignment outside of section", the guide explains how to identify existing processes, kill the watchdog and main voipmonitor process manually, then start the service using the init.d script to bypass the faulty systemd unit. It also provides the legacy init.d wrapper systemd configuration as a stable alternative for distributions like AlmaLinux.
'''Keywords:''' systemd, systemctl, service, daemon, init.d, unit file, voipmonitor.service, start on boot, enable, restart, status, dependency, After=, Wants=, ExecStart, Type=simple, troubleshooting, Assignment outside of section, bypass systemd, kill process, watchdog, syntax error
'''Key Questions:'''
'''Key Questions:'''
 
* What is the recommended systemd configuration for VoIPmonitor?
How do I manage the VoIPmonitor sniffer service on a modern Linux system?
* Why should I avoid the <code>service</code> command and use <code>systemctl</code>?
 
* How do I configure systemd to wait for MySQL before starting VoIPmonitor?
What is the correct systemd unit file for VoIPmonitor?
* How do I ensure Napatech drivers are loaded before the sniffer starts?
 
* What is the correct content of /etc/systemd/system/voipmonitor.service?
How do I make the VoIPmonitor sensor start automatically on boot?
* How do I make VoIPmonitor start automatically on boot?
 
* How do I bypass a broken systemd unit file and start VoIPmonitor manually?
Why shouldn't I use the service voipmonitor start command?
* What causes "Assignment outside of section" error in systemd?
 
* How do I troubleshoot VoIPmonitor service startup failures?
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?
 
What do I do if I see "Assignment outside of section" error when starting systemd service?
 
How do I bypass a broken systemd unit file and start VoIPmonitor using init.d?
 
How do I kill the watchdog and voipmonitor processes manually?
 
How do I fix syntax errors in a systemd unit file?
 
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

Revision as of 11:24, 6 January 2026


This guide provides the recommended method for managing the VoIPmonitor sensor service using systemd on modern Linux distributions.

Overview

Modern Linux distributions (Debian, Ubuntu, CentOS, RHEL, AlmaLinux) use systemd as the primary service manager. The recommended approach is to create a systemd unit file that wraps the reliable /etc/init.d/voipmonitor script, ensuring compatibility across various distributions.

Important Warning
Always use systemctl commands to manage the service. Do not use the legacy service command (e.g., service voipmonitor start) as systemd may lose track of the process state.

Unit File Configuration

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
PrivateTmp=false

[Install]
WantedBy=multi-user.target

Dependency Customization

MySQL/MariaDB

The line After=mysql.service is only required if the database is installed locally on the same server. If your database runs on a remote server, you can remove this line.

Napatech Cards

If you use Napatech hardware acceleration cards, add the following lines to the [Unit] section to ensure drivers load before VoIPmonitor starts:

Before=network-pre.target
Wants=network-pre.target
After=ntservice.service
Requires=ntservice.service

Activation and Management

Reload systemd after changes

systemctl daemon-reload

Enable start on boot

systemctl enable voipmonitor

Standard management commands

# Start the service
systemctl start voipmonitor

# Stop the service
systemctl stop voipmonitor

# Restart the service
systemctl restart voipmonitor

# Check status and view recent logs
systemctl status voipmonitor

Troubleshooting

Service Not Starting vs Connection Failures

Before troubleshooting systemd issues, identify whether the problem is with the systemd service OR with network connectivity:

Problem Type Symptoms Solution
Service fails to start systemctl start voipmonitor returns error, service shows failed status Continue with this guide
Service starts but cannot connect Service shows active (running) but logs show "cannot connect to server" See Distributed Architecture Troubleshooting

Unit File Syntax Errors

If you encounter errors like:

Error: Assignment outside of section. Ignoring.
Job for voipmonitor.service failed because the control process exited with error code.

This indicates syntax errors in the unit file. To bypass and fix:

# 1. Identify existing processes
ps aux | grep voipmonitor

# 2. Kill the watchdog process first (find its PID from ps output)
kill <PID_WATCHDOG>

# 3. Kill the main voipmonitor process
kill -9 <PID_VOIPMONITOR>

# 4. Stop using init.d script
/etc/init.d/voipmonitor stop

# 5. Start using init.d script (bypasses broken systemd unit)
/etc/init.d/voipmonitor start

Common Unit File Errors

  • Missing [Unit], [Service], or [Install] section headers
  • Assignments placed outside of their proper sections
  • Typos in directive names (e.g., ExecStar instead of ExecStart)
  • Missing equals (=) signs between directive and value

After fixing the unit file:

sudo systemctl daemon-reload
sudo systemctl start voipmonitor

AI Summary for RAG

Summary: This guide provides the stable method for managing the VoIPmonitor sensor using systemd by wrapping the legacy init.d script in a unit file. This approach ensures compatibility across various distributions including AlmaLinux 9.5. The unit file configuration uses Type=forking with RemainAfterExit=yes and calls /etc/init.d/voipmonitor start/stop directly. Key dependencies include After=mysql.service for local databases and After=ntservice.service with Requires=ntservice.service for Napatech hardware. The guide emphasizes using systemctl commands exclusively (never the legacy service command) for reliable process tracking. Troubleshooting covers distinguishing between systemd failures and network connectivity issues, and provides steps to bypass a faulty unit file using the init.d script directly.

Keywords: systemd, systemctl, voipmonitor.service, init.d wrapper, unit file, Type=forking, RemainAfterExit, dependency, After=mysql.service, Napatech, AlmaLinux, service management, daemon-reload, enable on boot

Key Questions:

  • What is the recommended systemd configuration for VoIPmonitor?
  • Why should I avoid the service command and use systemctl?
  • How do I configure systemd to wait for MySQL before starting VoIPmonitor?
  • How do I ensure Napatech drivers are loaded before the sniffer starts?
  • What is the correct content of /etc/systemd/system/voipmonitor.service?
  • How do I make VoIPmonitor start automatically on boot?
  • How do I bypass a broken systemd unit file and start VoIPmonitor manually?
  • What causes "Assignment outside of section" error in systemd?
  • How do I troubleshoot VoIPmonitor service startup failures?