From f7bc467c99ddd4a08febcb90a4f3cc6edde36c12 Mon Sep 17 00:00:00 2001 From: Steven Zou Date: Thu, 10 May 2018 14:44:04 +0800 Subject: [PATCH] Return none zero code when job service exit with error replace fmt.Println/logger.Errorf with logger.Fatal(f) --- src/jobservice/main.go | 7 ++----- src/jobservice/runtime/bootstrap.go | 9 +++++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/jobservice/main.go b/src/jobservice/main.go index 87e70db92..ef5c673cc 100644 --- a/src/jobservice/main.go +++ b/src/jobservice/main.go @@ -3,7 +3,6 @@ package main import ( "errors" "flag" - "fmt" "github.com/vmware/harbor/src/adminserver/client" "github.com/vmware/harbor/src/jobservice/config" @@ -22,15 +21,13 @@ func main() { //Missing config file if configPath == nil || utils.IsEmptyStr(*configPath) { - fmt.Println("Config file should be specified") flag.Usage() - return + logger.Fatal("Config file should be specified") } //Load configurations if err := config.DefaultConfig.Load(*configPath, true); err != nil { - fmt.Printf("Failed to load configurations with error: %s\n", err) - return + logger.Fatalf("Failed to load configurations with error: %s\n", err) } //Set job context initializer diff --git a/src/jobservice/runtime/bootstrap.go b/src/jobservice/runtime/bootstrap.go index 32fa2fd71..c4f9ccc02 100644 --- a/src/jobservice/runtime/bootstrap.go +++ b/src/jobservice/runtime/bootstrap.go @@ -91,13 +91,14 @@ func (bs *Bootstrap) LoadAndRun() { logSweeper := logger.NewSweeper(ctx, config.GetLogBasePath(), config.GetLogArchivePeriod()) logSweeper.Start() + //To indicate if any errors occurred + var err error //Block here sig := make(chan os.Signal, 1) signal.Notify(sig, os.Interrupt, syscall.SIGTERM, os.Kill) select { case <-sig: - case err := <-rootContext.ErrorChan: - logger.Errorf("Server error:%s\n", err) + case err = <-rootContext.ErrorChan: } //Call cancel to send termination signal to other interested parts. @@ -125,6 +126,10 @@ func (bs *Bootstrap) LoadAndRun() { rootContext.WG.Wait() close <- true + if err != nil { + logger.Fatalf("Server exit with error: %s\n", err) + } + logger.Infof("Server gracefully exit") }