Skip to content
Snippets Groups Projects
Commit 8adbffaa authored by Iustin Pop's avatar Iustin Pop
Browse files

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
parent 44bf25ff
No related branches found
No related tags found
No related merge requests found
...@@ -648,6 +648,30 @@ def ParseOptions(): ...@@ -648,6 +648,30 @@ def ParseOptions():
return options, args 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(): def main():
"""Main function for the node daemon. """Main function for the node daemon.
...@@ -668,20 +692,7 @@ def main(): ...@@ -668,20 +692,7 @@ def main():
print "Cluster configuration incomplete: '%s'" % str(err) print "Cluster configuration incomplete: '%s'" % str(err)
sys.exit(5) sys.exit(5)
# create the various SUB_RUN_DIRS, if not existing, so that we handle the EnsureRuntimeEnvironment()
# 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)
# become a daemon # become a daemon
if options.fork: if options.fork:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment