From 8adbffaad96da0cd3d644e5fbbce032727be968b Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 11 Nov 2008 10:58:39 +0000 Subject: [PATCH] Abstract runtime creation of dirs into a function Currently the dir creation in ganeti-noded is in the main function. This is not nice: we move it into a separate function and also add creation of the OS_LOG_DIR (with different permissions, but in the same way). This will permit cleanup of the creation of the OS_LOG_DIR from the backend module (it's done multiple places currently). Reviewed-by: imsnah --- daemons/ganeti-noded | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded index 958a031d1..45c12655c 100755 --- a/daemons/ganeti-noded +++ b/daemons/ganeti-noded @@ -648,6 +648,30 @@ def ParseOptions(): return options, args +def EnsureRuntimeEnvironment(): + """Ensure our run-time environment is complete. + + Currently this creates directories which could be missing, either + due to directories being on a tmpfs mount, or due to incomplete + packaging. + + """ + dirs = [(val, 0755) for val in constants.SUB_RUN_DIRS] + dirs.append((constants.LOG_OS_DIR, 0750)) + for dir_name, dir_mode in dirs: + if not os.path.exists(dir_name): + try: + os.mkdir(dir_name, dir_mode) + except EnvironmentError, err: + if err.errno != errno.EEXIST: + print ("Node setup wrong, cannot create directory '%s': %s" % + (dir_name, err)) + sys.exit(5) + if not os.path.isdir(dir_name): + print ("Node setup wrong, '%s' is not a directory" % dir_name) + sys.exit(5) + + def main(): """Main function for the node daemon. @@ -668,20 +692,7 @@ def main(): print "Cluster configuration incomplete: '%s'" % str(err) sys.exit(5) - # create the various SUB_RUN_DIRS, if not existing, so that we handle the - # situation where RUN_DIR is tmpfs - for dir_name in constants.SUB_RUN_DIRS: - if not os.path.exists(dir_name): - try: - os.mkdir(dir_name, 0755) - except EnvironmentError, err: - if err.errno != errno.EEXIST: - print ("Node setup wrong, cannot create directory %s: %s" % - (dir_name, err)) - sys.exit(5) - if not os.path.isdir(dir_name): - print ("Node setup wrong, %s is not a directory" % dir_name) - sys.exit(5) + EnsureRuntimeEnvironment() # become a daemon if options.fork: -- GitLab