|
@@ -15,13 +15,10 @@ namespace WingCloudServer
|
|
|
class Program
|
|
|
{
|
|
|
private static IServiceContainer _rpcServiceContainer;
|
|
|
- private static HttpListener _httpListener;
|
|
|
- private static bool _stopHttpListener = false;
|
|
|
static void Main(string[] args)
|
|
|
{
|
|
|
var logEngine = new ServerLoggerEngine();
|
|
|
Logger.RegisterEngine(logEngine);
|
|
|
- StartWatch();
|
|
|
while (!StartServer())
|
|
|
{
|
|
|
Console.WriteLine("The server is abnormal,wait 5 second will to reboot server!");
|
|
@@ -29,65 +26,6 @@ namespace WingCloudServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static void StartWatch()
|
|
|
- {
|
|
|
- _httpListener = new HttpListener();
|
|
|
- _httpListener.Prefixes.Add("http://*:8000/");
|
|
|
- _httpListener.Start();
|
|
|
- _stopHttpListener = false;
|
|
|
- Console.WriteLine("Server watch started.");
|
|
|
- LoopingWatch();
|
|
|
- }
|
|
|
-
|
|
|
- private static void LoopingWatch()
|
|
|
- {
|
|
|
- if (!_stopHttpListener)
|
|
|
- {
|
|
|
- _httpListener.BeginGetContext(new AsyncCallback(GetContextCallBack), _httpListener);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static void GetContextCallBack(IAsyncResult ar)
|
|
|
- {
|
|
|
- if (!_stopHttpListener)
|
|
|
- {
|
|
|
- HttpListener listener = (HttpListener)ar.AsyncState;
|
|
|
- HttpListenerContext context = listener.EndGetContext(ar);
|
|
|
- listener.BeginGetContext(new AsyncCallback(GetContextCallBack), listener);
|
|
|
- if (context.Request.QueryString.Get("action") == "exit")
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- var outputBuffer1 = Encoding.UTF8.GetBytes("stop server start");
|
|
|
- context.Response.OutputStream.Write(outputBuffer1, 0, outputBuffer1.Length);
|
|
|
- _stopHttpListener = true;
|
|
|
- _rpcServiceContainer.StopService();
|
|
|
- context.Response.Close();
|
|
|
- _httpListener.Stop();
|
|
|
- var proList = new List<Process>();
|
|
|
- //关闭短信服务
|
|
|
- ProcessStarter.StopTool("Sms.Tool");
|
|
|
- //关闭静态服务器
|
|
|
- ProcessStarter.StopTool("GoStaticSev");
|
|
|
- //关闭mongodb服务器
|
|
|
- ProcessStarter.StopTool("mongod");
|
|
|
- Console.WriteLine("Start exit app");
|
|
|
- Process.GetProcessById(Process.GetCurrentProcess().Id).Kill();
|
|
|
- Environment.Exit(0);
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- Logger.WriteLineError($"error:{ex}");
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
- var outputBuffer = Encoding.UTF8.GetBytes("unauthorized access");
|
|
|
- context.Response.OutputStream.Write(outputBuffer, 0, outputBuffer.Length);
|
|
|
- context.Response.ContentLength64 = outputBuffer.Length;
|
|
|
- context.Response.Close();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private static bool StartServer()
|
|
|
{
|
|
|
try
|