-
Notifications
You must be signed in to change notification settings - Fork 0
/
6. SignalNginx.cs
51 lines (44 loc) · 1.88 KB
/
6. SignalNginx.cs
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
44
45
46
47
48
49
50
51
using BSS.Logging;
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace CertBotHelper
{
internal static partial class Program
{
private static Boolean SignalNginxReload(ref Configuration configuration)
{
Log.FastLog("Signaling as: " + Environment.UserName, LogSeverity.Verbose, "Signal");
Process nginx = new();
nginx.StartInfo.FileName = configuration.NginxPath;
nginx.StartInfo.Arguments = "-s reload";
nginx.StartInfo.WorkingDirectory = Directory.GetParent(configuration.NginxPath).FullName;
nginx.StartInfo.CreateNoWindow = true;
nginx.StartInfo.UseShellExecute = false;
nginx.StartInfo.RedirectStandardError = true;
try
{
nginx.Start();
Log.FastLog($"Send reload signal to '{configuration.NginxPath}'", LogSeverity.Info, "Signal-NGINX");
String errOut = nginx.StandardError.ReadToEnd();
nginx.WaitForExit();
nginx.Dispose();
if (errOut != "")
{
Log.FastLog($"An error occurred trying signal a reload to nginx, error was:'\n{errOut}", LogSeverity.Error, "Signal-NGINX");
return false;
}
}
catch (Exception exception)
{
Log.FastLog($"An error occurred trying to start '{configuration.NginxPath} -s reload'\n{exception.Message}", LogSeverity.Error, "Signal-NGINX");
nginx.Dispose();
return false;
}
Log.FastLog($"Successfully signaled a reload to nginx (errOut was empty)", LogSeverity.Info, "Signal-NGINX");
return true;
}
}
}