Fix MySQL diagnostic script quoting
This commit is contained in:
@@ -558,10 +558,9 @@ def ensure_mysql_service_running(
|
||||
else:
|
||||
service_log = default_mysql_service_log_path()
|
||||
on_output(f"MySQL 服务启动日志: {service_log}")
|
||||
exit_code = run_elevated_command_with_log(
|
||||
build_mysql_service_start_command(service_name),
|
||||
exit_code = run_mysql_service_start_diagnostic(
|
||||
service_name,
|
||||
service_log,
|
||||
show_window=False,
|
||||
)
|
||||
if exit_code not in {0, 1056}:
|
||||
detail = _read_install_log_tail(default_mysql_service_log_path(), max_lines=24)
|
||||
@@ -586,9 +585,9 @@ def ensure_mysql_service_running(
|
||||
)
|
||||
|
||||
|
||||
def build_mysql_service_start_command(service_name: str = "MySQL80") -> list[str]:
|
||||
def build_mysql_service_start_script(service_name: str = "MySQL80") -> str:
|
||||
escaped_service_name = service_name.replace("'", "''")
|
||||
script = (
|
||||
return (
|
||||
"$ErrorActionPreference='Continue';"
|
||||
f"$name='{escaped_service_name}';"
|
||||
"$startError='';"
|
||||
@@ -607,15 +606,28 @@ def build_mysql_service_start_command(service_name: str = "MySQL80") -> list[str
|
||||
"else{Write-Output 'No .err log found with administrator privileges.'};"
|
||||
"if($service.State -eq 'Running'){exit 0}else{exit 1}"
|
||||
)
|
||||
return [
|
||||
"powershell.exe",
|
||||
"-NoProfile",
|
||||
"-NonInteractive",
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-Command",
|
||||
script,
|
||||
]
|
||||
|
||||
|
||||
def run_mysql_service_start_diagnostic(service_name: str, log_path: Path) -> int:
|
||||
with tempfile.TemporaryDirectory(prefix="autodeploy-mysql-service-") as temporary:
|
||||
script_path = Path(temporary) / "start-mysql-service.ps1"
|
||||
script_path.write_text(
|
||||
build_mysql_service_start_script(service_name),
|
||||
encoding="utf-8-sig",
|
||||
)
|
||||
return run_elevated_command_with_log(
|
||||
[
|
||||
"powershell.exe",
|
||||
"-NoProfile",
|
||||
"-NonInteractive",
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
str(script_path),
|
||||
],
|
||||
log_path,
|
||||
show_window=False,
|
||||
)
|
||||
|
||||
|
||||
def find_mysql_error_log(mysql_executable: Path | None = None) -> Path | None:
|
||||
|
||||
Reference in New Issue
Block a user