Ejemplo n.º 1
0
Archivo: exec.go Proyecto: unikk/cuto
// NewCommand creates Command object with unique network name.
// Network name is generate from realtimeName and current timestamp.
func NewCommand(realtimeName string) *Command {
	c := new(Command)
	timestamp := time.Now().Format("20060102150405")
	if realtimeName == "" {
		c.networkName = fmt.Sprintf("realtime_%s", timestamp)
	} else {
		c.networkName = fmt.Sprintf("realtime_%s_%s", realtimeName, timestamp)
	}

	masterPath := filepath.Join(util.GetRootPath(), "bin", "master")
	configPath := filepath.Join(util.GetRootPath(), "bin", "master.ini")
	c.cmd = exec.Command(masterPath, "-n", c.networkName, "-s", "-c", configPath)
	return c
}
Ejemplo n.º 2
0
Archivo: main.go Proyecto: 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
}
Ejemplo n.º 3
0
Archivo: main.go Proyecto: unikk/cuto
func realMain() int {
	args := fetchArgs()
	if args == nil {
		showUsage()
		return 1
	}

	configPath := filepath.Join(util.GetRootPath(), "bin", "master.ini")
	if err := config.Load(configPath); err != nil {
		msg := fmt.Sprintf("master.ini not found or cannot read it.")
		fmt.Println(network.RealtimeErrorResult(msg))
		return 1
	}
	networkDir := config.Dir.JobnetDir

	if err := network.LoadJobex(args.realtimeName, networkDir); err != nil {
		msg := fmt.Sprintf("Jobex csv load error: %s", err)
		fmt.Println(network.RealtimeErrorResult(msg))
		return 1
	}

	res, err := http.Get(args.jsonURL)
	if err != nil {
		msg := fmt.Sprintf("HTTP request error: %s", err)
		fmt.Println(network.RealtimeErrorResult(msg))
		return 1
	}
	defer res.Body.Close()
	if res.StatusCode != http.StatusOK {
		msg := fmt.Sprintf("HTTP response error. Status code[%d]", res.StatusCode)
		fmt.Println(network.RealtimeErrorResult(msg))
		return 1
	}

	nwk, err := network.Parse(res.Body)
	if err != nil {
		msg := fmt.Sprintf("Parse error: %s", err)
		fmt.Println(network.RealtimeErrorResult(msg))
		return 1
	}

	cmd := network.NewCommand(args.realtimeName)
	if err := nwk.Export(cmd.GetNetworkName(), networkDir); err != nil {
		msg := fmt.Sprintf("Network temporary file create error: %s", err)
		fmt.Println(network.RealtimeErrorResult(msg))
		return 1
	}
	defer nwk.Clean(cmd.GetNetworkName(), networkDir)

	id, err := cmd.Run()
	if err != nil {
		fmt.Println(network.MasterErrorResult(err.Error(), cmd.GetPID()))
		return 1
	}

	result := network.SuccessResult(cmd.GetPID(), id, cmd.GetNetworkName())
	fmt.Println(result)
	cmd.Release()

	return 0
}
Ejemplo n.º 4
0
Archivo: config.go Proyecto: unikk/cuto
func init() {
	RootPath = util.GetRootPath()
	//	FilePath = fmt.Sprintf("%s%c%s%c%s", RootPath, os.PathSeparator, dirName, os.PathSeparator, fileName)
	FilePath = fmt.Sprintf(".%c%s", os.PathSeparator, fileName)
}
Ejemplo n.º 5
0
Archivo: config.go Proyecto: unikk/cuto
func (s *ServantConfig) replaceCutoroot() {
	s.Dir.JoblogDir = strings.Replace(s.Dir.JoblogDir, tag_CUTOROOT, util.GetRootPath(), -1)
	s.Dir.JobDir = strings.Replace(s.Dir.JobDir, tag_CUTOROOT, util.GetRootPath(), -1)
	s.Dir.LogDir = strings.Replace(s.Dir.LogDir, tag_CUTOROOT, util.GetRootPath(), -1)
}
Ejemplo n.º 6
0
Archivo: config.go Proyecto: unikk/cuto
func replaceCutoroot(c *config) {
	c.Dir.JobnetDir = strings.Replace(c.Dir.JobnetDir, tag_CUTOROOT, util.GetRootPath(), -1)
	c.Dir.LogDir = strings.Replace(c.Dir.LogDir, tag_CUTOROOT, util.GetRootPath(), -1)
	c.DB.DBFile = strings.Replace(c.DB.DBFile, tag_CUTOROOT, util.GetRootPath(), -1)
}