-
-
Save gyoza/ca10b504a7a4f3aa2cdcae2f57faa1a2 to your computer and use it in GitHub Desktop.
lockfiles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def touch(path): | |
with open(path, 'a'): | |
os.utime(path, None) | |
def lock_file(LOCK_FILE): | |
now = datetime.now() | |
restart_hours = [1] | |
if now.hour in restart_hours: | |
if VERBOSE: PrettyLogger(log_level="info", msg="H|Restart hour hgreen|Found.") | |
if (now.minute <= 0 or 59): | |
if VERBOSE: PrettyLogger(log_level="info", msg="H|Restart minute hgreen|Found.") | |
if os.path.isfile(LOCK_FILE): | |
LOCK_FILE_time = int(getmtime(LOCK_FILE)) | |
now = int(time.time()) | |
file_age = now - LOCK_FILE_time | |
if file_age > 39600: | |
PrettyLogger(log_level="info", msg="H|Restart file older than 10 hours, hgreen|RESTARTING") | |
touch(LOCK_FILE) | |
shell_all = 'echo dostuff' | |
return_code = subprocess.call(shell_all, shell=True) | |
else: | |
PrettyLogger(log_level="info", msg="H|Restart less than 10 hours old. No restart required.".format(file_age)) | |
else: | |
PrettyLogger(log_level="info", msg="H|No restart file found, hgreen|RESTARTING") | |
touch(LOCK_FILE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment