saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.1k stars 5.47k forks source link

[BUG] systemd templated services not handled correctly #60036

Open OrangeDog opened 3 years ago

OrangeDog commented 3 years ago

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.

OrangeDog commented 3 years ago

Also note that salt is listing units that aren't services. I don't know whether that's intentional or another bug.

salt-call service.get_all | grep -E '\.(timer|target|socket|mount)' ``` - apt-daily-upgrade.timer - apt-daily.timer - basic.target - blockdev@.target - bluetooth.target - boot-complete.target - cryptsetup-pre.target - cryptsetup.target - ctrl-alt-del.target - dbus.socket - default.target - dev-hugepages.mount - dev-mqueue.mount - dm-event.socket - e2scrub_all.timer - emergency.target - exit.target - final.target - friendly-recovery.target - fstrim.timer - getty-pre.target - getty.target - graphical.target - halt.target - hibernate.target - hybrid-sleep.target - initrd-fs.target - initrd-root-device.target - initrd-root-fs.target - initrd-switch-root.target - initrd.target - kexec.target - local-fs-pre.target - local-fs.target - logrotate.timer - lvm2-lvmpolld.socket - man-db.timer - motd-news.timer - multi-user.target - network-online.target - network-pre.target - network.target - nfs-client.target - nss-lookup.target - nss-user-lookup.target - paths.target - poweroff.target - printer.target - proc-fs-nfsd.mount - proc-sys-fs-binfmt_misc.mount - reboot.target - remote-cryptsetup.target - remote-fs-pre.target - remote-fs.target - rescue-ssh.target - rescue.target - rpcbind.socket - rpcbind.target - run-rpc_pipefs.mount - runlevel0.target - runlevel1.target - runlevel2.target - runlevel3.target - runlevel4.target - runlevel5.target - runlevel6.target - shutdown.target - sigpwr.target - sleep.target - slices.target - smartcard.target - sockets.target - sound.target - ssh.socket - suspend-then-hibernate.target - suspend.target - swap.target - sys-fs-fuse-connections.mount - sys-kernel-config.mount - sys-kernel-debug.mount - sys-kernel-tracing.mount - sysinit.target - syslog.socket - system-update-pre.target - system-update.target - systemd-fsckd.socket - systemd-initctl.socket - systemd-journald-audit.socket - systemd-journald-dev-log.socket - systemd-journald-varlink@.socket - systemd-journald.socket - systemd-journald@.socket - systemd-networkd.socket - systemd-rfkill.socket - systemd-tmpfiles-clean.timer - systemd-udevd-control.socket - systemd-udevd-kernel.socket - time-set.target - time-sync.target - timers.target - umount.target - uuidd.socket ```

They can all be "started", "stopped" or "enabled" and some can be "reloaded", so there is some use to having them.

sagetherage commented 3 years ago

I apologize I missed this comment @OrangeDog I will get this in front of the Core team and follow up.

waynew commented 3 years ago

My thought is that we should be listing anything systemd does. (I.e. intentional, not a bug. Or at least it should be intentional)