cb8e9e
From 6220dbf7cf45946eb1474a2da5113c90244cebcc Mon Sep 17 00:00:00 2001
cb8e9e
From: Avra Sengupta <asengupt@redhat.com>
cb8e9e
Date: Tue, 9 Jun 2015 18:00:57 +0530
cb8e9e
Subject: [PATCH 47/57] snapshot/scheduler: Reload /etc/cron.d/glusterfs_snap_cron_tasks when shared storage is available
cb8e9e
cb8e9e
     Backport of http://review.gluster.org/#/c/11139/
cb8e9e
cb8e9e
If shared storage is not accessible, create a flag in /var/run/gluster/
cb8e9e
So that when /etc/cron.d/glusterfs_snap_cron_tasks is
cb8e9e
available again, the flag will tell us, to reload
cb8e9e
/etc/cron.d/glusterfs_snap_cron_tasks
cb8e9e
cb8e9e
Change-Id: I41b19f57ff0b8f7e0b820eaf592b0fdedb0a5d86
cb8e9e
BUG: 1223205
cb8e9e
Signed-off-by: Avra Sengupta <asengupt@redhat.com>
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/50514
cb8e9e
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
cb8e9e
Tested-by: Rajesh Joseph <rjoseph@redhat.com>
cb8e9e
---
cb8e9e
 extras/snap_scheduler/gcron.py |   33 +++++++++++++++++++++++++++++++++
cb8e9e
 1 files changed, 33 insertions(+), 0 deletions(-)
cb8e9e
cb8e9e
diff --git a/extras/snap_scheduler/gcron.py b/extras/snap_scheduler/gcron.py
cb8e9e
index a21c40f..d720578 100755
cb8e9e
--- a/extras/snap_scheduler/gcron.py
cb8e9e
+++ b/extras/snap_scheduler/gcron.py
cb8e9e
@@ -21,6 +21,7 @@ import fcntl
cb8e9e
 
cb8e9e
 GCRON_TASKS = "/var/run/gluster/shared_storage/snaps/glusterfs_snap_cron_tasks"
cb8e9e
 GCRON_CROND_TASK = "/etc/cron.d/glusterfs_snap_cron_tasks"
cb8e9e
+GCRON_RELOAD_FLAG = "/var/run/gluster/crond_task_reload_flag"
cb8e9e
 LOCK_FILE_DIR = "/var/run/gluster/shared_storage/snaps/lock_files/"
cb8e9e
 log = logging.getLogger("gcron-logger")
cb8e9e
 start_time = 0.0
cb8e9e
@@ -121,9 +122,41 @@ def main():
cb8e9e
     global start_time
cb8e9e
     if sys.argv[1] == "--update":
cb8e9e
         if not os.path.exists(GCRON_TASKS):
cb8e9e
+            # Create a flag in /var/run/gluster which indicates that this nodes
cb8e9e
+            # doesn't have access to GCRON_TASKS right now, so that
cb8e9e
+            # when the mount is available and GCRON_TASKS is available
cb8e9e
+            # the flag will tell this routine to reload GCRON_CROND_TASK
cb8e9e
+            try:
cb8e9e
+                f = os.open(GCRON_RELOAD_FLAG, os.O_CREAT | os.O_NONBLOCK, 0644)
cb8e9e
+                os.close(f)
cb8e9e
+            except OSError as (errno, strerror):
cb8e9e
+                if errno != EEXIST:
cb8e9e
+                    log.error("Failed to create %s : %s",
cb8e9e
+                              GCRON_RELOAD_FLAG, strerror)
cb8e9e
+                    output("Failed to create %s. Error: %s"
cb8e9e
+                           % (GCRON_RELOAD_FLAG, strerror))
cb8e9e
             return
cb8e9e
+
cb8e9e
         if not os.path.exists(GCRON_CROND_TASK):
cb8e9e
             return
cb8e9e
+
cb8e9e
+        # As GCRON_TASKS exists now, we should check if GCRON_RELOAD_FLAG
cb8e9e
+        # also exists. If so we should touch GCRON_CROND_TASK and remove
cb8e9e
+        # the GCRON_RELOAD_FLAG
cb8e9e
+        if os.path.exists(GCRON_RELOAD_FLAG):
cb8e9e
+            try:
cb8e9e
+                os.remove(GCRON_RELOAD_FLAG);
cb8e9e
+                process = subprocess.Popen(["touch", "-h", GCRON_CROND_TASK],
cb8e9e
+                                           stdout=subprocess.PIPE,
cb8e9e
+                                           stderr=subprocess.PIPE)
cb8e9e
+                out, err = process.communicate()
cb8e9e
+                if process.returncode != 0:
cb8e9e
+                    log.error("Failed to touch %s. Error: %s.",
cb8e9e
+                              GCRON_CROND_TASK, err)
cb8e9e
+            except (IOError, OSError) as (errno, strerror):
cb8e9e
+                log.error("Failed to touch %s. Error: %s.",
cb8e9e
+                          GCRON_CROND_TASK, strerror)
cb8e9e
+            return
cb8e9e
         if os.lstat(GCRON_TASKS).st_mtime > \
cb8e9e
            os.lstat(GCRON_CROND_TASK).st_mtime:
cb8e9e
             try:
cb8e9e
-- 
cb8e9e
1.7.1
cb8e9e