Exemplo n.º 1
0
func main() {
	if reexec.Init() {
		return
	}

	fnd := flag.Bool("nondaemon", false, "Not daemonize")
	flDisableIptables := flag.Bool("noniptables", false, "Don't enable iptables rules")
	flConfig := flag.String("config", "", "Config file for hyperd")
	flHost := flag.String("host", "", "Host for hyperd")
	flHelp := flag.Bool("help", false, "Print help message for Hyperd daemon")
	glog.Init()
	flag.Usage = func() { printHelp() }
	flag.Parse()
	if *flHelp == true {
		printHelp()
		return
	}

	if !*fnd {
		cmd, err := exec.LookPath(os.Args[0])
		if err != nil {
			fmt.Println("cannot find path of arg0 ", os.Args[0])
			os.Exit(-1)
		}
		cmd, err = filepath.Abs(cmd)
		if err != nil {
			fmt.Println("cannot find absolute path of arg0 ", os.Args[0])
			os.Exit(-1)
		}

		pid, err := utils.Daemonize()
		if err != nil {
			fmt.Println("faile to daemonize hyperd")
			os.Exit(-1)
		}
		if pid > 0 {
			return
		}

		err = syscall.Exec(cmd, append(os.Args, "--nondaemon"), os.Environ())
		if err != nil {
			fmt.Println("fail to exec in nondaemon mode: ", err.Error())
			os.Exit(-1)
		}

		return
	}

	mainDaemon(*flConfig, *flHost, *flDisableIptables)
}
Exemplo n.º 2
0
func main() {
	if reexec.Init() {
		return
	}

	fnd := flag.Bool("nondaemon", false, "Not daemonize")
	flDisableIptables := flag.Bool("noniptables", false, "Don't enable iptables rules")
	flConfig := flag.String("config", "", "Config file for hyperd")
	flHost := flag.String("host", "", "Host for hyperd")
	flHelp := flag.Bool("help", false, "Print help message for Hyperd daemon")
	glog.Init()
	flag.Usage = func() { printHelp() }
	flag.Parse()
	if *flHelp == true {
		printHelp()
		return
	}

	if !*fnd {
		path, err := osext.Executable()
		if err != nil {
			fmt.Printf("cannot find self executable path for %s: %v\n", os.Args[0], err)
			os.Exit(-1)
		}

		_, err = runvutils.ExecInDaemon(path, append(os.Args, "--nondaemon"))
		if err != nil {
			fmt.Println("faile to daemonize hyperd")
			os.Exit(-1)
		}

		return
	}

	mainDaemon(*flConfig, *flHost, *flDisableIptables)
}