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)
(Rewrite: konsolidace a vylepšení struktury - zjednodušeno z 384 na 177 řádků)
 
(6 intermediate revisions by the same user not shown)
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]]


===beware of use the service command===
'''This guide covers managing the VoIPmonitor sensor service using systemd on modern Linux distributions.'''
'''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==
{{Warning|1='''Always use <code>systemctl</code> commands.''' Do not use the legacy <code>service</code> command as systemd may lose track of the process state.}}
Create file /etc/systemd/system/voipmonitor.service
 
== Unit File Configuration ==
 
Create <code>/etc/systemd/system/voipmonitor.service</code>:
 
<syntaxhighlight lang="ini">
[Unit]
[Unit]
Description=VoIPmonitor sniffer
Description=VoIPmonitor sniffer
After=syslog.target
After=syslog.target network.target
After=network.target
# Add mysql.service only if DB is local (see Dependencies below)
After=mysql.service


[Service]
[Service]
Type=forking
Type=forking
Restart=no
RemainAfterExit=yes
TimeoutSec=5min
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
KillMode=process
GuessMainPID=no
GuessMainPID=no
RemainAfterExit=yes
IgnoreSIGPIPE=no
SuccessExitStatus=5 6
SuccessExitStatus=5 6
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]
[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
</syntaxhighlight>


===service file and db host===
=== Dependencies ===
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 ==
{| class="wikitable"
 
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
! Scenario !! Add to [Unit] section
|-
|-
| style="vertical-align: top;" | '''Service fails to start (systemctl fails):'''
| '''Local MySQL/MariaDB''' || <code>After=mysql.service</code>
| 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:'''
| '''Napatech SmartNIC''' || <code>After=ntservice.service</code><br/><code>Requires=ntservice.service</code><br/><code>Wants=network-pre.target</code><br/><code>Before=network-pre.target</code>
| 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:
== Basic Commands ==
* 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 ==
<syntaxhighlight lang="bash">
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.
# After any unit file changes
 
systemctl daemon-reload
'''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>
# Enable auto-start on boot
sudo nano /etc/systemd/system/voipmonitor.service
systemctl enable voipmonitor
</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 ---
# Start/Stop/Restart
# After=mysql.service mariadb.service      # If the database is on the same server
systemctl start voipmonitor
# After=ntservice.service                  # If you use Napatech cards
systemctl stop voipmonitor
systemctl restart voipmonitor


[Service]
# Check status
Type=forking
systemctl status voipmonitor
User=root
</syntaxhighlight>
Group=root


# The command to start the sniffer.
== Watchdog Integration ==
# 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
When using the internal watchdog with systemd, configure it to restart via systemctl. Otherwise, systemd will incorrectly report the service as "failed" after a watchdog-triggered restart.
Restart=on-failure
RestartSec=5s


# It's good practice to define a clean stop command
Add to <code>/etc/voipmonitor.conf</code>:
ExecStop=/bin/kill -s TERM $MAINPID


[Install]
<syntaxhighlight lang="ini">
WantedBy=multi-user.target
watchdog = yes
</pre>
watchdog_run_command = systemctl restart voipmonitor
</syntaxhighlight>


== Step 2: Optional Customizations ==
== Controlling Verbose Output ==
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:
By default, VoIPmonitor outputs statistics to syslog every 10 seconds (controlled by <code>-v 1</code> in the init.d script).
: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:
=== Option 1: Redirect to Dedicated Log (Recommended) ===
: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 ==
Add to <code>/etc/rsyslog.conf</code>:
After creating or modifying the unit file, you must tell systemd to reload its configuration.


<pre>
<syntaxhighlight lang="rsyslog">
sudo systemctl daemon-reload
if $programname == 'voipmonitor' then /var/log/voipmonitor.log
</pre>
& ~
</syntaxhighlight>


Then: <code>systemctl restart rsyslog</code>


Next, enable the service to ensure it starts automatically every time the server boots.
=== Option 2: Disable Statistics Entirely ===


<pre>
{{Warning|This removes valuable diagnostic metrics. Only use if necessary.}}
sudo systemctl enable voipmonitor.service
</pre>


Edit <code>/etc/init.d/voipmonitor</code>, find the <code>ARGS=</code> line, and remove <code>-v 1</code> (or <code>v 1</code>):


== Step 4: Managing the Service ==
<syntaxhighlight lang="text">
You can now manage the VoIPmonitor sensor using the standard systemctl commands.
# Before:
ARGS="-v 1 --config-file /etc/voipmonitor.conf"


;To start the service:
# After:
ARGS="--config-file /etc/voipmonitor.conf"
</syntaxhighlight>


<pre>sudo systemctl start voipmonitor</pre>
Then: <code>systemctl daemon-reload && systemctl restart voipmonitor</code>


== Troubleshooting ==


;To stop the service:
=== Unit File Syntax Errors ===


<pre>sudo systemctl stop voipmonitor</pre>
'''Symptom:''' "Assignment outside of section" or "control process exited with error code"


'''Fix:''' Check unit file for:
* Missing section headers (<code>[Unit]</code>, <code>[Service]</code>, <code>[Install]</code>)
* Typos in directive names
* Missing <code>=</code> signs


;To restart the service after a configuration change:
'''Emergency bypass:'''
 
<syntaxhighlight lang="bash">
<pre>sudo systemctl restart voipmonitor</pre>
killall -9 voipmonitor
 
/etc/init.d/voipmonitor start
 
# Fix unit file, then:
;To check the current status and view recent logs:
systemctl daemon-reload && systemctl start voipmonitor
 
</syntaxhighlight>
<pre>sudo systemctl status voipmonitor</pre>
 
 
;To disable the service from starting on boot:
 
<pre>sudo systemctl disable voipmonitor</pre>
 
 
== Troubleshooting: Systemd Unit File Errors ==
 
If you encounter systemd errors when trying to start the voipmonitor service, such as:
 
<pre>Error: Assignment outside of section. Ignoring.
Job for voipmonitor.service failed because the control process exited with error code.
</pre>
 
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:
 
<pre>
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>
# 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)
=== Multiple Instances Running (Duplicate Packets, Corrupted RRD) ===
/etc/init.d/voipmonitor start
</pre>


=== Fixing the Systemd Unit File ===
'''Symptom:''' Duplicate SIP packets in GUI, broken RRD graphs, multiple voipmonitor processes


Once the service is running via the init.d script, permanently fix the systemd unit file:
'''Cause:''' Both systemd unit and init.d wrapper trying to start VoIPmonitor


<pre>
'''Fix:'''
# 1. Check the unit file for syntax errors
systemctl status voipmonitor.service


# 2. Review the unit file contents
<syntaxhighlight lang="bash">
cat /etc/systemd/system/voipmonitor.service
# 1. Kill all instances
sudo killall -9 voipmonitor


# 3. Common errors include:
# 2. Disable init.d wrapper (keeps script but prevents auto-start)
#    - Missing [Unit], [Service], or [Install] section headers
sudo chmod -x /etc/init.d/voipmonitor
#    - 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
# 3. Delete corrupted RRD files
sudo systemctl daemon-reload
sudo rm -f /var/spool/voipmonitor/rrd/*


# 5. Now you can use systemctl again
# 4. Start via systemd
sudo systemctl enable voipmonitor
sudo systemctl start voipmonitor
sudo systemctl start voipmonitor
</pre>


=== Using the Legacy Init.d Service Configuration ===
# 5. Verify single instance
ps aux | grep "[v]oipmonitor"
</syntaxhighlight>


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:
{{Note|1=The <code>chmod -x</code> disables the SysV compatibility service that systemd auto-generates from init.d scripts.}}


<pre>
=== Connection Failures (Service Running but Not Connecting) ===
[Unit]
Description=VoIPmonitor sniffer
After=syslog.target
After=network.target
After=mysql.service


[Service]
If <code>systemctl status voipmonitor</code> shows "active (running)" but logs show connection errors, the problem is not systemd-related. See [[Sniffer_distributed_architecture#Troubleshooting|Distributed Architecture Troubleshooting]].
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]
== See Also ==
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.
* [[Sniffer_configuration]] - Full configuration reference
* [[Sniffer_installation]] - Installation guide
* [[Multiple_sniffer_instancies]] - Running multiple sensors on one host


== 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. 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?
'''Summary:''' Guide for managing VoIPmonitor sensor with systemd. Create unit file at <code>/etc/systemd/system/voipmonitor.service</code> with <code>Type=forking</code> and <code>RemainAfterExit=yes</code>. Key dependencies: add <code>After=mysql.service</code> for local DB only, add <code>After=ntservice.service</code> with <code>Requires=ntservice.service</code> for Napatech cards. Always use <code>systemctl</code> commands (not legacy <code>service</code>). For watchdog integration, set <code>watchdog_run_command = systemctl restart voipmonitor</code> to prevent systemd from showing failed status after watchdog restarts. For multiple instance conflicts (duplicate packets, corrupted RRD), run <code>chmod -x /etc/init.d/voipmonitor</code> to disable the init.d wrapper, delete RRD files, and restart via systemd. For verbose log spam (every 10 seconds), either redirect via rsyslog or remove <code>-v 1</code> from the init.d ARGS line.


What is the correct systemd unit file for VoIPmonitor?
'''Keywords:''' systemd, systemctl, voipmonitor.service, unit file, Type=forking, RemainAfterExit, After=mysql.service, Napatech, ntservice, daemon-reload, watchdog, watchdog_run_command, multiple instances, duplicate packets, corrupted RRD, chmod -x, verbose output, syslog spam, -v 1, rsyslog


How do I make the VoIPmonitor sensor start automatically on boot?
'''Key Questions:'''
 
* What is the recommended systemd unit file for VoIPmonitor?
Why shouldn't I use the service voipmonitor start command?
* How do I configure systemd dependencies for MySQL and Napatech?
 
* How do I make VoIPmonitor start automatically on boot?
How can I make the VoIPmonitor service wait for the MySQL database to be ready before starting?
* Why does systemd show service as failed after watchdog restart?
 
* How do I fix multiple voipmonitor processes running (duplicate packets, corrupted RRD)?
What is the difference between an init.d script and a systemd service file?
* How do I stop init.d and systemd from conflicting?
 
* How do I disable or redirect the verbose statistics output to syslog?
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

Latest revision as of 16:48, 8 January 2026


This guide covers managing the VoIPmonitor sensor service using systemd on modern Linux distributions.

⚠️ Warning: Always use systemctl commands. Do not use the legacy service command as systemd may lose track of the process state.

Unit File Configuration

Create /etc/systemd/system/voipmonitor.service:

[Unit]
Description=VoIPmonitor sniffer
After=syslog.target network.target
# Add mysql.service only if DB is local (see Dependencies below)

[Service]
Type=forking
RemainAfterExit=yes
TimeoutSec=5min
KillMode=process
GuessMainPID=no
IgnoreSIGPIPE=no
SuccessExitStatus=5 6
ExecStart=/etc/init.d/voipmonitor start
ExecStop=/etc/init.d/voipmonitor stop
PrivateTmp=false

[Install]
WantedBy=multi-user.target

Dependencies

Scenario Add to [Unit] section
Local MySQL/MariaDB After=mysql.service
Napatech SmartNIC After=ntservice.service
Requires=ntservice.service
Wants=network-pre.target
Before=network-pre.target

Basic Commands

# After any unit file changes
systemctl daemon-reload

# Enable auto-start on boot
systemctl enable voipmonitor

# Start/Stop/Restart
systemctl start voipmonitor
systemctl stop voipmonitor
systemctl restart voipmonitor

# Check status
systemctl status voipmonitor

Watchdog Integration

When using the internal watchdog with systemd, configure it to restart via systemctl. Otherwise, systemd will incorrectly report the service as "failed" after a watchdog-triggered restart.

Add to /etc/voipmonitor.conf:

watchdog = yes
watchdog_run_command = systemctl restart voipmonitor

Controlling Verbose Output

By default, VoIPmonitor outputs statistics to syslog every 10 seconds (controlled by -v 1 in the init.d script).

Option 1: Redirect to Dedicated Log (Recommended)

Add to /etc/rsyslog.conf:

if $programname == 'voipmonitor' then /var/log/voipmonitor.log
& ~

Then: systemctl restart rsyslog

Option 2: Disable Statistics Entirely

⚠️ Warning: This removes valuable diagnostic metrics. Only use if necessary.

Edit /etc/init.d/voipmonitor, find the ARGS= line, and remove -v 1 (or v 1):

# Before:
ARGS="-v 1 --config-file /etc/voipmonitor.conf"

# After:
ARGS="--config-file /etc/voipmonitor.conf"

Then: systemctl daemon-reload && systemctl restart voipmonitor

Troubleshooting

Unit File Syntax Errors

Symptom: "Assignment outside of section" or "control process exited with error code"

Fix: Check unit file for:

  • Missing section headers ([Unit], [Service], [Install])
  • Typos in directive names
  • Missing = signs

Emergency bypass:

killall -9 voipmonitor
/etc/init.d/voipmonitor start
# Fix unit file, then:
systemctl daemon-reload && systemctl start voipmonitor

Multiple Instances Running (Duplicate Packets, Corrupted RRD)

Symptom: Duplicate SIP packets in GUI, broken RRD graphs, multiple voipmonitor processes

Cause: Both systemd unit and init.d wrapper trying to start VoIPmonitor

Fix:

# 1. Kill all instances
sudo killall -9 voipmonitor

# 2. Disable init.d wrapper (keeps script but prevents auto-start)
sudo chmod -x /etc/init.d/voipmonitor

# 3. Delete corrupted RRD files
sudo rm -f /var/spool/voipmonitor/rrd/*

# 4. Start via systemd
sudo systemctl enable voipmonitor
sudo systemctl start voipmonitor

# 5. Verify single instance
ps aux | grep "[v]oipmonitor"

ℹ️ Note: The chmod -x disables the SysV compatibility service that systemd auto-generates from init.d scripts.

Connection Failures (Service Running but Not Connecting)

If systemctl status voipmonitor shows "active (running)" but logs show connection errors, the problem is not systemd-related. See Distributed Architecture Troubleshooting.

See Also

AI Summary for RAG

Summary: Guide for managing VoIPmonitor sensor with systemd. Create unit file at /etc/systemd/system/voipmonitor.service with Type=forking and RemainAfterExit=yes. Key dependencies: add After=mysql.service for local DB only, add After=ntservice.service with Requires=ntservice.service for Napatech cards. Always use systemctl commands (not legacy service). For watchdog integration, set watchdog_run_command = systemctl restart voipmonitor to prevent systemd from showing failed status after watchdog restarts. For multiple instance conflicts (duplicate packets, corrupted RRD), run chmod -x /etc/init.d/voipmonitor to disable the init.d wrapper, delete RRD files, and restart via systemd. For verbose log spam (every 10 seconds), either redirect via rsyslog or remove -v 1 from the init.d ARGS line.

Keywords: systemd, systemctl, voipmonitor.service, unit file, Type=forking, RemainAfterExit, After=mysql.service, Napatech, ntservice, daemon-reload, watchdog, watchdog_run_command, multiple instances, duplicate packets, corrupted RRD, chmod -x, verbose output, syslog spam, -v 1, rsyslog

Key Questions:

  • What is the recommended systemd unit file for VoIPmonitor?
  • How do I configure systemd dependencies for MySQL and Napatech?
  • How do I make VoIPmonitor start automatically on boot?
  • Why does systemd show service as failed after watchdog restart?
  • How do I fix multiple voipmonitor processes running (duplicate packets, corrupted RRD)?
  • How do I stop init.d and systemd from conflicting?
  • How do I disable or redirect the verbose statistics output to syslog?