Systemd for voipmonitor service management

From VoIPmonitor.org
Revision as of 10:09, 6 January 2026 by Admin (talk | contribs) (Add troubleshooting section for systemd unit file errors - fix for Assignment outside of section)

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.

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.

Identify the Problem Type
Service fails to start (systemctl fails): System reports the service cannot start. Symptoms: systemctl start voipmonitor returns error, service shows failed status, or service exits immediately. Continue with this guide.
Service starts but cannot connect to central server: Service shows as active (running) but logs show "cannot connect to server", "connection refused", or "timeout". THIS IS NOT A SYSTEMD ISSUE. Go to 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 this troubleshooting section for network connectivity diagnostics including:

  • Testing connectivity with nc -zv <server_ip> <port>
  • 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:

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


Troubleshooting: Systemd Unit File Errors

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

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

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

First, identify any existing voipmonitor processes:

ps aux | grep voipmonitor

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:

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

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

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

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

Fixing the Systemd Unit File

Once the service is running via the init.d script, permanently fix the systemd unit file:

# 1. Check the unit file for syntax errors
systemctl status voipmonitor.service

# 2. Review the unit file contents
cat /etc/systemd/system/voipmonitor.service

# 3. Common errors include:
#    - 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
sudo systemctl daemon-reload

# 5. Now you can use systemctl again
sudo systemctl start voipmonitor

Using the Legacy Init.d Service Configuration

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:

[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

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:

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?

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