Commit fe93383e by Szeberényi Imre

win_exe\debug

parent e8f8a3e8
...@@ -57,7 +57,7 @@ class AppServerSvc (win32serviceutil.ServiceFramework): ...@@ -57,7 +57,7 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
timo = timo_base timo = timo_base
sleep(6*timo) # boot process may have triggered the agent, so we are patient sleep(6*timo) # boot process may have triggered the agent, so we are patient
while not self._stopped: while not self._stopped:
logger.debug("checking....(timo: %d)", timo) # logger.debug("checking....(timo: %d)", timo)
if not check_service(checked_service): if not check_service(checked_service):
logger.info("Service %s is not running.", checked_service) logger.info("Service %s is not running.", checked_service)
try: try:
...@@ -83,10 +83,12 @@ class AppServerSvc (win32serviceutil.ServiceFramework): ...@@ -83,10 +83,12 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
working_dir = r"C:\circle" working_dir = r"C:\circle"
exe = "circle-watchdog.exe" exe = "circle-watchdog.exe"
exe_path = join(working_dir, exe) exe_path = join(working_dir, exe)
logger.debug("hahooo %s %s", self._svc_name_, exe_path) logger.debug("Update check: %s %s", self._svc_name_, exe_path)
if update_component(self._svc_name_ + ".state", workdir) == "exit": update = update_component(self._svc_name_ + ".state", workdir)
logger.info("Update status: %s", update)
if update == "exit":
# Service updated, Restart needed # Service updated, Restart needed
logger.debug("update....") logger.info("Exit for update....")
self.ReportServiceStatus( self.ReportServiceStatus(
win32service.SERVICE_STOPPED, win32service.SERVICE_STOPPED,
win32ExitCode=winerror.ERROR_SERVICE_SPECIFIC_ERROR, # 1066 win32ExitCode=winerror.ERROR_SERVICE_SPECIFIC_ERROR, # 1066
......
...@@ -52,7 +52,8 @@ if win: ...@@ -52,7 +52,8 @@ if win:
level level
) )
logger.setLevel(level) logger.setLevel(level)
# system = get_windows_version() system = get_windows_version()
system = "DEBUG"
from context import get_context, get_serial # noqa from context import get_context, get_serial # noqa
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
"img": "circle-watchdog.exe", "img": "circle-watchdog.exe",
"img_pending": "agent-wdog-winservice.exe", "img_pending": "agent-wdog-winservice.exe",
"service": "circle-watchdog", "service": "circle-watchdog",
"state": "idle", "status": "idle",
"last_checked": "2026-01-15T18:08:08.331288+00:00Z", "last_checked": "2026-01-15T18:08:08.331288+00:00Z"
"status": "idle"
} }
\ No newline at end of file
pyinstaller --clean -F --path . --hidden-import pkg_resources --hidden-import infi --hidden-import win32timezone --hidden-import win32traceutil -F agent-wdog-winservice.py pyinstaller --clean -F --path . --hidden-import pkg_resources --hidden-import infi --hidden-import win32timezone --hidden-import win32traceutil --exclude-module tkinter --exclude-module _tkinter -F agent-wdog-winservice.py
pyinstaller --clean -F --path . --hidden-import pkg_resources --hidden-import infi --hidden-import win32timezone --hidden-import win32traceutil -F agent-winservice.py pyinstaller --clean -F --path . --hidden-import pkg_resources --hidden-import infi --hidden-import win32timezone --hidden-import win32traceutil --exclude-module tkinter --exclude-module _tkinter -F agent-winservice.py
pyinstaller --clean -F --path . --hidden-import pkg_resources --hidden-import infi --hidden-import win32timezone --hidden-import win32traceutil -F agent-notify.pyw pyinstaller --clean -F --path . --hidden-import pkg_resources --hidden-import infi --hidden-import win32timezone --hidden-import win32traceutil -F agent-notify.pyw
\ No newline at end of file
{
"img": "circle-watchdog.exe",
"img_pending": "agent-wdog-winservice.exe",
"service": "circle-watchdog",
"status": "idle",
"last_checked": "2026-01-15T21:06:58.683711+00:00Z"
}
\ No newline at end of file
{
"img": "circle-watchdog.exe",
"img_pending": "agent-wdog-winservice.exe",
"service": "circle-watchdog",
"status": "idle",
"last_checked": "2026-01-15T18:08:08.331288+00:00Z"
}
\ No newline at end of file
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from os.path import join from os.path import join, exists
import sys import sys
import logging import logging
...@@ -21,7 +21,7 @@ from context import BaseContext ...@@ -21,7 +21,7 @@ from context import BaseContext
from windows.winutils import ( from windows.winutils import (
is_frozen_exe, copy_running_exe, is_frozen_exe, copy_running_exe,
update_service_binpath, servicePostUpdate, update_service_binpath, servicePostUpdate,
run_with_powershell start_process_async
) )
try: try:
...@@ -128,13 +128,14 @@ class Context(BaseContext): ...@@ -128,13 +128,14 @@ class Context(BaseContext):
logger.error(e) logger.error(e)
return return
logger.info("Transfer completed!") logger.info("Transfer completed!")
if executable.startswith("0000_"): if executable.startswith("000_"):
logger.debug("starting %s in %s", executable, Context.workdir) logger.debug("starting %s in %s", executable, Context.workdir)
start_process_async(executable, workdir=Context.workdir) start_process_async(executable, workdir=Context.workdir)
else: else:
old_exe = update_service_binpath("CIRCLE-agent", join(Context.workdir, executable)) if executable.startswith("0_"):
logger.info('%s Updated', old_exe) old_exe = update_service_binpath("CIRCLE-agent", join(Context.workdir, executable))
if os.path.exists(join(Context.workdir, Context.update_cmd)): logger.info('%s Updated', old_exe)
if exists(join(Context.workdir, Context.update_cmd)):
logger.debug("starting %s in %s", Context.update_cmd, Context.workdir) logger.debug("starting %s in %s", Context.update_cmd, Context.workdir)
start_process_async(Context.update_cmd, workdir=Context.workdir, delay_seconds=60) start_process_async(Context.update_cmd, workdir=Context.workdir, delay_seconds=60)
Context.exit_code = 1 Context.exit_code = 1
......
"""
winutils.py --- Windows helpers
"""
import os import os
import sys import sys
import logging import logging
...@@ -5,8 +9,7 @@ import subprocess ...@@ -5,8 +9,7 @@ import subprocess
import json import json
import tempfile import tempfile
from datetime import datetime, timezone from datetime import datetime, timezone
from shutil import copy2
from shutil import copy
from os.path import join, normcase, normpath from os.path import join, normcase, normpath
from winreg import ( from winreg import (
OpenKeyEx, QueryValueEx, SetValueEx, OpenKeyEx, QueryValueEx, SetValueEx,
...@@ -50,7 +53,7 @@ def copy_running_exe(dest: str) -> bool: ...@@ -50,7 +53,7 @@ def copy_running_exe(dest: str) -> bool:
if normcase(current_exe) == normcase(dest): if normcase(current_exe) == normcase(dest):
return False return False
copy(current_exe, dest) copy2(current_exe, dest)
return True return True
def servicePostUpdate(service_name, exe_path): def servicePostUpdate(service_name, exe_path):
...@@ -79,8 +82,7 @@ def getRegistryVal(reg_path: str, name: str, default=None): ...@@ -79,8 +82,7 @@ def getRegistryVal(reg_path: str, name: str, default=None):
value, _ = QueryValueEx(key, name) value, _ = QueryValueEx(key, name)
except Exception as e: except Exception as e:
logger.debug("Registry read failed %s\\%s: %s", logger.debug("Registry read failed %s\\%s: %s",
reg_path, name, e reg_path, name, e)
)
return value return value
def start_process_async(path, args=None, workdir=None, delay_seconds=0): def start_process_async(path, args=None, workdir=None, delay_seconds=0):
...@@ -213,9 +215,6 @@ def save_json(path, data): ...@@ -213,9 +215,6 @@ def save_json(path, data):
except OSError: except OSError:
pass pass
import os
import sys
import shutil
def update_component(state_file: str, base_dir: str) -> str: def update_component(state_file: str, base_dir: str) -> str:
""" """
...@@ -230,8 +229,16 @@ def update_component(state_file: str, base_dir: str) -> str: ...@@ -230,8 +229,16 @@ def update_component(state_file: str, base_dir: str) -> str:
and user-mode processes. The running image is identified by comparing and user-mode processes. The running image is identified by comparing
sys.executable with the configured image names. sys.executable with the configured image names.
""" """
if not is_frozen_exe():
return "Not frozen"
state_file = os.path.join(base_dir, state_file) state_file = os.path.join(base_dir, state_file)
state = load_json(state_file, default={})
try:
state = load_json(state_file)
except (FileNotFoundError, json.JSONDecodeError, OSError) as e:
logger.error("Cannot load state: %s", e)
return "State file error"
state["last_checked"] = datetime.now(timezone.utc).isoformat() + "Z" state["last_checked"] = datetime.now(timezone.utc).isoformat() + "Z"
save_json(state_file, state) save_json(state_file, state)
img = state.get("img") img = state.get("img")
...@@ -240,7 +247,8 @@ def update_component(state_file: str, base_dir: str) -> str: ...@@ -240,7 +247,8 @@ def update_component(state_file: str, base_dir: str) -> str:
service = state.get("service") service = state.get("service")
if not img or not img_pending: if not img or not img_pending:
raise ValueError("status json must contain 'img' and 'img_pending'") return "Miisng basic update info"
# raise ValueError("status json must contain 'img' and 'img_pending'")
img_path = os.path.join(base_dir, img) img_path = os.path.join(base_dir, img)
img_pending_path = os.path.join(base_dir, img_pending) img_pending_path = os.path.join(base_dir, img_pending)
...@@ -279,7 +287,7 @@ def update_component(state_file: str, base_dir: str) -> str: ...@@ -279,7 +287,7 @@ def update_component(state_file: str, base_dir: str) -> str:
if status == "pending" and is_self_img_pending: if status == "pending" and is_self_img_pending:
# we are running as img_pending -> safe to overwrite img (img is not running) # we are running as img_pending -> safe to overwrite img (img is not running)
shutil.copy2(img_pending_path, img_path) copy2(img_pending_path, img_path)
logger.debug("Copy: %s ---> %s", img_pending_path, img_path) logger.debug("Copy: %s ---> %s", img_pending_path, img_path)
state["status"] = "copied" state["status"] = "copied"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment