Module: check_mk
Branch: master
Commit: 73b5e8afa1c4029a33552306a166c66986bb6dd4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=73b5e8afa1c402…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Feb 23 21:16:25 2015 +0100
Fixed snapshot creation with CentOS <2.5
---
modules/automation.py | 55 +++++++++++++++++++++++++++++++------------------
web/htdocs/wato.py | 2 --
2 files changed, 35 insertions(+), 22 deletions(-)
diff --git a/modules/automation.py b/modules/automation.py
index 96217f2..6d20c45 100644
--- a/modules/automation.py
+++ b/modules/automation.py
@@ -867,23 +867,37 @@ def automation_create_snapshot(args):
statusinfo[name] = "TODO:0"
update_status_file()
- if not data.get("wait"):
- try:
- pid = os.fork()
- if pid > 0:
- # Exit parent process
- return
- # Decouple from parent environment
- os.chdir("/")
- os.umask(0)
- os.setsid()
- for fd in range(0, 256):
- try:
- os.close(fd)
- except OSError:
- pass
- except OSError, e:
- raise MKAutomationError(str(e))
+ # Now fork into our own process to have an asynchronous backup creation
+ try:
+ pid = os.fork()
+ if pid > 0:
+ # Exit parent process
+ return
+ # Decouple from parent environment
+ os.chdir("/")
+ os.umask(0)
+ os.setsid()
+
+ # Close all fd except stdin,out,err
+ for fd in range(3, 256):
+ try:
+ os.close(fd)
+ except OSError:
+ pass
+
+ sys.stdout.flush()
+ sys.stderr.flush()
+
+ si = os.open("/dev/null", os.O_RDONLY)
+ so = os.open("/dev/null", os.O_WRONLY)
+ os.dup2(si, 0)
+ os.dup2(so, 1)
+ os.dup2(so, 2)
+ os.close(si)
+ os.close(so)
+
+ except OSError, e:
+ raise MKAutomationError(str(e))
# Save pid of working process.
file(filename_pid, "w").write("%d" % os.getpid())
@@ -987,13 +1001,14 @@ def automation_create_snapshot(args):
command = "tar czf %s --ignore-failed-read --force-local %s -C %s
%s" % \
(path_subtar, exclude_options, prefix, "
".join(paths))
- proc = subprocess.Popen(command, shell=True, stdin = None,
- stdout = subprocess.PIPE, stderr = subprocess.PIPE,
cwd = prefix)
+ proc = subprocess.Popen(command, shell=True, stdin=None, close_fds=True,
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cwd=prefix)
stdout, stderr = proc.communicate()
exit_code = proc.wait()
# Allow exit codes 0 and 1 (files changed during backup)
if exit_code not in [0, 1]:
- raise MKAutomationError("Error while creating backup of %s (Exit
Code %d) - %s.\n%s" % (current_domain, exit_code, stderr, command))
+ raise MKAutomationError("Error while creating backup of %s (Exit
Code %d) - %s.\n%s" %
+ (current_domain, exit_code, stderr, command))
subtar_size = os.stat(path_subtar).st_size
subtar_hash = sha256(file(path_subtar).read()).hexdigest()
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index afbc4d5..bb84f59 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -6819,7 +6819,6 @@ def mode_snapshot(phase):
snapshot_data["type"] = "manual"
snapshot_data["snapshot_name"] = snapshot_name
snapshot_data["domains"] = store_domains
- snapshot_data["wait"] = False
return None, _("Created snapshot <tt>%s</tt>.") %
create_snapshot(snapshot_data)
@@ -7036,7 +7035,6 @@ def create_snapshot(data = {}):
snapshot_data["type"] = data.get("type",
"automatic")
snapshot_data["snapshot_name"] = snapshot_name
snapshot_data["domains"] =
remove_functions(data.get("domains",
get_backup_domains(["default"])))
- snapshot_data["wait"] = data.get("wait", False)
check_mk_local_automation("create-snapshot", [], snapshot_data)