Make ganeti-noded create BDEV_CACHE_DIR automatically
authorIustin Pop <iustin@google.com>
Wed, 19 Mar 2008 10:17:36 +0000 (10:17 +0000)
committerIustin Pop <iustin@google.com>
Wed, 19 Mar 2008 10:17:36 +0000 (10:17 +0000)
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
doc/examples/ganeti.initd.in

index 620f880..c6ab69c 100755 (executable)
@@ -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()
index 99079fc..2d5219f 100644 (file)
@@ -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 :