完善三平台安装包与服务控制流程
统一服务默认端口为 59188,完善 Windows 服务权限与 macOS LaunchAgent 管理。 实现 Windows 与 macOS 托盘状态机、服务启停等待、单实例保护、日志目录入口和退出前清理后台服务。 统一 Linux、Windows、macOS 与 Docker 的 Playwright Chromium runtime 构建流程,增加缓存、架构校验和 Linux 原生 runner,避免 QEMU。 完善 Windows、macOS、Linux 安装包及签名打包脚本,修正 Chromium 嵌入、服务注册和安装卸载流程。 同步 README、AGENTS、官网首页、Wiki 与前端开发文档,统一端口、初始化、服务、日志、托盘和安装说明。
This commit is contained in:
1 parent
94f4e070f6
commit
2df324647a
35 files changed
+1546
-214
No files matched your search
@@ -5,6 +5,7 @@ APP_NAME="ydisks-xianyu-helper"
|
||||
INSTALL_DIR="/opt/$APP_NAME"
|
||||
DATA_DIR="/var/lib/$APP_NAME"
|
||||
CONFIG_DIR="/etc/$APP_NAME"
|
||||
LOG_DIR="/var/log/$APP_NAME"
|
||||
SERVICE_NAME="$APP_NAME.service"
|
||||
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
||||
|
||||
@@ -55,6 +56,7 @@ fi
|
||||
systemctl stop "$SERVICE_NAME" >/dev/null 2>&1 || true
|
||||
install -d -m 0755 "$INSTALL_DIR"
|
||||
install -d -o "$APP_NAME" -g "$APP_NAME" -m 0750 "$DATA_DIR"
|
||||
install -d -o "$APP_NAME" -g "$APP_NAME" -m 0750 "$LOG_DIR"
|
||||
rm -rf "$INSTALL_DIR/playwright-runtime"
|
||||
install -d -m 0755 "$INSTALL_DIR/playwright-runtime"
|
||||
cp -R "$RUNTIME_SOURCE/." "$INSTALL_DIR/playwright-runtime/"
|
||||
|
||||
@@ -9,7 +9,8 @@ User=ydisks-xianyu
|
||||
Group=ydisks-xianyu
|
||||
WorkingDirectory=/var/lib/ydisks-xianyu-helper
|
||||
EnvironmentFile=-/etc/ydisks-xianyu-helper/config.env
|
||||
ExecStart=/opt/ydisks-xianyu-helper/xianyu-server -addr 127.0.0.1:8080 -workdir /var/lib/ydisks-xianyu-helper -data-key-file /var/lib/ydisks-xianyu-helper/data-key -playwright-runtime-root /opt/ydisks-xianyu-helper/playwright-runtime
|
||||
Environment=XIANYU_LOG_DIR=/var/log/ydisks-xianyu-helper
|
||||
ExecStart=/opt/ydisks-xianyu-helper/xianyu-server -addr 127.0.0.1:59188 -workdir /var/lib/ydisks-xianyu-helper -data-key-file /var/lib/ydisks-xianyu-helper/data-key -playwright-runtime-root /opt/ydisks-xianyu-helper/playwright-runtime
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
KillSignal=SIGTERM
|
||||
|
||||
@@ -22,9 +22,30 @@ if [ ! -x "$BIN_DIR/xianyu-server" ] || [ ! -x "$BIN_DIR/xianyu-tray" ]; then
|
||||
echo "缺少 $ARCH 架构的桌面二进制:$BIN_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -d "$DIST_DIR/playwright-runtime/$ARCH/playwright-driver" ] || \
|
||||
[ ! -d "$DIST_DIR/playwright-runtime/$ARCH/playwright-browsers" ]; then
|
||||
echo "缺少 $ARCH 架构的 Playwright runtime:$DIST_DIR/playwright-runtime/$ARCH" >&2
|
||||
case "$ARCH" in
|
||||
arm64) PLATFORM_ARCH="arm64" ;;
|
||||
amd64) PLATFORM_ARCH="x64" ;;
|
||||
esac
|
||||
runtime_dir="$DIST_DIR/playwright-runtime/$ARCH"
|
||||
runtime_has_chromium() {
|
||||
find "$runtime_dir/playwright-browsers" -type f \
|
||||
-path "*/chrome-mac-$PLATFORM_ARCH/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing" \
|
||||
-print -quit 2>/dev/null | grep -q .
|
||||
}
|
||||
runtime_has_headless_shell() {
|
||||
find "$runtime_dir/playwright-browsers" -type f \
|
||||
-path "*/chrome-headless-shell-mac-$PLATFORM_ARCH/chrome-headless-shell" \
|
||||
-print -quit 2>/dev/null | grep -q .
|
||||
}
|
||||
if [ ! -d "$runtime_dir/playwright-driver" ] || \
|
||||
[ ! -d "$runtime_dir/playwright-browsers" ] || \
|
||||
! runtime_has_chromium || ! runtime_has_headless_shell; then
|
||||
echo "未找到完整的 $ARCH Playwright runtime,尝试从本机缓存准备。" >&2
|
||||
"$SCRIPT_DIR/prepare-runtime.sh" "$ARCH" "$runtime_dir"
|
||||
fi
|
||||
|
||||
if ! runtime_has_chromium || ! runtime_has_headless_shell; then
|
||||
echo "Playwright runtime 缺少 $ARCH 架构的 Chromium 或 headless shell。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>__SERVER__</string>
|
||||
<string>-addr</string><string>127.0.0.1:8080</string>
|
||||
<string>-addr</string><string>127.0.0.1:59188</string>
|
||||
<string>-playwright-runtime-root</string><string>__RUNTIME_ROOT__</string>
|
||||
</array>
|
||||
<key>WorkingDirectory</key><string>__DATA_DIR__</string>
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
<key>Label</key><string>com.ydisks.xianyu-helper.tray</string>
|
||||
<key>ProgramArguments</key><array><string>__TRAY__</string></array>
|
||||
<key>RunAtLoad</key><true/>
|
||||
<key>StandardOutPath</key><string>__LOG_DIR__/tray.log</string>
|
||||
<key>StandardErrorPath</key><string>__LOG_DIR__/tray.log</string>
|
||||
<!-- 托盘允许用户退出;服务端 LaunchAgent 单独负责 KeepAlive。 -->
|
||||
<key>KeepAlive</key><false/>
|
||||
</dict>
|
||||
|
||||
Executable
+72
@@ -0,0 +1,72 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
# 将本机 Playwright 缓存整理成 macOS 安装包使用的固定 runtime 目录。
|
||||
# CI 通过 browser-install 下载 runtime;本地打包直接复用同一版本的缓存,
|
||||
# 不需要再次访问 npm 或 Chromium 下载地址。
|
||||
|
||||
ARCH="${1:?architecture is required (arm64 or amd64)}"
|
||||
DEST_DIR="${2:?runtime destination is required}"
|
||||
|
||||
case "$ARCH" in
|
||||
arm64) PLATFORM_ARCH="arm64" ;;
|
||||
amd64) PLATFORM_ARCH="x64" ;;
|
||||
*) echo "不支持的 macOS 架构:$ARCH" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
PLAYWRIGHT_GO_CACHE="${PLAYWRIGHT_GO_CACHE:-${HOME:?}/Library/Caches/ms-playwright-go}"
|
||||
PLAYWRIGHT_BROWSER_CACHE="${PLAYWRIGHT_BROWSER_CACHE:-${HOME:?}/Library/Caches/ms-playwright}"
|
||||
|
||||
if [ ! -d "$PLAYWRIGHT_GO_CACHE" ]; then
|
||||
echo "找不到 Playwright Go 缓存:$PLAYWRIGHT_GO_CACHE" >&2
|
||||
echo "请先运行 browser-install,或设置 PLAYWRIGHT_GO_CACHE。" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -d "$PLAYWRIGHT_BROWSER_CACHE" ]; then
|
||||
echo "找不到 Playwright 浏览器缓存:$PLAYWRIGHT_BROWSER_CACHE" >&2
|
||||
echo "请先运行 browser-install,或设置 PLAYWRIGHT_BROWSER_CACHE。" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DRIVER_DIR=""
|
||||
for candidate in "$PLAYWRIGHT_GO_CACHE"/[0-9]*; do
|
||||
if [ -d "$candidate/package" ] && [ -x "$candidate/node" ]; then
|
||||
DRIVER_DIR="$candidate"
|
||||
fi
|
||||
done
|
||||
if [ -z "$DRIVER_DIR" ]; then
|
||||
echo "Playwright Go 缓存中没有可用 driver:$PLAYWRIGHT_GO_CACHE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BROWSER_DIR=""
|
||||
HEADLESS_DIR=""
|
||||
for candidate in "$PLAYWRIGHT_BROWSER_CACHE"/chromium-[0-9]*; do
|
||||
[ -d "$candidate" ] || continue
|
||||
revision="${candidate##*/chromium-}"
|
||||
chrome="$candidate/chrome-mac-$PLATFORM_ARCH/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing"
|
||||
headless="$PLAYWRIGHT_BROWSER_CACHE/chromium_headless_shell-$revision/chrome-headless-shell-mac-$PLATFORM_ARCH/chrome-headless-shell"
|
||||
if [ -f "$chrome" ] && [ -f "$headless" ]; then
|
||||
BROWSER_DIR="$candidate"
|
||||
HEADLESS_DIR="$PLAYWRIGHT_BROWSER_CACHE/chromium_headless_shell-$revision"
|
||||
fi
|
||||
done
|
||||
if [ -z "$BROWSER_DIR" ]; then
|
||||
echo "Playwright 浏览器缓存中没有 $ARCH 架构的 Chromium/headless shell:$PLAYWRIGHT_BROWSER_CACHE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
revision="${BROWSER_DIR##*/chromium-}"
|
||||
if ! grep -q '"revision": "'"$revision"'"' "$DRIVER_DIR/package/browsers.json"; then
|
||||
echo "Playwright driver 与 Chromium revision 不匹配:driver=$DRIVER_DIR,browser=$revision" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf "$DEST_DIR/playwright-driver" "$DEST_DIR/playwright-browsers"
|
||||
mkdir -p "$DEST_DIR"
|
||||
cp -R "$DRIVER_DIR" "$DEST_DIR/playwright-driver"
|
||||
mkdir -p "$DEST_DIR/playwright-browsers"
|
||||
cp -R "$BROWSER_DIR" "$DEST_DIR/playwright-browsers/"
|
||||
cp -R "$HEADLESS_DIR" "$DEST_DIR/playwright-browsers/"
|
||||
|
||||
echo "已从本机缓存准备 macOS $ARCH Playwright runtime:revision=$revision"
|
||||
@@ -56,7 +56,8 @@ fi
|
||||
echo "使用 $RUNTIME_ARCH 架构的 Playwright runtime。"
|
||||
|
||||
mkdir -p "$DATA_DIR" "$LOG_DIR" "$AGENT_DIR"
|
||||
chown -R "$CONSOLE_USER" "$DATA_DIR" "$LOG_DIR" "$AGENT_DIR"
|
||||
chown -R "$CONSOLE_USER" "$DATA_DIR" "$LOG_DIR"
|
||||
chown "$CONSOLE_USER" "$AGENT_DIR"
|
||||
|
||||
escape_sed() {
|
||||
printf '%s' "$1" | sed 's/[&|]/\\&/g'
|
||||
@@ -78,6 +79,7 @@ sed -e "s|__SERVER__|$SERVER_ESCAPED|g" \
|
||||
-e "s|__RUNTIME_ROOT__|$RUNTIME_ROOT_ESCAPED|g" \
|
||||
"$APP/Contents/Resources/com.ydisks.xianyu-helper.server.plist.template" > "$server_plist"
|
||||
sed -e "s|__TRAY__|$TRAY_ESCAPED|g" \
|
||||
-e "s|__LOG_DIR__|$LOG_ESCAPED|g" \
|
||||
"$APP/Contents/Resources/com.ydisks.xianyu-helper.tray.plist.template" > "$tray_plist"
|
||||
chown "$CONSOLE_USER" "$server_plist" "$tray_plist"
|
||||
chmod 0644 "$server_plist" "$tray_plist"
|
||||
@@ -85,6 +87,24 @@ chmod 0644 "$server_plist" "$tray_plist"
|
||||
launchctl bootout "gui/$UID_VALUE/$SERVER_LABEL" >/dev/null 2>&1 || true
|
||||
launchctl bootout "gui/$UID_VALUE/$TRAY_LABEL" >/dev/null 2>&1 || true
|
||||
|
||||
# 旧版本的托盘曾经可能在 bootout 后脱离 launchd 继续存活。它仍然占用
|
||||
# 菜单栏并使用旧的控制逻辑,会让升级后的第二次启动看起来像启动失败。
|
||||
# 这里只按当前应用的绝对路径清理旧托盘,不影响其它程序。
|
||||
STALE_TRAY_PIDS="$(ps -axo pid=,command= | awk -v target="$TRAY" '$2 == target {print $1}')"
|
||||
for stale_pid in $STALE_TRAY_PIDS; do
|
||||
if [ "$stale_pid" != "$$" ] && [ -n "$stale_pid" ]; then
|
||||
kill -TERM "$stale_pid" >/dev/null 2>&1 || true
|
||||
fi
|
||||
done
|
||||
if [ -n "$STALE_TRAY_PIDS" ]; then
|
||||
sleep 1
|
||||
for stale_pid in $STALE_TRAY_PIDS; do
|
||||
if [ "$stale_pid" != "$$" ] && kill -0 "$stale_pid" >/dev/null 2>&1; then
|
||||
kill -KILL "$stale_pid" >/dev/null 2>&1 || true
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# 清理早期版本使用的个人域名标识,避免升级后新旧 LaunchAgent 同时运行。
|
||||
LEGACY_SERVER_LABEL="com.christ.ydisks-xianyu-helper.server"
|
||||
LEGACY_TRAY_LABEL="com.christ.ydisks-xianyu-helper.tray"
|
||||
@@ -94,5 +114,6 @@ rm -f "$AGENT_DIR/$LEGACY_SERVER_LABEL.plist" "$AGENT_DIR/$LEGACY_TRAY_LABEL.pli
|
||||
|
||||
launchctl bootstrap "gui/$UID_VALUE" "$server_plist"
|
||||
launchctl bootstrap "gui/$UID_VALUE" "$tray_plist"
|
||||
launchctl kickstart -k "gui/$UID_VALUE/$SERVER_LABEL"
|
||||
launchctl kickstart -k "gui/$UID_VALUE/$TRAY_LABEL"
|
||||
# bootstrap 会根据 RunAtLoad 自动启动两个 LaunchAgent。这里不能再调用
|
||||
# kickstart -k:它会给刚由 bootstrap 启动的托盘发送 SIGTERM,托盘会按
|
||||
# 正常退出流程停止服务,导致安装完成后第一次启动就被自己关掉。
|
||||
@@ -25,18 +25,39 @@ Source: "..\..\dist\windows\xianyu-server.exe"; DestDir: "{app}"; Flags: ignorev
|
||||
Source: "..\..\dist\windows\xianyu-tray.exe"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "..\..\icon\windows\icon.ico"; DestDir: "{app}"; Flags: ignoreversion
|
||||
Source: "..\..\dist\windows\playwright-runtime\*"; DestDir: "{app}\playwright-runtime"; Flags: recursesubdirs createallsubdirs ignoreversion
|
||||
Source: "service-control.ps1"; Flags: dontcopy
|
||||
Source: "service-control.ps1"; DestDir: "{app}"; Flags: ignoreversion
|
||||
|
||||
[Dirs]
|
||||
Name: "{#AppDataDir}"
|
||||
Name: "{#AppDataDir}\data"
|
||||
Name: "{#AppDataDir}\logs"; Permissions: users-modify
|
||||
|
||||
[Registry]
|
||||
Root: HKCU; Subkey: "Software\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "YdisksXianyuHelperTray"; ValueData: "{app}\xianyu-tray.exe"; Flags: uninsdeletevalue
|
||||
Root: HKCU; Subkey: "Software\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "YdisksXianyuHelperTray"; ValueData: """{app}\xianyu-tray.exe"""; Flags: uninsdeletevalue
|
||||
|
||||
[Run]
|
||||
Filename: "{sys}\sc.exe"; Parameters: "create YdisksXianyuHelper binPath= ""{app}\xianyu-server.exe"" -service -workdir {#AppDataDir} -data-key-file {#AppDataDir}\data-key -addr 127.0.0.1:8080 -playwright-runtime-root ""{app}\playwright-runtime"" start= delayed-auto"; Flags: runhidden waituntilterminated
|
||||
Filename: "{sys}\sc.exe"; Parameters: "start YdisksXianyuHelper"; Flags: runhidden waituntilterminated
|
||||
Filename: "{app}\xianyu-tray.exe"; Description: "启动菜单栏控制器"; Flags: nowait postinstall skipifsilent
|
||||
Filename: "{sys}\WindowsPowerShell\v1.0\powershell.exe"; Parameters: "-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -File ""{app}\service-control.ps1"" -Mode install -ExePath ""{app}\xianyu-server.exe"" -TrayPath ""{app}\xianyu-tray.exe"" -WorkDir ""{#AppDataDir}"" -RuntimeRoot ""{app}\playwright-runtime"""; Flags: runhidden waituntilterminated
|
||||
Filename: "{app}\xianyu-tray.exe"; Description: "启动菜单栏控制器"; Flags: nowait postinstall skipifsilent runasoriginaluser
|
||||
|
||||
[UninstallRun]
|
||||
Filename: "{sys}\sc.exe"; Parameters: "stop YdisksXianyuHelper"; Flags: runhidden waituntilterminated
|
||||
Filename: "{sys}\sc.exe"; Parameters: "delete YdisksXianyuHelper"; Flags: runhidden waituntilterminated
|
||||
Filename: "{sys}\WindowsPowerShell\v1.0\powershell.exe"; Parameters: "-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -File ""{app}\service-control.ps1"" -Mode uninstall -TrayPath ""{app}\xianyu-tray.exe"""; Flags: runhidden waituntilterminated
|
||||
|
||||
[Code]
|
||||
function PrepareToInstall(var NeedsRestart: Boolean): String;
|
||||
var
|
||||
ResultCode: Integer;
|
||||
begin
|
||||
Result := '';
|
||||
ExtractTemporaryFile('service-control.ps1');
|
||||
if not Exec(
|
||||
ExpandConstant('{sys}\WindowsPowerShell\v1.0\powershell.exe'),
|
||||
'-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "' +
|
||||
ExpandConstant('{tmp}\service-control.ps1') + '" -Mode stop -TrayPath "' +
|
||||
ExpandConstant('{app}\xianyu-tray.exe') + '"',
|
||||
'', SW_HIDE, ewWaitUntilTerminated, ResultCode)
|
||||
then
|
||||
Result := '无法执行旧服务停止脚本。'
|
||||
else if ResultCode <> 0 then
|
||||
Result := '旧版后台服务停止失败,错误码:' + IntToStr(ResultCode) + '。';
|
||||
end;
|
||||
@@ -0,0 +1,134 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateSet('stop', 'install', 'uninstall')]
|
||||
[string]$Mode,
|
||||
|
||||
[string]$ServiceName = 'YdisksXianyuHelper',
|
||||
[string]$ExePath = '',
|
||||
[string]$TrayPath = '',
|
||||
[string]$WorkDir = '',
|
||||
[string]$RuntimeRoot = ''
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function Get-InstalledService {
|
||||
Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
function Stop-InstalledService {
|
||||
$service = Get-InstalledService
|
||||
if ($null -eq $service) {
|
||||
return
|
||||
}
|
||||
if ($service.Status -ne [System.ServiceProcess.ServiceControllerStatus]::Stopped) {
|
||||
Stop-Service -Name $ServiceName -ErrorAction Stop
|
||||
$service.WaitForStatus(
|
||||
[System.ServiceProcess.ServiceControllerStatus]::Stopped,
|
||||
[TimeSpan]::FromSeconds(30)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function Stop-InstalledTray {
|
||||
if ([string]::IsNullOrWhiteSpace($TrayPath)) {
|
||||
return
|
||||
}
|
||||
$normalizedTrayPath = [IO.Path]::GetFullPath($TrayPath)
|
||||
Get-Process -Name 'xianyu-tray' -ErrorAction SilentlyContinue | ForEach-Object {
|
||||
$processPath = $null
|
||||
try {
|
||||
$processPath = $_.Path
|
||||
} catch {
|
||||
$processPath = $null
|
||||
}
|
||||
if (-not [string]::IsNullOrWhiteSpace($processPath) -and
|
||||
[StringComparer]::OrdinalIgnoreCase.Equals(
|
||||
[IO.Path]::GetFullPath($processPath),
|
||||
$normalizedTrayPath
|
||||
)) {
|
||||
Stop-Process -Id $_.Id -Force -ErrorAction Stop
|
||||
if (-not $_.WaitForExit(10000)) {
|
||||
throw "等待旧托盘进程退出超时: $($_.Id)"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Stop-InstalledComponents {
|
||||
Stop-InstalledTray
|
||||
Stop-InstalledService
|
||||
}
|
||||
|
||||
function Invoke-ScChecked {
|
||||
param([Parameter(ValueFromRemainingArguments = $true)][string[]]$Arguments)
|
||||
|
||||
$output = & "$env:SystemRoot\System32\sc.exe" @Arguments 2>&1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "sc.exe $($Arguments -join ' ') 失败 ($LASTEXITCODE): $($output -join ' ')"
|
||||
}
|
||||
}
|
||||
|
||||
function Grant-InteractiveUserServiceControl {
|
||||
# IU(INTERACTIVE)只包含当前交互式登录会话。授予的 LCRPWP 分别是
|
||||
# 查询状态、启动和停止;不包含修改配置、修改 ACL 或删除服务。
|
||||
$controlAce = '(A;;LCRPWP;;;IU)'
|
||||
$output = & "$env:SystemRoot\System32\sc.exe" sdshow $ServiceName 2>&1
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "读取服务安全描述符失败 ($LASTEXITCODE): $($output -join ' ')"
|
||||
}
|
||||
$sddl = $output |
|
||||
ForEach-Object { $_.ToString().Trim() } |
|
||||
Where-Object { $_ -like 'D:*' } |
|
||||
Select-Object -First 1
|
||||
if ([string]::IsNullOrWhiteSpace($sddl)) {
|
||||
throw '服务安全描述符中没有找到 DACL'
|
||||
}
|
||||
if ($sddl.Contains($controlAce)) {
|
||||
return
|
||||
}
|
||||
|
||||
$saclIndex = $sddl.IndexOf('S:')
|
||||
if ($saclIndex -ge 0) {
|
||||
$updatedSddl = $sddl.Insert($saclIndex, $controlAce)
|
||||
} else {
|
||||
$updatedSddl = $sddl + $controlAce
|
||||
}
|
||||
Invoke-ScChecked sdset $ServiceName $updatedSddl
|
||||
}
|
||||
|
||||
switch ($Mode) {
|
||||
'stop' {
|
||||
Stop-InstalledComponents
|
||||
}
|
||||
'install' {
|
||||
if ([string]::IsNullOrWhiteSpace($ExePath) -or
|
||||
[string]::IsNullOrWhiteSpace($WorkDir) -or
|
||||
[string]::IsNullOrWhiteSpace($RuntimeRoot)) {
|
||||
throw '安装服务缺少 ExePath、WorkDir 或 RuntimeRoot'
|
||||
}
|
||||
|
||||
Stop-InstalledComponents
|
||||
$binaryPath = '"{0}" -service -workdir "{1}" -data-key-file "{1}\data-key" -addr 127.0.0.1:59188 -playwright-runtime-root "{2}"' -f `
|
||||
$ExePath, $WorkDir, $RuntimeRoot
|
||||
if ($null -eq (Get-InstalledService)) {
|
||||
Invoke-ScChecked create $ServiceName 'binPath=' $binaryPath 'start=' 'delayed-auto'
|
||||
} else {
|
||||
Invoke-ScChecked config $ServiceName 'binPath=' $binaryPath 'start=' 'delayed-auto'
|
||||
}
|
||||
Invoke-ScChecked description $ServiceName 'Ydisks闲鱼助手后台服务'
|
||||
Grant-InteractiveUserServiceControl
|
||||
|
||||
Start-Service -Name $ServiceName -ErrorAction Stop
|
||||
(Get-Service -Name $ServiceName).WaitForStatus(
|
||||
[System.ServiceProcess.ServiceControllerStatus]::Running,
|
||||
[TimeSpan]::FromSeconds(30)
|
||||
)
|
||||
}
|
||||
'uninstall' {
|
||||
Stop-InstalledComponents
|
||||
if ($null -ne (Get-InstalledService)) {
|
||||
Invoke-ScChecked delete $ServiceName
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user