do not remove lock if we were not the ones to aquire it...

This commit is contained in:
Fredrik Eriksson 2021-03-08 16:39:25 +01:00
parent e5bf87c7ab
commit f56efb0085
Signed by: feffe
GPG Key ID: F4329687B0FA7F8D

View File

@ -181,8 +181,13 @@ def main():
resfile = os.path.join(libdir, 'result') resfile = os.path.join(libdir, 'result')
success = True success = True
has_lock = True
with open(outfile, 'w') as o, open(errfile, 'w+') as e, open(resfile, 'w') as r: with open(outfile, 'w') as o, open(errfile, 'w+') as e, open(resfile, 'w') as r:
if args.no_lock or aquire_lock(lckfile): if args.no_lock:
res = exec_command(args, o, e, r)
else:
has_lock = aquire_lock(lckfile)
if has_lock:
res = exec_command(args, o, e, r) res = exec_command(args, o, e, r)
else: else:
e.write("CRONWRAPPER: Unable to aquire lock, previous instance still running?\n") e.write("CRONWRAPPER: Unable to aquire lock, previous instance still running?\n")
@ -249,6 +254,7 @@ def main():
print("Cronjob failed\n") print("Cronjob failed\n")
print_runs([libdir], clean=False) print_runs([libdir], clean=False)
if has_lock:
release_lock(lckfile) release_lock(lckfile)
if __name__ == '__main__': if __name__ == '__main__':