auto update improvements

This commit is contained in:
wh1te909 2020-09-17 01:52:12 +00:00
parent d87c3f7b1d
commit 4a4b07f03b
1 changed files with 33 additions and 1 deletions

View File

@ -145,6 +145,29 @@ def install_updates():
return __salt__["cmd.run_bg"]([TAC_RMM, "-m", "winupdater"]) return __salt__["cmd.run_bg"]([TAC_RMM, "-m", "winupdater"])
def _wait_for_service(svc, status, retries=10):
attempts = 0
while 1:
try:
service = psutil.win_service_get(svc)
except psutil.NoSuchProcess:
stat = "fail"
attempts += 1
sleep(5)
else:
stat = service.status()
if stat != status:
attempts += 1
sleep(5)
else:
attempts = 0
if attempts == 0 or attempts > retries:
break
return stat
def agent_update_v2(inno, url): def agent_update_v2(inno, url):
# make sure another instance of the update is not running # make sure another instance of the update is not running
# this function spawns 2 instances of itself (because we call it twice with salt run_bg) # this function spawns 2 instances of itself (because we call it twice with salt run_bg)
@ -185,7 +208,16 @@ def agent_update_v2(inno, url):
f.write(chunk) f.write(chunk)
del r del r
ret = subprocess.run([exe, "/VERYSILENT", "/SUPPRESSMSGBOXES"], timeout=90) ret = subprocess.run([exe, "/VERYSILENT", "/SUPPRESSMSGBOXES"], timeout=120)
tac = _wait_for_service(svc="tacticalagent", status="running")
if tac != "running":
subprocess.run([NSSM, "start", "tacticalagent"], timeout=30)
chk = _wait_for_service(svc="checkrunner", status="running")
if chk != "running":
subprocess.run([NSSM, "start", "checkrunner"], timeout=30)
return "ok" return "ok"