Example #1
0
func GetCmdArg() (*ppconf.PuppeteerConf, int, int, string) {
	if 2 > len(os.Args) {
		return nil, 0, 0, ""
	}

	conf := ppconf.LoadPuppeteerConf(os.Args[1])
	port := PORT_DEFAULT
	timeout := TIMEOUT_DEFAULT
	addr := ADDR_DEFAULT

	switch len(os.Args) {
	case 5:
		addr = os.Args[4]
		fallthrough
	case 4:
		if tmp, err := strconv.ParseInt(os.Args[3], 10, 16); nil == err && 0 < tmp {
			timeout = int(tmp)
		}
		fallthrough
	case 3:
		if tmp, err := strconv.ParseInt(os.Args[2], 10, 16); nil == err && 0 < tmp && 65535 >= tmp {
			port = int(tmp)
		}
		break
	}

	return conf, port, timeout, addr
}
Example #2
0
func main() {
	if 2 > len(os.Args) {
		Usage()
	}

	puppeteerConf := ppconf.LoadPuppeteerConf(os.Args[1])
	if !ppconf.ChkPuppeteerConf(puppeteerConf) {
		Usage()
	}

	if logFH, logErr := os.OpenFile(puppeteerConf.LogFile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, ppioutil.FILE_MASK); nil == logErr {
		log.SetOutput(logFH)
		log.SetFlags(log.LstdFlags)
	}

	queueChannel := make(chan string, 1)
	scoreboard := NewScoreboard(puppeteerConf)

	go JobMaster(queueChannel, scoreboard)
	time.Sleep(time.Second)

	signalChannel := make(chan os.Signal, 1)
	signal.Notify(signalChannel, os.Kill, syscall.SIGHUP, syscall.SIGTERM)

	for {
		select {
		case inSignal := <-signalChannel:
			if syscall.SIGTERM == inSignal || syscall.SIGKILL == inSignal {
				scoreboard.Terminate()
			}
			break
		default:
		}

		if scoreboard.IsTerminated() {
			if 0 == scoreboard.GetProcCnt() {
				break
			}
		}
		time.Sleep(time.Second)
	}

	log.Printf("puppeteer stops")
	os.Exit(0)
}