新增纯netcore的星尘代理,用于Linux;

StarAgent使用AgentService后,无法在Linux下使用;
This commit is contained in:
大石头 2020-03-22 23:32:01 +08:00
parent 5c5685ab9b
commit 37e3b97f93
5 changed files with 129 additions and 1 deletions

1
.gitignore vendored
View File

@ -32,3 +32,4 @@ bld/
/Stardust.Data/Nodes/Config
/Stardust.Server/Properties
/Stardust.Web/Properties
/BinClient2

View File

@ -112,7 +112,7 @@ namespace StarAgent
_Client = null;
}
private static void CheckUpgrade(StarClient client, String channel)
private void CheckUpgrade(StarClient client, String channel)
{
// 检查更新
var ur = client.Upgrade(channel).Result;
@ -123,8 +123,11 @@ namespace StarAgent
// 强制更新时,马上重启
if (rs && ur.Force)
{
StopWork("Upgrade");
var p = Process.GetCurrentProcess();
p.Close();
p.Kill(true);
}
}
}

89
StarAgent2/Program.cs Normal file
View File

@ -0,0 +1,89 @@
using System;
using System.Diagnostics;
using System.Threading;
using NewLife;
using NewLife.Log;
using NewLife.Threading;
using Stardust;
namespace StarAgent2
{
class Program
{
static void Main(string[] args)
{
XTrace.UseConsole();
var set = StarAgent.Setting.Current;
StartClient();
// 应用服务管理
_Manager = new ServiceManager
{
Services = set.Services,
Log = XTrace.Log,
};
_Manager.Start();
Thread.Sleep(-1);
}
private static TimerX _timer;
private static StarClient _Client;
private static ServiceManager _Manager;
private static void StartClient()
{
var set = StarAgent.Setting.Current;
var server = set.Server;
if (server.IsNullOrEmpty()) return;
XTrace.WriteLine("初始化服务端地址:{0}", server);
var client = new StarClient(server)
{
Code = Environment.MachineName,
Secret = Environment.MachineName,
Log = XTrace.Log,
};
// 可能需要多次尝试
_timer = new TimerX(TryConnectServer, client, 0, 5_000) { Async = true };
_Client = client;
}
private static void TryConnectServer(Object state)
{
var client = state as StarClient;
var set = StarAgent.Setting.Current;
//Task.Run(client.Login).ContinueWith(t => CheckUpgrade(client, set.Channel));
client.Login().Wait();
CheckUpgrade(client, set.Channel);
// 登录成功,销毁定时器
//TimerX.Current.Period = 0;
_timer.TryDispose();
_timer = null;
}
private static void CheckUpgrade(StarClient client, String channel)
{
// 检查更新
var ur = client.Upgrade(channel).Result;
if (ur != null)
{
var rs = client.ProcessUpgrade(ur);
// 强制更新时,马上重启
if (rs && ur.Force)
{
var p = Process.GetCurrentProcess();
p.Close();
p.Kill(true);
}
}
}
}
}

View File

@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyTitle>星尘代理</AssemblyTitle>
<Description>星尘,分布式资源调度,客户端代理部署于每一台机器节点,接受服务端命令,获取目标应用包并拉起进程。</Description>
<Company>新生命开发团队</Company>
<Copyright>©2002-2020 NewLife</Copyright>
<Version>1.0.2020.0322</Version>
<FileVersion>1.0.2020.0322</FileVersion>
<AssemblyVersion>1.0.*</AssemblyVersion>
<Deterministic>false</Deterministic>
<OutputPath>..\BinClient2</OutputPath>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\StarAgent\Setting.cs" Link="Setting.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Stardust\Stardust.csproj" />
</ItemGroup>
</Project>

View File

@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClientTest", "ClientTest\ClientTest.csproj", "{7DE10A4D-1749-4474-A6B2-F52CA8462813}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StarAgent2", "StarAgent2\StarAgent2.csproj", "{8F868ED3-102A-446C-AC1B-D635FF7EA772}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -61,6 +63,10 @@ Global
{7DE10A4D-1749-4474-A6B2-F52CA8462813}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DE10A4D-1749-4474-A6B2-F52CA8462813}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7DE10A4D-1749-4474-A6B2-F52CA8462813}.Release|Any CPU.Build.0 = Release|Any CPU
{8F868ED3-102A-446C-AC1B-D635FF7EA772}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F868ED3-102A-446C-AC1B-D635FF7EA772}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F868ED3-102A-446C-AC1B-D635FF7EA772}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F868ED3-102A-446C-AC1B-D635FF7EA772}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE