saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.2k stars 5.48k forks source link

[BUG] Salt minion 3006.9 does not respect /usr/sbin/policy-rc.d on Debian derivatives #67052

Open lubyou opened 1 week ago

lubyou commented 1 week ago

Description

The postinst in 3006.9 directly uses systemctl to restart a minion after an upgrade instead of using deb-systemd-invoke:

https://github.com/saltstack/salt/blob/b40833ed15b2c8b1b169560b694e02489de84782/pkg/debian/salt-minion.postinst#L25

/usr/sbin/policy-rc.d gets ignored as result.

The following patch seems to restore the previous behaviour:

--- 3006.9/postinst 2024-07-29 07:42:36.000000000 +0000
+++ 3006.9-fix-postinst/postinst    2024-11-07 22:17:46.816048641 +0000
@@ -16,13 +16,14 @@
       fi
       chown -R $RET:$RET /etc/salt/pki/minion /etc/salt/minion.d /var/log/salt/minion /var/cache/salt/minion /var/run/salt/minion
     fi
-    if command -v systemctl; then
+    command -v systemctl >/dev/null
+    if [ $? -eq 0 ]; then
         db_get salt-minion/active
         RESLT=$(echo "$RET" | cut -d ' ' -f 1)
         if [ "$RESLT" != 10 ]; then
             systemctl daemon-reload
             if [ "$RESLT" = "active" ]; then
-                systemctl restart salt-minion
+                deb-systemd-invoke restart salt-minion
             fi
             db_get salt-minion/enabled
             RESLT=$(echo "$RET" | cut -d ' ' -f 1)
@@ -33,7 +34,7 @@
             fi
         else
             systemctl daemon-reload
-            systemctl restart salt-minion
+            deb-systemd-invoke restart salt-minion
             systemctl enable salt-minion
         fi
     fi

Setup (Please provide relevant configs and/or SLS files (be sure to remove sensitive info. There is no general set-up of Salt.)

Please be as specific as possible and give set-up details.

Steps to Reproduce the behavior

# define /usr/sbin/policy-rc.d
printf '#!/bin/sh\nexit 101' | sudo tee /usr/sbin/policy-rc.d && sudo chmod +x /usr/sbin/policy-rc.d
# 3006.7 to 3006.8 upgrade, `/usr/sbin/policy-rc.d` is respected
DEBIAN_FRONTEND=noninteracive sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install salt-common=3006.8 salt-minion=3006.8
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  ifupdown
The following packages will be upgraded:
  salt-common salt-minion
2 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
Need to get 0 B/34.3 MB of archives.
After this operation, 2,846 kB of additional disk space will be used.
(Reading database ... 116481 files and directories currently installed.)
Preparing to unpack .../salt-common_3006.8_amd64.deb ...
usermod: no changes
Unpacking salt-common (3006.8) over (3006.7) ...
Preparing to unpack .../salt-minion_3006.8_amd64.deb ...
Unpacking salt-minion (3006.8) over (3006.7) ...
Setting up salt-common (3006.8) ...
Setting up salt-minion (3006.8) ...

Configuration file '/etc/salt/minion'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
 ==> Keeping old config file as default.
/usr/sbin/policy-rc.d returned 101, not running 'restart salt-minion.service'
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.8) ...
# upgrade from 3006.8 to 3006.9, /usr/sbin/policy-rc.d is not considered
DEBIAN_FRONTEND=noninteracive sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install salt-common=3006.9 salt-minion=3006.9
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  ifupdown
The following packages will be upgraded:
  salt-common salt-minion
2 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
Need to get 0 B/34.3 MB of archives.
After this operation, 221 kB of additional disk space will be used.
Preconfiguring packages ...
(Reading database ... 116522 files and directories currently installed.)
Preparing to unpack .../salt-common_3006.9_amd64.deb ...
usermod: no changes
Unpacking salt-common (3006.9) over (3006.8) ...
Preparing to unpack .../salt-minion_3006.9_amd64.deb ...
/usr/bin/systemctl
Unpacking salt-minion (3006.9) over (3006.8) ...
Setting up salt-common (3006.9) ...
Setting up salt-minion (3006.9) ...
/usr/bin/systemctl
Synchronizing state of salt-minion.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable salt-minion
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.8) ...
Scanning processes...
Scanning candidates...
Scanning linux images...

Expected behavior /usr/sbin/policy-rc.d should be considered.

Versions Report

```yaml Salt Version: Salt: 3006.9 Python Version: Python: 3.10.14 (main, Jun 26 2024, 11:44:37) [GCC 11.2.0] Dependency Versions: cffi: 1.14.6 cherrypy: 18.6.1 cryptography: 42.0.5 dateutil: 2.8.1 docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed Jinja2: 3.1.4 libgit2: Not Installed looseversion: 1.0.2 M2Crypto: Not Installed Mako: Not Installed msgpack: 1.0.2 msgpack-pure: Not Installed mysql-python: Not Installed packaging: 22.0 pycparser: 2.21 pycrypto: Not Installed pycryptodome: 3.19.1 pygit2: Not Installed python-gnupg: 0.4.8 PyYAML: 6.0.1 PyZMQ: 23.2.0 relenv: 0.17.0 smmap: Not Installed timelib: 0.2.4 Tornado: 4.5.3 ZMQ: 4.3.4 System Versions: dist: ubuntu 22.04.5 jammy locale: utf-8 machine: x86_64 release: 5.15.0-86-generic system: Linux version: Ubuntu 22.04.5 jammy ```