//一键重启
        private void btnrestart_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("您确定要重启中间件服务器吗?", "询问窗", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                try
                {
                    //MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Red, "正在准备重启中间件服务,请等待...");
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();

                    RunState = HostState.NoOpen;

                    efwplusBaseManager.StartBase();
                    efwplusRouteManager.StartRoute();
                    efwplusWebAPIManager.StartAPI();
                    MongodbManager.StartDB();
                    NginxManager.StartWeb();

                    RunState = HostState.Opened;
                }
                catch { }
            }
        }
Exemple #2
0
        public static void Run(StartType type)
        {
            switch (type)
            {
            case StartType.BaseService:
                mAppHost = new ServiceHost(typeof(BaseService));
                //初始化连接池,默认10分钟清理连接
                ClientLinkPoolCache.Init(true, 200, 30, 600, "wcfserver", 30);

                AppGlobal.AppRootPath = System.Windows.Forms.Application.StartupPath + "\\";
                AppGlobal.appType     = AppType.WCF;
                AppGlobal.IsSaas      = System.Configuration.ConfigurationManager.AppSettings["IsSaas"] == "true" ? true : false;
                AppGlobal.AppStart();


                ClientManage.IsHeartbeat      = HostSettingConfig.GetValue("heartbeat") == "1" ? true : false;
                ClientManage.HeartbeatTime    = Convert.ToInt32(HostSettingConfig.GetValue("heartbeattime"));
                ClientManage.IsMessage        = HostSettingConfig.GetValue("message") == "1" ? true : false;
                ClientManage.MessageTime      = Convert.ToInt32(HostSettingConfig.GetValue("messagetime"));
                ClientManage.IsCompressJson   = HostSettingConfig.GetValue("compress") == "1" ? true : false;
                ClientManage.IsEncryptionJson = HostSettingConfig.GetValue("encryption") == "1" ? true : false;
                ClientManage.IsToken          = HostSettingConfig.GetValue("token") == "1" ? true : false;
                ClientManage.serializeType    = (SerializeType)Convert.ToInt32(HostSettingConfig.GetValue("serializetype"));
                ClientManage.IsOverTime       = HostSettingConfig.GetValue("overtime") == "1" ? true : false;
                ClientManage.OverTime         = Convert.ToInt32(HostSettingConfig.GetValue("overtimetime"));

                ClientManage.StartHost();
                mAppHost.Open();

                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "数据服务启动完成");
                break;

            case StartType.FileService:
                AppGlobal.AppRootPath = System.Windows.Forms.Application.StartupPath + "\\";

                mFileHost = new ServiceHost(typeof(FileService));
                mFileHost.Open();

                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "文件服务启动完成");
                break;

            case StartType.RouterBaseService:
                mRouterHost = new ServiceHost(typeof(RouterBaseService));
                RouterManage.Start();
                mRouterHost.Open();

                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "数据路由服务启动完成");
                break;

            case StartType.RouterFileService:
                mFileRouterHost = new ServiceHost(typeof(RouterFileService));
                mFileRouterHost.Open();

                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "文件路由服务启动完成");
                break;

            case StartType.SuperClient:
                SuperClient.CreateSuperClient();
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "超级客户端启动完成");
                break;

            case StartType.MiddlewareTask:
                MiddlewareTask.StartTask();    //开启定时任务
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "定时任务启动完成");
                break;

            case StartType.PublishService:    //订阅
                PublishServiceManage.InitPublishService();
                PublishSubManager.StartPublish();
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "发布订阅服务完成");
                break;

            case StartType.MongoDB:
                MongodbManager.StartDB();    //开启MongoDB
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "MongoDB启动完成");
                break;

            case StartType.Nginx:
                NginxManager.StartWeb();    //开启Nginx
                MiddlewareLogHelper.WriterLog(LogType.MidLog, true, Color.Blue, "Nginx启动完成");
                break;

            case StartType.KillAllProcess:
                MongodbManager.StopDB();    //停止MongoDB  清理掉所有子进程,因为主进程关闭子进程不关闭的话,占用的端口号一样不会释放
                NginxManager.StopWeb();
                break;
            }
        }
Exemple #3
0
        static string ExecCmd(string m, Dictionary <string, string> a)
        {
            try
            {
                //ProcessWatcher.OnStop();
                switch (m)
                {
                case "startall":
                    ProcessWatcher.OnStop();

                    efwplusHttpManager.StartHttp();
                    MongodbManager.StartDB();
                    NginxManager.StartWeb();

                    efwplusBaseManager.StartBase();
                    efwplusRouteManager.StartRoute();
                    efwplusWebAPIManager.StartAPI();

                    ProcessWatcher.OnStart();
                    break;

                case "quitall":
                    ProcessWatcher.OnStop();

                    efwplusHttpManager.StopHttp();
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();
                    break;

                case "exit":
                    ProcessWatcher.OnStop();

                    efwplusHttpManager.StopHttp();
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();
                    Process.GetCurrentProcess().Kill();
                    break;

                case "restart":
                    ProcessWatcher.OnStop();

                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();

                    Application.Restart();
                    Process.GetCurrentProcess().Kill();
                    //MongodbManager.StartDB();
                    //NginxManager.StartWeb();

                    //efwplusBaseManager.StartBase();
                    //efwplusRouteManager.StartRoute();
                    //efwplusWebAPIManager.StartAPI();

                    break;

                case "restartbase":
                    efwplusBaseManager.StopBase();
                    efwplusBaseManager.StartBase();
                    break;

                case "restartroute":
                    efwplusRouteManager.StopRoute();
                    efwplusRouteManager.StartRoute();
                    break;

                case "restartwebapi":
                    efwplusWebAPIManager.StopAPI();
                    efwplusWebAPIManager.StartAPI();
                    break;

                case "restartmongodb":
                    MongodbManager.StopDB();
                    MongodbManager.StartDB();
                    break;

                case "restartnginx":
                    NginxManager.StopWeb();
                    NginxManager.StartWeb();
                    break;

                case "upgradeplugin":                                                               //升级插件
                    if (EFWCoreLib.CoreFrame.Init.HostSettingConfig.GetValue("autoupdater") == "1") //是否启动自动升级程序
                    {
                        showmsg("准备升级插件...");
                        ExecCmd("quitall", null);
                        try
                        {
                            efwplusHosting.UpgradeProgram.SetUpPluginUpgrade();
                        }
                        catch (Exception err)
                        {
                            showmsg("升级插件失败!" + err.Message + err.StackTrace);
                            showmsg("程序服务未启动.");
                            //Process.GetCurrentProcess().Kill();
                            //host.RunState = HostState.NoOpen;
                        }

                        showmsg("升级插件完成,正在启动服务...");
                        ExecCmd("startall", null);
                    }
                    else
                    {
                        showmsg("自动升级插件没有开启!");
                    }
                    break;
                }
                //ProcessWatcher.OnStart();
                return("succeed");
            }
            catch (Exception e)
            {
                showmsg(e.Message + e.StackTrace);
                return(e.Message);
            }
        }
Exemple #4
0
        static string ExecCmd(string m, Dictionary <string, string> a)
        {
            try
            {
                switch (m)
                {
                case "startall":
                    efwplusHttpManager.StartHttp();
                    MongodbManager.StartDB();
                    NginxManager.StartWeb();
                    //先启动mongodb,因为efwplusBaseManager启动时有访问mongodb数据
                    efwplusBaseManager.StartBase();
                    efwplusRouteManager.StartRoute();
                    efwplusWebAPIManager.StartAPI();
                    break;

                case "quitall":
                    efwplusHttpManager.StopHttp();
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();
                    break;

                case "exit":
                    efwplusHttpManager.StopHttp();
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();
                    Environment.Exit(0);
                    break;

                case "restart":
                    efwplusBaseManager.StopBase();
                    efwplusRouteManager.StopRoute();
                    efwplusWebAPIManager.StopAPI();
                    MongodbManager.StopDB();
                    NginxManager.StopWeb();

                    MongodbManager.StartDB();
                    NginxManager.StartWeb();

                    efwplusBaseManager.StartBase();
                    efwplusRouteManager.StartRoute();
                    efwplusWebAPIManager.StartAPI();
                    break;

                case "restartbase":
                    efwplusBaseManager.StopBase();
                    efwplusBaseManager.StartBase();
                    break;

                case "restartroute":
                    efwplusRouteManager.StopRoute();
                    efwplusRouteManager.StartRoute();
                    break;

                case "restartwebapi":
                    efwplusWebAPIManager.StopAPI();
                    efwplusWebAPIManager.StartAPI();
                    break;

                case "restartmongodb":
                    efwplusWebAPIManager.StopAPI();
                    efwplusWebAPIManager.StartAPI();
                    break;

                case "restartnginx":
                    efwplusWebAPIManager.StopAPI();
                    efwplusWebAPIManager.StartAPI();
                    break;
                }

                return("succeed");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }