public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] sshd-regen-keys: Improve service, make more robust
@ 2021-03-25 12:54 Jan Kiszka
  2021-03-25 14:30 ` Henning Schild
  2021-03-26  8:11 ` Henning Schild
  0 siblings, 2 replies; 10+ messages in thread
From: Jan Kiszka @ 2021-03-25 12:54 UTC (permalink / raw)
  To: isar-users; +Cc: Quirin Gylstorff, Henning Schild

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-03-30 10:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-25 12:54 [PATCH] sshd-regen-keys: Improve service, make more robust Jan Kiszka
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox