增加log日志,关机的锁

This commit is contained in:
wangsong 2021-12-02 13:54:32 +08:00
parent 5e1d9d36be
commit 993511903f
1 changed files with 7 additions and 4 deletions

View File

@ -739,9 +739,10 @@ def LockedPreventShutdown():
try: try:
if not locked: if not locked:
fcntl.flock(pidfile, fcntl.LOCK_EX | fcntl.LOCK_NB) fcntl.flock(pidfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
logging.info("Has been locked.") logging.info("Shutdown Has been locked...")
locked = True locked = True
except: except Exception as e:
logging.error(str(e))
locked = False locked = False
logging.error("file cannot be locked.") logging.error("file cannot be locked.")
return False return False
@ -751,13 +752,15 @@ def unLockedEnableShutdown():
global pidfile global pidfile
global locked global locked
if not pidfile: if not pidfile:
logging.errr("pidfile file disc is None...")
return False return False
try: try:
fcntl.flock(pidfile, fcntl.LOCK_UN) fcntl.flock(pidfile, fcntl.LOCK_UN)
pidfile.close() pidfile.close()
locked = False locked = False
logging.info("Has been unlocked.") logging.info("Shutdown Has been unlocked...")
except: except Exception as e:
logging.error(str(e))
logging.error("unlock failed.") logging.error("unlock failed.")
return False return False