Skip to content

Commit faacd30

Browse files
committed
[server] 크레마 서비스 등록 시 http 포트를 지정할 수 있는 기능 추가
사용 방법 cremaserver.exe service install <repo path> --http-port 5104
1 parent 51240ca commit faacd30

6 files changed

Lines changed: 32 additions & 6 deletions

File tree

common/Ntreev.Crema.ServiceModel/AddressUtility.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,10 @@ public static string GetIPAddress(string address)
6666
var match = Regex.Match(address, "(?<name>[^:]*)[:]*(?<port>\\d*)", RegexOptions.ExplicitCapture);
6767
return match.Groups["name"].Value;
6868
}
69+
70+
public static int GetDefaultHttpPort(int port)
71+
{
72+
return port + 100;
73+
}
6974
}
7075
}

server/Ntreev.Crema.ServiceHosts/CremaService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public int Port
134134
public int? HttpPort
135135
{
136136
get => this.httpPort;
137-
set => this.httpPort = value ?? this.port + 100;
137+
set => this.httpPort = value ?? AddressUtility.GetDefaultHttpPort(this.port);
138138
}
139139

140140
public ICremaHost CremaHost

server/Ntreev.Crema.WindowsServiceHost/CremaService.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ protected override void OnStart(string[] args)
6060
var baseArgs = Environment.GetCommandLineArgs();
6161
var path = baseArgs[1];
6262
var port = int.Parse(baseArgs[2]);
63+
var httpPort = int.Parse(baseArgs[3]);
6364

6465
this.cremaService = new CremaService()
6566
{
6667
BasePath = path,
6768
Port = port,
69+
HttpPort = httpPort
6870
};
6971

7072
CremaLog.Debug("service base path : {0}", path);
@@ -79,6 +81,7 @@ protected override void OnStart(string[] args)
7981
{
8082
BasePath = this.cremaService.BasePath,
8183
Port = this.cremaService.Port,
84+
HttpPort = this.cremaService.HttpPort.Value,
8285
RepositoryModule = this.cremaService.RepositoryModule,
8386
RepositoryName = this.cremaService.RepositoryName,
8487
};
@@ -94,6 +97,7 @@ protected override void OnStart(string[] args)
9497
CremaLog.Debug("new settings");
9598
CremaLog.Debug("service base path : {0}", settings.BasePath);
9699
CremaLog.Debug("service port : {0}", settings.Port);
100+
CremaLog.Debug("service http port : {0}", settings.HttpPort);
97101
CremaLog.Debug("service repo name : {0}", settings.RepositoryName);
98102
CremaLog.Debug("service repo module : {0}", settings.RepositoryModule);
99103
CremaLog.Debug("=========================================================");

server/Ntreev.Crema.WindowsServiceHost/ServiceCommand.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ServiceCommand()
4444
}
4545

4646
[CommandMethod]
47-
[CommandMethodProperty(nameof(Port), nameof(ServiceName), nameof(DisplayName), nameof(Comment))]
47+
[CommandMethodProperty(nameof(Port), nameof(ServiceName), nameof(DisplayName), nameof(Comment), nameof(HttpPort))]
4848
public void Install(string path)
4949
{
5050
var basePath = new DirectoryInfo(path).FullName;
@@ -91,16 +91,23 @@ public string DisplayName
9191
set;
9292
}
9393

94+
[CommandProperty]
95+
public int? HttpPort {
96+
get;
97+
set;
98+
}
99+
94100
public override bool IsEnabled => Environment.OSVersion.Platform == PlatformID.Win32NT;
95101

96102
private void InstallService(string exeFilename, string basePath)
97103
{
98104
var pathArg = string.Format("/PATH={0}", basePath);
99105
var portArg = string.Format("/PORT={0}", this.Port);
106+
var httpPortArgs = string.Format("/HTTPPORT={0}", this.HttpPort ?? AddressUtility.GetDefaultHttpPort(this.Port));
100107
var displayNameArg = string.Format("/DisplayName={0}", this.DisplayName);
101108
var serviceNameArg = string.Format("/ServiceName={0}", this.ServiceName);
102109
var comment = string.Format("/Comment={0}", this.Comment);
103-
var commandLineOptions = new string[] { pathArg, portArg, displayNameArg, serviceNameArg, comment };
110+
var commandLineOptions = new string[] { pathArg, portArg, displayNameArg, serviceNameArg, comment, httpPortArgs };
104111
var installer = new AssemblyInstaller(exeFilename, commandLineOptions);
105112

106113
installer.Install(null);
@@ -111,9 +118,10 @@ private void UninstallService(string exeFilename, string basePath)
111118
{
112119
var pathArg = string.Format("/PATH={0}", basePath);
113120
var portArg = string.Format("/PORT={0}", this.Port);
121+
var httpPortArgs = string.Format("/HTTPPORT={0}", this.HttpPort ?? AddressUtility.GetDefaultHttpPort(this.Port));
114122
var displayNameArg = string.Format("/DisplayName={0}", this.DisplayName);
115123
var serviceNameArg = string.Format("/ServiceName={0}", this.ServiceName);
116-
var commandLineOptions = new string[] { pathArg, portArg, displayNameArg, serviceNameArg };
124+
var commandLineOptions = new string[] { pathArg, portArg, displayNameArg, serviceNameArg, httpPortArgs };
117125
var installer = new AssemblyInstaller(exeFilename, commandLineOptions)
118126
{
119127
UseNewContext = true

server/Ntreev.Crema.WindowsServiceHost/Settings.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,12 @@ public string RepositoryModule
5555
get;
5656
set;
5757
}
58+
59+
[CommandProperty]
60+
public int HttpPort
61+
{
62+
get;
63+
set;
64+
}
5865
}
5966
}

server/Ntreev.Crema.WindowsServiceHost/WindowsServiceInstaller.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ protected override void OnBeforeInstall(System.Collections.IDictionary savedStat
5353

5454
var path = this.Context.Parameters["PATH"];
5555
var port = this.Context.Parameters["PORT"];
56+
var httpPort = this.Context.Parameters["HTTPPORT"];
5657
var filename = this.Context.Parameters["assemblypath"];
5758

58-
this.Context.Parameters["assemblypath"] = $"{filename.WrapQuot()} {path.WrapQuot()} {port}";
59+
this.Context.Parameters["assemblypath"] = $"{filename.WrapQuot()} {path.WrapQuot()} {port} {httpPort}";
5960

6061
this.serviceInstaller.Description = this.Context.Parameters["Comment"];
6162
this.serviceInstaller.DisplayName = this.Context.Parameters["DisplayName"];
@@ -96,9 +97,10 @@ protected override void OnBeforeUninstall(System.Collections.IDictionary savedSt
9697

9798
var path = this.Context.Parameters["PATH"];
9899
var port = this.Context.Parameters["PORT"];
100+
var httpPort = this.Context.Parameters["HTTPPORT"];
99101
var filename = this.Context.Parameters["assemblypath"];
100102

101-
this.Context.Parameters["assemblypath"] = $"{filename.WrapQuot()} {path.WrapQuot()} {port}";
103+
this.Context.Parameters["assemblypath"] = $"{filename.WrapQuot()} {path.WrapQuot()} {port} {httpPort}";
102104

103105
this.serviceInstaller.Description = this.Context.Parameters["Comment"];
104106
this.serviceInstaller.DisplayName = this.Context.Parameters["DisplayName"];

0 commit comments

Comments
 (0)