diff --git a/app/mix/cmd_offline/main.go b/app/mix/cmd_offline/main.go index 4d88c72b..2e695296 100644 --- a/app/mix/cmd_offline/main.go +++ b/app/mix/cmd_offline/main.go @@ -116,7 +116,8 @@ func main() { Addr: fmt.Sprintf("%s:%d", GetIp(), cfg.App.Port), Handler: router, } - httpserver.StartHttpServer(srv, cfg.DefaultConfig) + //httpserver.StartHttpServer(srv, cfg.DefaultConfig) + httpserver.StartOfflineHttpServer(srv, cfg.DefaultConfig) } func PrintAndExit(msg string) { diff --git a/etc/mix/mix-prod-offline.yaml b/etc/mix/mix-prod-offline.yaml index 2b0310d6..5d5211db 100644 --- a/etc/mix/mix-prod-offline.yaml +++ b/etc/mix/mix-prod-offline.yaml @@ -142,17 +142,4 @@ elastic_search: uri: "http://172.31.37.67:9200" username: "elastic" password: "Wishpal@2024" - sniff: false - -offline_server: - log: - stdout_enable: true - stdout_level: "trace" - file_enable: true - file_level: "trace" - file_abs_path: "/app/ironfan/log/offline-server/" - - app: - app_name: "offline-server" - ip: "127.0.0.1" - port: 9998 \ No newline at end of file + sniff: false \ No newline at end of file diff --git a/etc/mix/mix-test-offline.yaml b/etc/mix/mix-test-offline.yaml index 33732186..3c8e969a 100644 --- a/etc/mix/mix-test-offline.yaml +++ b/etc/mix/mix-test-offline.yaml @@ -143,16 +143,4 @@ elastic_search: uri: "http://127.0.0.1:9200" username: "elastic" password: "Wishpal@2024" - sniff: false - -offline_server_log: - stdout_enable: true - stdout_level: "trace" - file_enable: true - file_level: "trace" - file_abs_path: "/app/ironfan/log/offline-server/" - -offline_server_app: - app_name: "offline-server" - ip: "127.0.0.1" - port: 9998 \ No newline at end of file + sniff: false \ No newline at end of file diff --git a/library/httpserver/httpserver.go b/library/httpserver/httpserver.go index ee0871bd..a7c86255 100644 --- a/library/httpserver/httpserver.go +++ b/library/httpserver/httpserver.go @@ -40,3 +40,31 @@ func StartHttpServer(srv *http.Server, cfg *configcenter.DefaultConfig) { logger.Info("Server exited") } + +func StartOfflineHttpServer(srv *http.Server, cfg *configcenter.DefaultConfig) { + go func() { + if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { + logger.Fatal("listen: %v", err) + } + }() + + logger.Info("Server %s start at %s", cfg.App.AppName, srv.Addr) + + quit := make(chan os.Signal) + signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) + <-quit + logger.Info("Shutdown Server ...") + + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() + if err := srv.Shutdown(ctx); err != nil { + log.Fatal("Server Shutdown:", err) + } + + select { + case <-ctx.Done(): + logger.Info("timeout of 1 seconds.") + } + + logger.Info("Server exited") +}