fix: initialize private Linux agent config and user service from desktop
This commit is contained in:
1 parent
316292bdfb
commit
e9cf55f597
3 files changed
+20
-1
No files matched your search
@@ -270,6 +270,15 @@ pub fn save_private(path: &Path, data: &[u8]) -> Result<()> {
|
|||||||
let parent = path
|
let parent = path
|
||||||
.parent()
|
.parent()
|
||||||
.context("configuration requires a parent directory")?;
|
.context("configuration requires a parent directory")?;
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
use std::os::unix::fs::DirBuilderExt;
|
||||||
|
std::fs::DirBuilder::new()
|
||||||
|
.recursive(true)
|
||||||
|
.mode(0o700)
|
||||||
|
.create(parent)?;
|
||||||
|
}
|
||||||
|
#[cfg(not(unix))]
|
||||||
std::fs::create_dir_all(parent)?;
|
std::fs::create_dir_all(parent)?;
|
||||||
let temporary = parent.join(format!(
|
let temporary = parent.join(format!(
|
||||||
".ads-{}-{}.tmp",
|
".ads-{}-{}.tmp",
|
||||||
|
|||||||
@@ -203,11 +203,13 @@ public partial class AgentManagementViewModel : ObservableObject, IDisposable
|
|||||||
var args=new List<string>{"--json","--config",ConfigPath,"--server",root.GetProperty("server").GetString()!,"init","--id",root.GetProperty("id").GetString()!,"--name",root.GetProperty("name").GetString()!};
|
var args=new List<string>{"--json","--config",ConfigPath,"--server",root.GetProperty("server").GetString()!,"init","--id",root.GetProperty("id").GetString()!,"--name",root.GetProperty("name").GetString()!};
|
||||||
// Origin is a global CLI option and must precede the subcommand.
|
// Origin is a global CLI option and must precede the subcommand.
|
||||||
if(root.TryGetProperty("connect_address",out var origin)&&origin.ValueKind==JsonValueKind.String)args.InsertRange(5,["--connect-address",origin.GetString()!]);
|
if(root.TryGetProperty("connect_address",out var origin)&&origin.ValueKind==JsonValueKind.String)args.InsertRange(5,["--connect-address",origin.GetString()!]);
|
||||||
|
if(OperatingSystem.IsLinux())Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(ConfigPath))!,UnixFileMode.UserRead|UnixFileMode.UserWrite|UnixFileMode.UserExecute);
|
||||||
var info=ProcessTools.CreateStartInfo(DesktopPaths.ResolveTool(DesktopPaths.FindTool("adsctl"),"adsctl"),args);info.Environment["ADS_AGENT_TOKEN"]=EnrollmentToken;
|
var info=ProcessTools.CreateStartInfo(DesktopPaths.ResolveTool(DesktopPaths.FindTool("adsctl"),"adsctl"),args);info.Environment["ADS_AGENT_TOKEN"]=EnrollmentToken;
|
||||||
var result=await ProcessTools.RunAsync(info,lifetime.Token);if(result.ExitCode!=0)throw new InvalidOperationException(result.Error);
|
var result=await ProcessTools.RunAsync(info,lifetime.Token);if(result.ExitCode!=0)throw new InvalidOperationException(result.Error);
|
||||||
EnrollmentToken="";Notice="本机配置已初始化,可启动后台 Agent 后应用设备配置。";
|
EnrollmentToken="";Notice="本机配置已初始化,可启动后台 Agent 后应用设备配置。";
|
||||||
});
|
});
|
||||||
[RelayCommand(CanExecute=nameof(CanLocal))]private Task StartLocalAsync()=>Guard(async()=>{
|
[RelayCommand(CanExecute=nameof(CanLocal))]private Task StartLocalAsync()=>Guard(async()=>{
|
||||||
|
if(!File.Exists(ConfigPath))throw new InvalidOperationException("请先导入 agent.env 并初始化本机配置,再启动 Agent。");
|
||||||
try { await LocalRequestAsync(new{op="status"});Notice="本机 Agent 已在运行。";return; } catch(InvalidOperationException){}
|
try { await LocalRequestAsync(new{op="status"});Notice="本机 Agent 已在运行。";return; } catch(InvalidOperationException){}
|
||||||
var info=ProcessTools.CreateStartInfo(DesktopPaths.ResolveTool(DesktopPaths.FindTool("ads-agent"),"ads-agent"),["--quiet","--supervise","--config",ConfigPath]);
|
var info=ProcessTools.CreateStartInfo(DesktopPaths.ResolveTool(DesktopPaths.FindTool("ads-agent"),"ads-agent"),["--quiet","--supervise","--config",ConfigPath]);
|
||||||
info.RedirectStandardOutput=false;info.RedirectStandardError=false;
|
info.RedirectStandardOutput=false;info.RedirectStandardError=false;
|
||||||
@@ -215,7 +217,13 @@ public partial class AgentManagementViewModel : ObservableObject, IDisposable
|
|||||||
await Task.Delay(700,lifetime.Token);await RefreshCoreAsync();Notice="后台 Agent 已启动,退出托盘不会停止它。";
|
await Task.Delay(700,lifetime.Token);await RefreshCoreAsync();Notice="后台 Agent 已启动,退出托盘不会停止它。";
|
||||||
});
|
});
|
||||||
[RelayCommand(CanExecute=nameof(CanLocal))]private Task InstallServiceAsync()=>Guard(async()=>{
|
[RelayCommand(CanExecute=nameof(CanLocal))]private Task InstallServiceAsync()=>Guard(async()=>{
|
||||||
if(!OperatingSystem.IsWindows())throw new InvalidOperationException("请在终端运行 adsctl service install;系统级服务可加 --system。");
|
if(OperatingSystem.IsLinux()) {
|
||||||
|
var start=ProcessTools.CreateStartInfo(DesktopPaths.ResolveTool(DesktopPaths.FindTool("adsctl"),"adsctl"),new[]{"--config",ConfigPath,"service","install"});
|
||||||
|
var result=await ProcessTools.RunAsync(start,lifetime.Token);
|
||||||
|
if(result.ExitCode!=0)throw new InvalidOperationException(result.Error);
|
||||||
|
await RefreshCoreAsync();Notice="已安装用户级 systemd 服务;无登录开机运行需启用该用户的 linger。";return;
|
||||||
|
}
|
||||||
|
if(!OperatingSystem.IsWindows())throw new InvalidOperationException("此平台请手动运行 Agent。");
|
||||||
var info=new ProcessStartInfo(DesktopPaths.ResolveTool(DesktopPaths.FindTool("adsctl"),"adsctl")){UseShellExecute=true,Verb="runas",WindowStyle=ProcessWindowStyle.Hidden};
|
var info=new ProcessStartInfo(DesktopPaths.ResolveTool(DesktopPaths.FindTool("adsctl"),"adsctl")){UseShellExecute=true,Verb="runas",WindowStyle=ProcessWindowStyle.Hidden};
|
||||||
foreach(var value in new[]{"--config",ConfigPath,"service","install"})info.ArgumentList.Add(value);
|
foreach(var value in new[]{"--config",ConfigPath,"service","install"})info.ArgumentList.Add(value);
|
||||||
using var process=Process.Start(info) ?? throw new InvalidOperationException("安装命令无法启动。");await process.WaitForExitAsync(lifetime.Token);
|
using var process=Process.Start(info) ?? throw new InvalidOperationException("安装命令无法启动。");await process.WaitForExitAsync(lifetime.Token);
|
||||||
|
|||||||
@@ -120,3 +120,5 @@ v3 增加 `/agents/register`(Agent WSS)、`/agents`(管理员 HTTP/WSS 列
|
|||||||
Windows 排障:本机管理返回拒绝访问时,检查配置目录所有者是否为实际使用管理客户端的用户。管理员权限创建目录可能将所有者设为 Administrators,普通 UAC 桌面进程不能使用这个组访问私有管道。保留原 ACL,将专属配置目录所有者调整为实际用户,再重启 Agent 重建管道。不要向 Everyone 授予管理权限。
|
Windows 排障:本机管理返回拒绝访问时,检查配置目录所有者是否为实际使用管理客户端的用户。管理员权限创建目录可能将所有者设为 Administrators,普通 UAC 桌面进程不能使用这个组访问私有管道。保留原 ACL,将专属配置目录所有者调整为实际用户,再重启 Agent 重建管道。不要向 Everyone 授予管理权限。
|
||||||
|
|
||||||
设备发现:两套客户端点击“发现 ADB 设备”,查询所选 Agent 主机的 ADB server,显示已添加、未添加、未授权/离线状态。选择在线且未添加的条目会填入添加表单,确认后添加;不自动暴露所有新插入的手机。CLI 使用 `adsctl devices discover`,远程可加 `--agent ID`。须先启动该主机的 ADB server;SYSTEM Agent 也通过配置的 TCP ADB server 地址查询。此能力需要控制中心与 Agent 更新到支持 devices_discover 的版本。
|
设备发现:两套客户端点击“发现 ADB 设备”,查询所选 Agent 主机的 ADB server,显示已添加、未添加、未授权/离线状态。选择在线且未添加的条目会填入添加表单,确认后添加;不自动暴露所有新插入的手机。CLI 使用 `adsctl devices discover`,远程可加 `--agent ID`。须先启动该主机的 ADB server;SYSTEM Agent 也通过配置的 TCP ADB server 地址查询。此能力需要控制中心与 Agent 更新到支持 devices_discover 的版本。
|
||||||
|
|
||||||
|
Linux 本机 Agent 初始没有配置时,先导入 agent.env 并初始化,再启动。桌面现在支持直接安装用户级 systemd 服务;无登录运行需管理员启用该用户 linger。新建私有配置目录使用 0700,以避免 Ubuntu 常见 umask 0002 创建组可写目录而被拒绝。已有目录不自动放宽权限。
|
||||||
Reference in new issue
Block a user