示例#1
0
文件: run.go 项目: perry-xiong/daemon
func main() {

	if len(os.Args) < 2 {
		log.ErrorNoLine(`
	Please Input Server Name And Params:
	Absolute path
		`)
		return
	}

	filePath, err := filepath.Abs(os.Args[1])
	if err != nil {
		log.Error(err)
	}

	server := Exec(filePath, os.Args[2:]...)
	err = server.Start()
	if err != nil {
		filePath = os.Args[1]
		server = Exec(filePath, os.Args[2:]...)
		err2 := server.Start()
		if err2 != nil {
			log.Error(err2)
			return
		}
		return
	}

	log.Info("Start Daemon Server Ok!\n", os.Args[1])

	return
}
示例#2
0
文件: run.go 项目: kissthink/daemon-1
func main() {

	if len(os.Args) < 2 {
		log.ErrorNoLine(`
	Please Input Server Name And Params:
	Absolute path
		`)
		return
	}

	filePath, err := filepath.Abs(os.Args[1])
	if err != nil {
		log.Error(err)
		return
	}

	server := exec.Command(filePath, os.Args[2:]...)
	server.Stdout = os.Stdout
	server.Stderr = os.Stderr
	server.Stdin = os.Stdin

	var path string

	if GetRelative(path) >= 0 {
		path = GetPath(os.Args[1])
		server.Dir = path
	}

	err = server.Start()
	if err != nil {
		log.Error(err)
		return
	}

	log.Info("Start Daemon Server Ok!\n", os.Args[1])

	return
}
示例#3
0
func main() {

	if len(os.Args) < 3 {
		log.ErrorNoLine(`
	-root		:	server root path(can empty)
	-filter		:	process filter(if empty, no effect)
	-server		:	server relative path
	-time		:	search time	
	`)
		return
	}

	runtime.GOMAXPROCS(runtime.NumCPU())

	var root string
	var server string
	var filter string
	var t int

	flag.StringVar(&root, "root", "", "server root path")
	flag.StringVar(&server, "server", "", "server relative path")
	flag.StringVar(&filter, "filter", "", "process filter")
	flag.IntVar(&t, "time", 5, "search time")

	flag.Parse()

	if len(root) > 0 && root[len(root)-1:len(root)] != "/" {
		root += "/"
	}

	serverlist := strings.Split(server, ",")
	if len(serverlist) <= 0 {
		log.ErrorNoLine("Please Input Server Path")
		return
	}

	servers := make([]string, 0)
	for i := 0; i < len(serverlist); i++ {
		if serverlist[i] != "" {
			servers = append(servers, serverlist[i])
		}
	}

	waitgroup := &sync.WaitGroup{}
	buff := NewStringBuffer()
	timer := time.NewTimer(time.Second * time.Duration(t))

	waitgroup.Add(1)

	fl := GetFilter(ParseFilter(filter))

	go func() {
		defer waitgroup.Done()

		for {

			GetApp(buff, fl)
			buff.Msg <- 1

			<-timer.C
			timer.Reset(time.Second * time.Duration(t))
		}
	}()

	go func() {
		for {
			<-buff.Msg

			data, err := buff.Read()
			if err != nil {
				log.ErrorNoLine(err)
				break
			}

			apps := ParseApp(data)

			noStartServer, err := CheckApp(apps, root, servers)
			if err != nil {
				log.ErrorNoLine(err)
				return
			}

			log.Info("Need Start Server:\n", noStartServer)
			StartApps(root, noStartServer)

		}
	}()

	waitgroup.Wait()
	log.InfoNoLine("Exit")
}