From 0214b0c0859cef8c17216d912d4e2b1271b812d2 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 19 Mar 2008 10:17:36 +0000
Subject: [PATCH] Make ganeti-noded create BDEV_CACHE_DIR automatically

Currently in order to deal with tmpfs /var/run, we create the
BDEV_CACHE_DIR in the init script. However, that does not cover all the
cases, and it's not a proper place to deal with it: for example, dealing
with not initialized clusters and the master node is more complicated.

Therefore, this patch does:
  - make ganeti-noded create the directory automatically
  - make ganeti-noded error out if it can't create it or it's already
    there but not a directory
  - remove the creation from the init.d script

Reviewed-by: ultrotter
---
 daemons/ganeti-noded         | 16 ++++++++++++++++
 doc/examples/ganeti.initd.in |  4 ----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded
index 620f8809b..c6ab69c04 100755
--- a/daemons/ganeti-noded
+++ b/daemons/ganeti-noded
@@ -30,6 +30,7 @@ import resource
 import traceback
 import BaseHTTPServer
 import simplejson
+import errno
 
 from optparse import OptionParser
 
@@ -536,6 +537,21 @@ def main():
     print "Cluster configuration incomplete: '%s'" % str(err)
     sys.exit(5)
 
+  # create /var/run/ganeti if not existing, in order to take care of
+  # tmpfs /var/run
+  if not os.path.exists(constants.BDEV_CACHE_DIR):
+    try:
+      os.mkdir(constants.BDEV_CACHE_DIR, 0755)
+    except EnvironmentError, err:
+      if err.errno != errno.EEXIST:
+        print ("Node setup wrong, cannot create directory %s: %s" %
+               (constants.BDEV_CACHE_DIR, err))
+        sys.exit(5)
+  if not os.path.isdir(constants.BDEV_CACHE_DIR):
+    print ("Node setup wrong, %s is not a directory" %
+           constants.BDEV_CACHE_DIR)
+    sys.exit(5)
+
   # become a daemon
   if options.fork:
     createDaemon()
diff --git a/doc/examples/ganeti.initd.in b/doc/examples/ganeti.initd.in
index 99079fc48..2d5219f74 100644
--- a/doc/examples/ganeti.initd.in
+++ b/doc/examples/ganeti.initd.in
@@ -17,7 +17,6 @@ NAME=ganeti-noded
 NODED=@PREFIX@/sbin/ganeti-noded
 MASTER=@PREFIX@/sbin/ganeti-master
 SCRIPTNAME=@SYSCONFDIR@/init.d/ganeti
-RUNDIR="@LOCALSTATEDIR@/run/ganeti"
 
 test -f $NODED || exit 0
 
@@ -56,7 +55,6 @@ case "$1" in
     start)
         log_daemon_msg "Starting $DESC" "$NAME"
         check_config
-        test -e "$RUNDIR" || mkdir -p "$RUNDIR"
         if start-stop-daemon --start --quiet --exec $NODED; then
             log_end_msg 0
         else
@@ -90,5 +88,3 @@ case "$1" in
 esac
 
 exit 0
-
-# vim: set sw=4 sts=4 et foldmethod=marker :
-- 
GitLab