saltstack / saltstack/salt

[BUG] systemd templated services not handled correctly

Open
#60,036 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug severity-medium
Dominant language
Python
Stars
15.7k
Forks
5.6k
Avg merge
2d 44m
Merged PRs (30d)
80

Description

Description
Under systemd you can have multiple services based on the same unit file. These will be listed containing an @ in the service name. Some Salt functions, e.g. systemd_service.get_all do not handle this correctly.

Setup
Be logged in to any systemd system.

Steps to Reproduce the behavior

# salt-call --local service.get_all | grep '@'
    - autovt@
    - blockdev@.target
    - container-getty@
    - e2scrub@
    - e2scrub_fail@
    - getty@
    - lvm2-pvscan@
    - modprobe@
    - postgresql@
    - salt-proxy@
    - serial-getty@
    - ssh@
    - systemd-backlight@
    - systemd-fsck@
    - systemd-hibernate-resume@
    - systemd-journald-varlink@.socket
    - systemd-journald@
    - systemd-journald@.socket
    - user-runtime-dir@
    - user@
# systemctl list-units --plain --all --type=service '*@*'
  UNIT                                        LOAD   ACTIVE   SUB     DESCRIPTION
  getty@tty1.service                          loaded active   running Getty on tty1
  lvm2-pvscan@252:1.service                   loaded active   exited  LVM event activation on device 252:1
  modprobe@drm.service                        loaded inactive dead    Load Kernel Module drm
  postgresql@12-main.service                  loaded active   running PostgreSQL Cluster 12-main
  systemd-fsck@dev-mapper-vg1\x2ddata.service loaded active   exited  File System Check on /dev/mapper/vg1-data
  systemd-fsck@dev-mapper-vg1\x2dvar.service  loaded active   exited  File System Check on /dev/mapper/vg1-var
  user-runtime-dir@112.service                loaded active   exited  User Runtime Directory /run/user/112
  user-runtime-dir@216216.service             loaded active   exited  User Runtime Directory /run/user/216216
  user@112.service                            loaded active   running User Manager for UID 112
  user@216216.service                         loaded active   running User Manager for UID 216216

Expected behavior
Should include the full names of each service, including multiple for the same template.

Versions Report

salt --versions-report
Salt Version:
          Salt: 3003

Dependency Versions:
          cffi: 1.14.5
      cherrypy: Not Installed
      dateutil: 2.7.3
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.10.1
       libgit2: 1.1.0
      M2Crypto: 0.31.0
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.20
      pycrypto: Not Installed
  pycryptodome: 3.6.1
        pygit2: 1.5.0
        Python: 3.8.5 (default, Jan 27 2021, 15:41:15)
  python-gnupg: 0.4.5
        PyYAML: 5.3.1
         PyZMQ: 18.1.1
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.2

System Versions:
          dist: ubuntu 20.04 focal
        locale: utf-8
       machine: x86_64
       release: 5.4.0-71-generic
        system: Linux
       version: Ubuntu 20.04 focal

Additional context
systemctl list-units can't show services from unloaded units, e.g. salt-proxy. In an attempt to represent "disabled" services, salt is probably conflating units with unit files.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the systemd_service.get_all and service.get_all entry points, then reproduce the behavior using salt-call --local service.get_all and the listed systemctl command on a systemd host. Done means the service listing preserves full templated service names, includes multiple instances of the same template, and does not conflate unit files with loaded units.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.