forked from redis-windows/redis-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
43 lines (35 loc) · 1.22 KB
/
Program.cs
File metadata and controls
43 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//author: https://www.zhihu.com/question/424272611/answer/2611312760
using System.Diagnostics;
using System.ServiceProcess;
namespace RedisService
{
class Program
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:验证平台兼容性", Justification = "<挂起>")]
static void Main()
{
ServiceBase.Run(new RedisService());
}
}
partial class RedisService : ServiceBase
{
private Process? process = new();
protected override void OnStart(string[] args)
{
var basePath = Path.Combine(AppContext.BaseDirectory).Replace("\\", "/");
var diskSymbol = basePath[..basePath.IndexOf(":")];
var confPath = basePath.Replace(diskSymbol + ":", "/cygdrive/" + diskSymbol);
ProcessStartInfo processStartInfo = new(basePath + "redis-server.exe", confPath + "redis.conf");
processStartInfo.WorkingDirectory = basePath;
process = Process.Start(processStartInfo);
}
protected override void OnStop()
{
if (process != null)
{
process.Kill();
process.Dispose();
}
}
}
}