From 7e1fac2590e8ba134b4f6aa251ee8e8162ccf56a Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Thu, 5 Nov 2009 12:21:48 +0100
Subject: [PATCH] =?UTF-8?q?Use=20=E2=80=9Cdaemon-util=E2=80=9D=20to=20relo?=
 =?UTF-8?q?ad=20SSH=20keys?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 Makefile.am            | 2 +-
 daemons/daemon-util.in | 5 +++++
 lib/backend.py         | 5 ++++-
 lib/constants.py       | 1 -
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index f51024e1d..6edaff5b9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -408,7 +408,6 @@ lib/_autoconf.py: Makefile stamp-directories
 	  echo "VERSION_FULL = '$(VERSION_FULL)'"; \
 	  echo "LOCALSTATEDIR = '$(localstatedir)'"; \
 	  echo "SYSCONFDIR = '$(sysconfdir)'"; \
-	  echo "SSH_INITD_SCRIPT = '$(SSH_INITD_SCRIPT)'"; \
 	  echo "EXPORT_DIR = '$(EXPORT_DIR)'"; \
 	  echo "OS_SEARCH_PATH = [$(OS_SEARCH_PATH)]"; \
 	  echo "XEN_BOOTLOADER = '$(XEN_BOOTLOADER)'"; \
@@ -437,6 +436,7 @@ $(REPLACE_VARS_SED): Makefile
 	  echo 's#@CUSTOM_XEN_KERNEL@#$(XEN_KERNEL)#g'; \
 	  echo 's#@CUSTOM_XEN_INITRD@#$(XEN_INITRD)#g'; \
 	  echo 's#@RPL_FILE_STORAGE_DIR@#$(FILE_STORAGE_DIR)#g'; \
+	  echo 's#@RPL_SSH_INITD_SCRIPT@#$(SSH_INITD_SCRIPT)#g'; \
 	  echo 's#@PKGLIBDIR@#$(pkglibdir)#g'; \
 	} > $@
 
diff --git a/daemons/daemon-util.in b/daemons/daemon-util.in
index 12b4afbf8..ab58ac5d6 100755
--- a/daemons/daemon-util.in
+++ b/daemons/daemon-util.in
@@ -104,6 +104,11 @@ stop_master() {
   stop ganeti-masterd
 }
 
+# Reloads the SSH keys
+reload_ssh_keys() {
+  @RPL_SSH_INITD_SCRIPT@ restart
+}
+
 if [[ "$#" -lt 1 ]]; then
   echo "Usage: $0 <action>" >&2
   exit 1
diff --git a/lib/backend.py b/lib/backend.py
index 2961371fb..0a50100b3 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -355,7 +355,10 @@ def AddNode(dsa, dsapub, rsa, rsapub, sshkey, sshpub):
 
   utils.AddAuthorizedKey(auth_keys, sshpub)
 
-  utils.RunCmd([constants.SSH_INITD_SCRIPT, "restart"])
+  result = utils.RunCmd([constants.DAEMON_UTIL, "reload-ssh-keys"])
+  if result.failed:
+    _Fail("Unable to reload SSH keys (command %r, exit code %s, output %r)",
+          result.cmd, result.exit_code, result.output)
 
 
 def LeaveCluster(modify_ssh_setup):
diff --git a/lib/constants.py b/lib/constants.py
index 659e26a86..b3a20a9ab 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -338,7 +338,6 @@ OS_API_FILE = 'ganeti_api_version'
 OS_VARIANTS_FILE = 'variants.list'
 
 # ssh constants
-SSH_INITD_SCRIPT = _autoconf.SSH_INITD_SCRIPT
 SSH_CONFIG_DIR = "/etc/ssh/"
 SSH_HOST_DSA_PRIV = SSH_CONFIG_DIR + "ssh_host_dsa_key"
 SSH_HOST_DSA_PUB = SSH_HOST_DSA_PRIV + ".pub"
-- 
GitLab