优化本地安装,现在的流程过于复杂

This commit is contained in:
智能石头 2020-12-02 19:40:37 +08:00
parent 08443440e1
commit 80b243946a
5 changed files with 49 additions and 46 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using NewLife;
using NewLife.Agent;
@ -69,10 +70,18 @@ namespace StarAgent
if (delay > 0) Thread.Sleep(delay * 1000);
// 如果要杀的是自己,则重启服务
if (processId == Process.GetCurrentProcess().Id && !fileName.IsNullOrEmpty())
var args = Environment.CommandLine.Split(" ");
if (processId == Process.GetCurrentProcess().Id && args.Contains("-s"))
{
Host.Restart(Service.ServiceName);
return;
try
{
Host.Restart(Service.ServiceName);
return;
}
catch (Exception ex)
{
XTrace.WriteException(ex);
}
}
try

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
@ -107,6 +106,7 @@ namespace Stardust
// 比目标版本高,不需要安装
if (String.Compare(info.Version, version) >= 0) return true;
if (!info.FileName.IsNullOrEmpty()) info.FileName = info.FileName.TrimEnd(" (deleted)");
if (target.IsNullOrEmpty()) target = Path.GetDirectoryName(info.FileName);
XTrace.WriteLine("StarAgent在用版本 v{0},低于目标版本 v{1}", info.Version, version);
@ -128,16 +128,15 @@ namespace Stardust
// 准备安装,甭管是否能够成功重启,先覆盖了文件再说
{
if (target.IsNullOrEmpty())
{
target = Runtime.Windows ? "C:\\StarAgent" : $"\\home\\{Environment.UserName}";
}
if (target.IsNullOrEmpty()) target = "..\\staragent";
target = target.GetFullPath();
target.EnsureDirectory(false);
XTrace.WriteLine("目标:{0}", target);
var ug = new Upgrade
{
SourceFile = Path.GetFileName(url),
SourceFile = Path.GetFileName(url).GetFullPath(),
DestinationPath = target,
Log = XTrace.Log,
@ -160,10 +159,13 @@ namespace Stardust
Process.GetProcessById(info.ProcessId) :
Process.GetProcesses().FirstOrDefault(e => e.ProcessName == "StarAgent");
// 在Linux中设置执行权限
var fileName = info?.FileName ?? target.CombinePath(Runtime.Linux ? "StarAgent" : "StarAgent.exe");
if (File.Exists(fileName) && Runtime.Linux) Process.Start("chmod", $"+x {fileName}");
// 让对方自己退出
if (info != null)
{
//_client.Invoke<String>("KillAndStart", new { processId = info.ProcessId });
_client.Invoke<String>("KillAndStart", new
{
processId = p.Id,
@ -187,13 +189,14 @@ namespace Stardust
}
}
var fileName = info?.FileName ?? target.CombinePath("StarAgent.exe");
if (File.Exists(fileName))
{
if (Runtime.Linux)
if (info?.Arguments == "-s")
{
Process.Start(fileName, "-restart");
}
else
{
Process.Start("chmod", $"+x {fileName}");
var si = new ProcessStartInfo(fileName, "-run")
{
WorkingDirectory = Path.GetDirectoryName(fileName),
@ -201,22 +204,6 @@ namespace Stardust
};
Process.Start(si);
}
else
{
if (info?.Arguments == "-s")
{
Process.Start(fileName, "-start");
}
else
{
var si = new ProcessStartInfo(fileName, "-run")
{
WorkingDirectory = Path.GetDirectoryName(fileName),
UseShellExecute = true
};
Process.Start(si);
}
}
}
}

View File

@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading;
using NewLife.Log;
using NewLife.Net;
using NewLife.Remoting;
using Stardust;
using XCode.DataAccessLayer;
namespace Test
{
@ -46,18 +42,14 @@ namespace Test
_Server = sc;
}
static void Test2()
{
//DAL.AddConnStr("node", "Data Source=..\\Data\\Node.db", null, "sqlite");
DAL.AddConnStr("mysql", "Server=.;Port=3306;Database=Node;Uid=root;Pwd=root;", null, "mysql");
var dal = DAL.Create("mysql");
var rs = dal.RestoreAll("../data/Node_20200903215342.zip", null);
//Assert.NotNull(rs);
}
static void Test3()
{
//foreach (Environment.SpecialFolder item in Enum.GetValues(typeof(Environment.SpecialFolder)))
//{
// var v = Environment.GetFolderPath(item);
// Console.WriteLine("{0}:\t{1}", item, v);
//}
var client = new LocalStarClient();
client.ProbeAndInstall(null, "1.1");
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>..\Bin\Test\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
</PropertyGroup>
</Project>

View File

@ -7,6 +7,7 @@
<Deterministic>false</Deterministic>
<OutputPath>..\Bin\Test</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
@ -14,8 +15,6 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Stardust.Data\Stardust.Data.csproj" />
<ProjectReference Include="..\Stardust.Server\Stardust.Server.csproj" />
<ProjectReference Include="..\Stardust\Stardust.csproj" />
</ItemGroup>