Return none zero code when job service exit with error

replace fmt.Println/logger.Errorf with logger.Fatal(f)
This commit is contained in:
Steven Zou 2018-05-10 14:44:04 +08:00
parent 3ca439c71a
commit f7bc467c99
2 changed files with 9 additions and 7 deletions

View File

@ -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

View File

@ -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")
}