#1071594 debhelper: fails to start openssh-server after creating host keys due to systemd 255 change

#1071594#5
Date:
2024-05-21 20:02:17 UTC
From:
To:
Hi,

I maintain the Debian Vagrant boxes. Recently, booting the 'testing'
image started to fail randomly.
The Debian Vagrant images ship without SSH host keys. A systemd service
is responsible for triggering a 'dpkg-reconfigure openssh-server' that
will generate the ssh keys and then start ssh.

Until systemd v254.5-1, that worked fine:
ssh.service was started but fails to start;
we get the 'ssh.service: Start request repeated too quickly.' error;
dpkg-reconfigure openssh-server creates the key and starts ssh.service
successfully.

With v255.2-1, that no longer works.
If ssh.service reached the 'Start request repeated too quickly.' state,
dpkg-reconfigure openssh-server is no longer able to start it.

The following code is in charge of starting ssh.service:


# Automatically added by dh_installsystemd/13.15.3
if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then
        if [ -d /run/systemd/system ]; then
                systemctl --system daemon-reload >/dev/null || true
                if [ -n "$2" ]; then
                        _dh_action=restart
                else
                        _dh_action=start
                fi
                deb-systemd-invoke $_dh_action 'ssh.service' >/dev/null || true
        fi
fi
# End automatically added section


A MWE to reproduce is:

systemctl stop ssh
rm /etc/ssh/ssh_host_*
for i in $(seq 1 10); do systemctl start ssh ; done
systemctl status ssh
dpkg-reconfigure openssh-server
systemctl status ssh


I tried to identify when and why it was changed in systemd, but failed.
It could be argued that this is a regression in systemd.

Lucas

#1071594#10
Date:
2024-05-23 09:40:37 UTC
From:
To:
Hi Michael and Luca

I suspect you are better suited to debug this one. Let me know if I
should change anything in the maintscript generated.

Lucas Nussbaum:

#1071594#15
Date:
2024-05-23 19:02:07 UTC
From:
To:
We have dependencies between units, we have ExecStartPre= and friends,
there's many good ways to handle requirements before a service can be
started. Hooking into dpkg reconfigure doesn't seem like a good idea,
so I recommend to just fix that.

#1071594#20
Date:
2024-05-24 09:00:33 UTC
From:
To:
I agree that I should fix the way the SSH keys are generated in the
vagrant image.

However, my point is that there's a change between systemd 254 and
systemd 255 that causes the debhelper-generated snippet to fail to
restart services during dpkg-reconfigure if the service was previously
in the 'Start request repeated too quickly.' state.

I hit this in the context of the Vagrant image, but it could hit users
in other contexts as well.

Lucas