fix: installer tolerates localized 'service exists' (1073) and restarts the service if an upgrade step fails; 1.1.7
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -201,7 +201,8 @@ def install_service(install_dir_path: Path) -> None:
|
||||
exe = Path(install_dir_path) / "GTIFiscalAgentService" / "GTIFiscalAgentService.exe"
|
||||
bin_path = f"\"{exe}\""
|
||||
result = _sc(["create", SERVICE_NAME, "binPath=", bin_path, "start=", "auto", "DisplayName=", SERVICE_DISPLAY])
|
||||
if result.returncode != 0 and "already exists" not in (result.stdout + result.stderr):
|
||||
# 1073 = ERROR_SERVICE_EXISTS. Match the code, never the message: the text is localized (pt-BR: "já existe").
|
||||
if result.returncode not in (0, 1073) and "already exists" not in (result.stdout + result.stderr):
|
||||
raise RuntimeError(f"sc create failed: {result.stdout} {result.stderr}".strip())
|
||||
_sc(["config", SERVICE_NAME, "start=", "delayed-auto"])
|
||||
_sc(["config", SERVICE_NAME, "obj=", "LocalSystem"])
|
||||
|
||||
@@ -142,10 +142,15 @@ def upgrade_flow(*, install_dir_path: str | None = None, progress: Callable[[str
|
||||
progress("Atualizando o Agent (identidade e credenciais preservadas)…")
|
||||
if common.service_installed():
|
||||
common.ensure_service_stopped()
|
||||
extract_payload(install)
|
||||
common.upgrade_agent_env(install, version)
|
||||
common.install_service(install)
|
||||
common.write_arp_uninstall(install)
|
||||
try:
|
||||
extract_payload(install)
|
||||
common.upgrade_agent_env(install, version)
|
||||
common.install_service(install)
|
||||
common.write_arp_uninstall(install)
|
||||
except Exception as error: # noqa: BLE001 — never leave the host without a running Agent because an upgrade step failed
|
||||
common.ilog(f"upgrade step failed: {error!r}; restarting the existing service")
|
||||
common.start_and_verify(attempts=2)
|
||||
raise
|
||||
os.environ["AGENT_VERSION"] = version
|
||||
progress("Iniciando o serviço…")
|
||||
common.ilog(f"upgrade to {version} from {existing.get('agent_id')}")
|
||||
|
||||
Reference in New Issue
Block a user