示例#1
0
func (p *program) run() error {
	mtu.Init(configuration, icmpPackets)

	if len(os.Args) > 1 {
		command := os.Args[1]
		switch command {
		case "interactive", "i":
			log.Println("Interactive testing")
			if len(os.Args) > 2 {
				handleInteractiveArg(os.Args[2])
			} else {
				fmt.Println("Please specify an additional argument when using 'ipsecdiagtool " + command + "'")
				fmt.Println("Use 'ipsecdiagtool help' to get additional information.")
			}
		}
	} else {
		go packetloss.Detect(configuration, ipsecPackets, false)
		capture.Start(configuration, icmpPackets, ipsecPackets)

		/*
			//Code tested in the IDE could be placed here
			if configuration.Debug {
				log.Println("WARNING DEBUG ENABLES IDE TEST CODE.")
				//Code tested directly in the IDE belongs in here
				go mtu.FindAll()
			}*/
	}

	if configuration.Debug {
		log.Println("Running Daemon via", service.Platform())
	}
	<-p.exit
	return nil
}
示例#2
0
func (p *program) run() {
	logger.Infof("Service running %v.", service.Platform())

	exePath, err := osext.ExecutableFolder()
	if err != nil {
		log.Fatal(err)
	}

	if _, err := os.Stat(exePath + "/logs"); os.IsNotExist(err) {
		err = os.Mkdir(exePath+"/logs", 0766)
		if err != nil {
			log.Fatalf("error creating logs folder: %v", err)
		}
	}

	ts := time.Now().Local().Format("2006-01-02")
	f, err := os.OpenFile(exePath+"/logs/print-server-"+ts+".log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		log.Fatalf("error opening log file: %v", err)
	}
	defer f.Close()

	log.SetOutput(f)
	log.SetFlags(log.Ldate + log.Ltime + log.Lmicroseconds)

	http.HandleFunc("/print", print)
	http.HandleFunc("/", home)

	log.Printf("Server started-up and listening at %s.", *addr)
	log.Fatal(http.ListenAndServe(*addr, nil))
}
示例#3
0
文件: gtd.go 项目: anansii/centurio
// the magic happens here
func (p *program) run() error {
	logger.Infof("Running as %v.", service.Platform())
	ticker := time.NewTicker(2 * time.Second)
	for {
		select {
		case tm := <-ticker.C:
			logger.Infof("Still running at %v...", tm)
		case <-p.exit:
			ticker.Stop()
			return nil
		}
	}
}
示例#4
0
func (p *program) run() error {
	logger.Infof("I'm running %v.", service.Platform())

	go func() {
		<-p.exit
		StopServers()
	}()

	if p.runfunc != nil {
		p.runfunc()
	}
	WaitForServers()

	return nil
}