From a2e041458cbdf7b758e1af5d1e0c897f34bbc7c0 Mon Sep 17 00:00:00 2001 From: Avra Sengupta Date: Sun, 5 Jul 2015 12:57:39 +0530 Subject: snapshot/scheduler: Use /var/run/gluster/shared_storage/snaps/tmp_file for writing data into tmp file and then making an atomic rename to the required filename The reason for using this location is that it adheres to the selinux policies. Also moving the update of the current_scheduler file, under the lock so as to avoid multiple writes Change-Id: I61e62b5daf6f1bce2319f64f7b1dfb8b93726077 BUG: 1239270 Signed-off-by: Avra Sengupta Reviewed-on: http://review.gluster.org/11536 Tested-by: NetBSD Build System Tested-by: Gluster Build System Reviewed-by: Rajesh Joseph --- extras/snap_scheduler/snap_scheduler.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'extras/snap_scheduler/snap_scheduler.py') diff --git a/extras/snap_scheduler/snap_scheduler.py b/extras/snap_scheduler/snap_scheduler.py index 09015c52f79..ce808cf16ba 100755 --- a/extras/snap_scheduler/snap_scheduler.py +++ b/extras/snap_scheduler/snap_scheduler.py @@ -423,7 +423,7 @@ def edit_schedules(jobname, schedule, volname): def initialise_scheduler(): try: - with open("/tmp/crontab", "w+", 0644) as f: + with open(TMP_FILE, "w+", 0644) as f: updater = ("* * * * * root PATH=$PATH:/usr/local/sbin:" "/usr/sbin gcron.py --update\n") f.write("%s\n" % updater) @@ -431,11 +431,11 @@ def initialise_scheduler(): os.fsync(f.fileno()) f.close() except IOError as (errno, strerror): - log.error("Failed to open /tmp/crontab. Error: %s.", strerror) + log.error("Failed to open %s. Error: %s.", TMP_FILE, strerror) ret = INIT_FAILED return ret - shutil.move("/tmp/crontab", GCRON_UPDATE_TASK) + shutil.move(TMP_FILE, GCRON_UPDATE_TASK) if not os.path.lexists(GCRON_TASKS): try: @@ -491,6 +491,9 @@ def syntax_checker(args): def perform_operation(args): + if not os.path.exists(CURRENT_SCHEDULER): + update_current_scheduler("none") + # Initialise snapshot scheduler on local node if args.action == "init": ret = initialise_scheduler() @@ -651,9 +654,6 @@ def main(argv): % (LOCK_FILE_DIR, strerror)) return INTERNAL_ERROR - if not os.path.exists(CURRENT_SCHEDULER): - update_current_scheduler("none") - try: f = os.open(LOCK_FILE, os.O_CREAT | os.O_RDWR | os.O_NONBLOCK, 0644) try: -- cgit