snmptrapd service cannot be enabled on Ubuntu 22.04

Bug #1989014 reported by Ludmil Miltchev
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
net-snmp (Ubuntu)
Expired
Undecided
Unassigned

Bug Description

After installing the snmptrapd package by running:

apt -y install snmptrapd

you can start snmptrapd successfully:

systemctl start snmptrapd

however, you won't be able to enable the service. When you try to do so, you get the error below:

# systemctl enable snmptrapd
Synchronizing state of snmptrapd.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable snmptrapd
The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
Alias= settings in the [Install] section, and DefaultInstance= for template
units). This means they are not meant to be enabled using systemctl.

Possible reasons for having this kind of units are:
• A unit may be statically enabled by being symlinked from another unit's
  .wants/ or .requires/ directory.
• A unit's purpose may be to act as a helper for some other unit which has
  a requirement dependency on it.
• A unit may be started when needed via activation (socket, path, timer,
  D-Bus, udev, scripted systemctl call, ...).
• In case of template units, the unit is meant to be enabled with some
  instance name specified.

I believe that this is caused by the missing "[Service]" section in the "/usr/lib/systemd/system/snmptrapd.service" file.

Example:

# cat /usr/lib/systemd/system/snmptrapd.service
[Unit]
Description=Simple Network Management Protocol (SNMP) Trap Daemon.

[Service]
Type=notify
User=Debian-snmp
ExecStart=/usr/sbin/snmptrapd -LOw -f udp:162 udp6:162
ExecReload=/bin/kill -HUP $MAINPID

[Unit]
Description=Simple Network Management Protocol (SNMP) Trap Daemon.

[Service]
Type=notify
User=Debian-snmp
ExecStart=/usr/sbin/snmptrapd -LOw -f udp:162 udp6:162
ExecReload=/bin/kill -HUP $MAINPID

This should've been:

[Unit]
Description=Simple Network Management Protocol (SNMP) Trap Daemon.

[Service]
Type=notify
User=Debian-snmp
ExecStart=/usr/sbin/snmptrapd -LOw -f udp:162 udp6:162
ExecReload=/bin/kill -HUP $MAINPID

[Unit]
Description=Simple Network Management Protocol (SNMP) Trap Daemon.

[Service]
Type=notify
User=Debian-snmp
ExecStart=/usr/sbin/snmptrapd -LOw -f udp:162 udp6:162
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

More info:

# cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.1 LTS"
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

# uname -a
Linux test-xi-ubuntu-22 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

# dpkg -l | grep snmptrapd
ii libnetsnmptrapd40:amd64 5.9.1+dfsg-1ubuntu2.2 amd64 SNMP (Simple Network Management Protocol) trap library
ii snmptrapd 5.9.1+dfsg-1ubuntu2.2 amd64 Net-SNMP notification receiver

Revision history for this message
Paride Legovini (paride) wrote :

Hello Ludmil and thanks for this bug report. snmptrapd is socket activated, see the
snmptrapd.socket systemd socket unit. I did a very quick test and it seems to be working:

root@paride-j:~# pgrep snmptrapd
root@paride-j:~# echo foo | nc -u -N -q0 127.0.0.1 162
root@paride-j:~# pgrep snmptrapd
1885

If I misinterpreted your bug report please let us know more context on what you're trying to achieve, otherwise if you agree the service activation is working as intended please change the status of this bug to Invalid. I'm marking it as Incomplete for now. Thanks!

Changed in net-snmp (Ubuntu):
status: New → Incomplete
Revision history for this message
Ludmil Miltchev (ludmilmm) wrote :

Thank you for your quick reply @Paride Legovini!

I didn't realize that snmptrapd is socket activated now in Ubuntu 22.04. I have a Jenkins job that is run on a schedule to see if certain services are enabled. This is an example (part of the Ansible playbook that I am using):

- name: Check enabled services on Ubuntu and Debian
  command: systemctl is-enabled {{ item }}
  with_items:
   - apache2
   - mysql
   - cron
   - snmptt
   - snmptrapd
  when: ansible_os_family == "Debian"

It used to work with the older versions of Ubuntu, but it fails now in Ubuntu 22.04.

Thanks!

Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for net-snmp (Ubuntu) because there has been no activity for 60 days.]

Changed in net-snmp (Ubuntu):
status: Incomplete → Expired
Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

Hi Ludmil,

Just a quick follow up to this bug: I believe you need to adjust your playbook to check if snmptrapd.socket is active, instead of just snmptrapd.

I'm not reopening this bug because I agree with Paride here and it seems more like a local configuration issue than a bug in the package.

Thanks!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.