From: Jan Kiszka <jan.kiszka@siemens.com>
To: isar-users <isar-users@googlegroups.com>
Cc: Quirin Gylstorff <quirin.gylstorff@siemens.com>,
Henning Schild <henning.schild@siemens.com>
Subject: [PATCH] sshd-regen-keys: Improve service, make more robust
Date: Thu, 25 Mar 2021 13:54:02 +0100 [thread overview]
Message-ID: <29bfb292-fa50-e82f-d0aa-172a14f93515@siemens.com> (raw)
From: Jan Kiszka <jan.kiszka@siemens.com>
This improves a number of things:
- stop the service while regenerating keys, rather than disabling its
auto-start
- fix restart test condition
- also check that /tmp is writable (better safe than sorry)
- do not disabling the regen service if it was not successful
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
This obsoletes Quirin's patch "sshd-regen-keys: do not enable ssh server if previously disabled".
.../sshd-regen-keys/files/sshd-regen-keys.service | 2 +-
.../sshd-regen-keys/files/sshd-regen-keys.sh | 14 ++++++++------
...hd-regen-keys_0.3.bb => sshd-regen-keys_0.4.bb} | 0
3 files changed, 9 insertions(+), 7 deletions(-)
rename meta/recipes-support/sshd-regen-keys/{sshd-regen-keys_0.3.bb => sshd-regen-keys_0.4.bb} (100%)
diff --git a/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.service b/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.service
index f50d34c8..e7142e69 100644
--- a/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.service
+++ b/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.service
@@ -5,13 +5,13 @@ Conflicts=shutdown.target
After=systemd-remount-fs.service
Before=shutdown.target ssh.service
ConditionPathIsReadWrite=/etc
+ConditionPathIsReadWrite=/tmp
[Service]
Type=oneshot
RemainAfterExit=yes
Environment=DEBIAN_FRONTEND=noninteractive
ExecStart=/usr/sbin/sshd-regen-keys.sh
-ExecStartPost=-/bin/systemctl disable sshd-regen-keys.service
StandardOutput=syslog
StandardError=syslog
diff --git a/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh b/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh
index 910d879b..9b19f9d3 100644
--- a/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh
+++ b/meta/recipes-support/sshd-regen-keys/files/sshd-regen-keys.sh
@@ -1,9 +1,9 @@
#!/usr/bin/env sh
echo -n "SSH server is "
-if systemctl is-enabled ssh; then
- SSHD_ENABLED="true"
- systemctl disable --no-reload ssh
+if systemctl is-active ssh; then
+ SSHD_ACTIVE="true"
+ systemctl stop ssh
fi
echo "Removing keys ..."
@@ -12,9 +12,11 @@ rm -v /etc/ssh/ssh_host_*_key*
echo "Regenerating keys ..."
dpkg-reconfigure openssh-server
-if test -n $SSHD_ENABLED; then
- echo "Reenabling ssh server ..."
- systemctl enable --no-reload ssh
+if test -n "$SSHD_ACTIVE"; then
+ echo "Restarting ssh server ..."
+ systemctl start ssh
fi
+systemctl disable sshd-regen-keys.service
+
sync
diff --git a/meta/recipes-support/sshd-regen-keys/sshd-regen-keys_0.3.bb b/meta/recipes-support/sshd-regen-keys/sshd-regen-keys_0.4.bb
similarity index 100%
rename from meta/recipes-support/sshd-regen-keys/sshd-regen-keys_0.3.bb
rename to meta/recipes-support/sshd-regen-keys/sshd-regen-keys_0.4.bb
--
2.26.2
next reply other threads:[~2021-03-25 13:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-25 12:54 Jan Kiszka [this message]
2021-03-25 14:30 ` Henning Schild
2021-03-25 18:53 ` Jan Kiszka
2021-03-26 7:35 ` Henning Schild
2021-03-26 8:14 ` Henning Schild
2021-03-26 8:11 ` Henning Schild
2021-03-26 9:24 ` Henning Schild
2021-03-26 9:44 ` Harald Seiler
2021-03-30 9:21 ` Henning Schild
2021-03-30 10:15 ` Henning Schild
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=29bfb292-fa50-e82f-d0aa-172a14f93515@siemens.com \
--to=jan.kiszka@siemens.com \
--cc=henning.schild@siemens.com \
--cc=isar-users@googlegroups.com \
--cc=quirin.gylstorff@siemens.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox