Exemplo n.º 1
0
Arquivo: main.go Projeto: unikk/cuto
func realMain(args *arguments) int {
	if args.v {
		showVersion()
		return rc_OK
	}
	message.ServantVersion = Version

	// システム変数のセット
	message.AddSysValue("ROOT", "", util.GetRootPath())

	config.ReadConfig(args.configPath)
	if err := config.Servant.DetectError(); err != nil {
		console.Display("CTS005E", err)
		return rc_error
	}

	// ログ出力開始
	if err := log.Init(config.Servant.Dir.LogDir,
		"servant",
		strconv.Itoa(config.Servant.Sys.BindPort),
		config.Servant.Log.OutputLevel,
		config.Servant.Log.MaxSizeKB,
		config.Servant.Log.MaxGeneration,
		config.Servant.Log.TimeoutSec); err != nil {
		console.Display("CTS023E", err)
		return rc_error
	}
	defer log.Term()
	console.Display("CTS001I", os.Getpid(), Version)

	// メイン処理開始
	exitCode, err := Run()

	if err != nil {
		log.Error(err)
		exitCode = rc_error
	}
	console.Display("CTS002I", exitCode)
	return exitCode
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: unikk/cuto
func realMain(args *arguments) int {
	if args.versionFlag == flag_ON {
		showVersion()
		return rc_OK
	}

	if args.networkName == "" && args.rerunInstance == 0 {
		showUsage()
		return rc_ERROR
	}

	if args.networkName != "" && args.rerunInstance != 0 {
		console.Display("CTM019E", "Cannot use both -n and -r option.")
		return rc_ERROR
	}

	if args.configPath == "" {
		args.configPath = defaultConfig
	}

	message.MasterVersion = Version

	if err := config.Load(args.configPath); err != nil {
		console.Display("CTM004E", args.configPath)
		return rc_ERROR
	}

	if err := config.DetectError(); err != nil {
		console.Display("CTM005E", err)
		return rc_ERROR
	}

	if err := log.Init(config.Dir.LogDir,
		"master",
		"",
		config.Log.OutputLevel,
		config.Log.MaxSizeKB,
		config.Log.MaxGeneration,
		config.Log.TimeoutSec); err != nil {
		console.Display("CTM021E", err)
		return rc_ERROR
	}
	defer log.Term()
	console.Display("CTM001I", os.Getpid(), Version)
	// master終了時のコンソール出力
	var rc int
	defer func() {
		console.Display("CTM002I", rc)
	}()

	if args.rerunInstance != 0 {
		nwkResult, err := getNetworkResult(args.rerunInstance)
		if err != nil {
			console.Display("CTM019E", err)
			return rc_ERROR
		}

		if nwkResult.Status == db.NORMAL || nwkResult.Status == db.WARN {
			console.Display("CTM029I", args.rerunInstance)
			return rc_OK
		}

		args.networkName = nwkResult.JobnetWork
		args.startFlag = flag_ON
	}

	nwk := jobnet.LoadNetwork(args.networkName)
	if nwk == nil {
		rc = rc_ERROR
		return rc
	}
	defer nwk.Terminate()

	err := nwk.DetectFlowError()
	if err != nil {
		console.Display("CTM011E", nwk.MasterPath, err)
		rc = rc_ERROR
		return rc
	}

	if args.startFlag == flag_OFF {
		console.Display("CTM020I", nwk.MasterPath)
		rc = rc_OK
		return rc
	}

	err = nwk.LoadJobEx()
	if err != nil {
		console.Display("CTM004E", nwk.JobExPath)
		log.Error(err)
		rc = rc_ERROR
		return rc
	}

	if args.rerunInstance == 0 {
		err = nwk.Run()
	} else {
		nwk.ID = args.rerunInstance
		err = nwk.Rerun()
	}
	if err != nil {
		console.Display("CTM013I", nwk.Name, nwk.ID, "ABNORMAL")
		// ジョブ自体の異常終了では、エラーメッセージが空で返るので、出力しない
		if len(err.Error()) != 0 {
			log.Error(err)
		}
		rc = rc_ERROR
		return rc
	}
	console.Display("CTM013I", nwk.Name, nwk.ID, "NORMAL")
	rc = rc_OK
	return rc
}