Commit fe93383e by Szeberényi Imre

win_exe\debug

parent e8f8a3e8
......@@ -57,7 +57,7 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
timo = timo_base
sleep(6*timo) # boot process may have triggered the agent, so we are patient
while not self._stopped:
logger.debug("checking....(timo: %d)", timo)
# logger.debug("checking....(timo: %d)", timo)
if not check_service(checked_service):
logger.info("Service %s is not running.", checked_service)
try:
......@@ -83,10 +83,12 @@ class AppServerSvc (win32serviceutil.ServiceFramework):
working_dir = r"C:\circle"
exe = "circle-watchdog.exe"
exe_path = join(working_dir, exe)
logger.debug("hahooo %s %s", self._svc_name_, exe_path)
if update_component(self._svc_name_ + ".state", workdir) == "exit":
logger.debug("Update check: %s %s", self._svc_name_, exe_path)
update = update_component(self._svc_name_ + ".state", workdir)
logger.info("Update status: %s", update)
if update == "exit":
# Service updated, Restart needed
logger.debug("update....")
logger.info("Exit for update....")
self.ReportServiceStatus(
win32service.SERVICE_STOPPED,
win32ExitCode=winerror.ERROR_SERVICE_SPECIFIC_ERROR, # 1066
......
......@@ -52,7 +52,8 @@ if win:
level
)
logger.setLevel(level)
# system = get_windows_version()
system = get_windows_version()
system = "DEBUG"
from context import get_context, get_serial # noqa
......
......@@ -2,7 +2,6 @@
"img": "circle-watchdog.exe",
"img_pending": "agent-wdog-winservice.exe",
"service": "circle-watchdog",
"state": "idle",
"last_checked": "2026-01-15T18:08:08.331288+00:00Z",
"status": "idle"
"status": "idle",
"last_checked": "2026-01-15T18:08:08.331288+00:00Z"
}
\ 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 -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-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-winservice.py
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
# -*- coding: utf-8 -*-
from os.path import join
from os.path import join, exists
import sys
import logging
......@@ -21,7 +21,7 @@ from context import BaseContext
from windows.winutils import (
is_frozen_exe, copy_running_exe,
update_service_binpath, servicePostUpdate,
run_with_powershell
start_process_async
)
try:
......@@ -128,13 +128,14 @@ class Context(BaseContext):
logger.error(e)
return
logger.info("Transfer completed!")
if executable.startswith("0000_"):
if executable.startswith("000_"):
logger.debug("starting %s in %s", executable, Context.workdir)
start_process_async(executable, workdir=Context.workdir)
else:
old_exe = update_service_binpath("CIRCLE-agent", join(Context.workdir, executable))
logger.info('%s Updated', old_exe)
if os.path.exists(join(Context.workdir, Context.update_cmd)):
if executable.startswith("0_"):
old_exe = update_service_binpath("CIRCLE-agent", join(Context.workdir, executable))
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)
start_process_async(Context.update_cmd, workdir=Context.workdir, delay_seconds=60)
Context.exit_code = 1
......
"""
winutils.py --- Windows helpers
"""
import os
import sys
import logging
......@@ -5,8 +9,7 @@ import subprocess
import json
import tempfile
from datetime import datetime, timezone
from shutil import copy
from shutil import copy2
from os.path import join, normcase, normpath
from winreg import (
OpenKeyEx, QueryValueEx, SetValueEx,
......@@ -50,7 +53,7 @@ def copy_running_exe(dest: str) -> bool:
if normcase(current_exe) == normcase(dest):
return False
copy(current_exe, dest)
copy2(current_exe, dest)
return True
def servicePostUpdate(service_name, exe_path):
......@@ -79,8 +82,7 @@ def getRegistryVal(reg_path: str, name: str, default=None):
value, _ = QueryValueEx(key, name)
except Exception as e:
logger.debug("Registry read failed %s\\%s: %s",
reg_path, name, e
)
reg_path, name, e)
return value
def start_process_async(path, args=None, workdir=None, delay_seconds=0):
......@@ -213,9 +215,6 @@ def save_json(path, data):
except OSError:
pass
import os
import sys
import shutil
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
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 = 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"
save_json(state_file, state)
img = state.get("img")
......@@ -240,7 +247,8 @@ def update_component(state_file: str, base_dir: str) -> str:
service = state.get("service")
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_pending_path = os.path.join(base_dir, img_pending)
......@@ -279,7 +287,7 @@ def update_component(state_file: str, base_dir: str) -> str:
if status == "pending" and is_self_img_pending:
# 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)
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