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