Skip to content

Commit ff4f5e4

Browse files
Ticket #109 : Can deploy EventMeshServer as a windows service
1 parent 70d73c9 commit ff4f5e4

8 files changed

Lines changed: 26 additions & 31 deletions

File tree

default.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ task publishDocker {
6161
}
6262

6363
task publishEventMeshService {
64-
exec { dotnet publish $source_dir\EventMesh\FaasNet.EventMesh.Service\FaasNet.EventMesh.Service.csproj -c Release -o $result_dir\eventMeshService }
64+
exec { dotnet publish $source_dir\EventMesh\FaasNet.EventMesh.Service\FaasNet.EventMesh.Service.csproj -c $config -o $result_dir\eventMeshService }
6565
}
6666

6767
task deployEventMeshService {
68-
exec { sc.exe create "EventMesh Service" binpath="$result_dir\eventMeshService\FaasNet.EventMesh.Service.exe" }
68+
exec { sc.exe create "EventMesh Service" binpath="$result_dir\eventMeshService\FaasNet.EventMesh.Service.exe --contentRoot $result_dir\eventMeshService" }
6969
}
7070

7171
# Pack

src/EventMesh/FaasNet.EventMesh.Seed.RocksDB/SubscriptionStore.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using FaasNet.EventMesh.Seed.Stores;
22
using Microsoft.Extensions.Options;
33
using RocksDbSharp;
4+
using System;
45
using System.IO;
56
using System.Reflection;
67
using System.Threading;
@@ -65,8 +66,8 @@ private string GetSubscriptionFolderPath()
6566

6667
private string GetPath()
6768
{
68-
if (string.IsNullOrWhiteSpace(_options.SubPath)) return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "storage");
69-
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), _options.SubPath, "storage");
69+
if (string.IsNullOrWhiteSpace(_options.SubPath)) return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "storage");
70+
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _options.SubPath, "storage");
7071
}
7172

7273
private static string BuildKey(string jobId, string topic)

src/EventMesh/FaasNet.EventMesh.Service/FaasNet.EventMesh.Service.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
44
<TargetFramework>net6.0</TargetFramework>
5-
<PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
5+
<ImplicitUsings>true</ImplicitUsings>
6+
<PublishSingleFile>true</PublishSingleFile>
67
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
78
<PlatformTarget>x64</PlatformTarget>
89
</PropertyGroup>
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
using FaasNet.Common;
2-
using Microsoft.Extensions.Configuration;
3-
using Microsoft.Extensions.DependencyInjection;
4-
using Microsoft.Extensions.Hosting;
2+
using FaasNet.EventMesh.Service;
53

6-
namespace FaasNet.EventMesh.Service
7-
{
8-
internal class Program
9-
{
10-
public static void Main(string[] args) { }
11-
12-
public static IHostBuilder CreateHostBuilder(string[] args) =>
13-
Host.CreateDefaultBuilder(args)
4+
using IHost host = Host.CreateDefaultBuilder(args)
145
.UseWindowsService(o =>
156
{
167
o.ServiceName = "EventMesh Service";
@@ -21,10 +12,12 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
2112
})
2213
.ConfigureServices((hostContext, services) =>
2314
{
24-
var options = hostContext.Configuration.GetValue<EventMeshServerOptions>("eventmesh");
15+
var options = hostContext.Configuration.Get<EventMeshServerOptions>();
2516
services.AddEventMeshServer(consensusNodeCallback: o => o.Port = options.Port)
26-
.UseRocksDB(o => { o.SubPath = $"node{options.Port}"; });
17+
.UseRocksDB(o =>
18+
{
19+
o.SubPath = $"node{options.Port}";
20+
});
2721
services.AddHostedService<EventMeshServerWorker>();
28-
});
29-
}
30-
}
22+
}).Build();
23+
await host.RunAsync();
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
2-
"eventmesh": {
3-
"port": 4000
4-
}
2+
"Port": 4000
53
}

src/RaftConsensus/FaasNet.RaftConsensus.RocksDB/RockDBNodeStateStore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
using FaasNet.RaftConsensus.Core.Stores;
33
using Microsoft.Extensions.Options;
44
using RocksDbSharp;
5+
using System;
56
using System.Collections.Generic;
67
using System.IO;
78
using System.Linq;
8-
using System.Reflection;
99
using System.Text;
1010
using System.Text.Json;
1111
using System.Threading;
@@ -190,8 +190,8 @@ private string GetFolderPathByTypeVersion(string type)
190190

191191
private string GetPath()
192192
{
193-
if(string.IsNullOrWhiteSpace(_options.SubPath)) return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "storage");
194-
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), _options.SubPath, "storage");
193+
if(string.IsNullOrWhiteSpace(_options.SubPath)) return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "storage");
194+
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _options.SubPath, "storage");
195195
}
196196
}
197197
}

src/RaftConsensus/FaasNet.RaftConsensus.RocksDB/RocksDBLogStore.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using FaasNet.RaftConsensus.Core.Stores;
33
using Microsoft.Extensions.Options;
44
using RocksDbSharp;
5+
using System;
56
using System.IO;
67
using System.Reflection;
78
using System.Text.Json;
@@ -61,8 +62,8 @@ private string GetDirectoryLogLatestVersion()
6162

6263
private string GetPath()
6364
{
64-
if (string.IsNullOrWhiteSpace(_options.SubPath)) return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "storage");
65-
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), _options.SubPath, "storage");
65+
if (string.IsNullOrWhiteSpace(_options.SubPath)) return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "storage");
66+
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _options.SubPath, "storage");
6667
}
6768

6869
private DbOptions BuildOptions()

src/RaftConsensus/FaasNet.RaftConsensus.RocksDB/RocksDBPeerInfoStore.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using FaasNet.RaftConsensus.Core.Stores;
33
using Microsoft.Extensions.Options;
44
using RocksDbSharp;
5+
using System;
56
using System.Collections.Generic;
67
using System.IO;
78
using System.Reflection;
@@ -80,8 +81,8 @@ private string GetFolderPeerInfo()
8081

8182
private string GetPath()
8283
{
83-
if (string.IsNullOrWhiteSpace(_options.SubPath)) return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "storage");
84-
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), _options.SubPath, "storage");
84+
if (string.IsNullOrWhiteSpace(_options.SubPath)) return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "storage");
85+
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _options.SubPath, "storage");
8586
}
8687
}
8788
}

0 commit comments

Comments
 (0)