diff --git a/cronwrapper/__init__.py b/cronwrapper/__init__.py index 55d07b9..79d9e83 100755 --- a/cronwrapper/__init__.py +++ b/cronwrapper/__init__.py @@ -181,13 +181,18 @@ def main(): resfile = os.path.join(libdir, 'result') success = True + has_lock = True 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: - e.write("CRONWRAPPER: Unable to aquire lock, previous instance still running?\n") - r.write("\nFalse\n") - res = False + has_lock = aquire_lock(lckfile) + if has_lock: + res = exec_command(args, o, e, r) + else: + e.write("CRONWRAPPER: Unable to aquire lock, previous instance still running?\n") + r.write("\nFalse\n") + res = False if res in args.success_exit_codes: # Possible success, check error output @@ -249,7 +254,8 @@ def main(): print("Cronjob failed\n") print_runs([libdir], clean=False) - release_lock(lckfile) + if has_lock: + release_lock(lckfile) if __name__ == '__main__': sys.exit(main())