Ejemplo n.º 1
0
func Run(configFile string, fileChangeDelay time.Duration) int {
	slog.Colorized("{green}Starting {yellow}Z{red}e{blue}u{magenta}s{green} server v" + zeusversion.VERSION)

	zerror.Init()

	monitor, err := buildFileMonitor(fileChangeDelay)
	if err != nil {
		return 2
	}

	var tree = config.BuildProcessTree(configFile, monitor)

	done := make(chan bool)

	defer exit(processtree.StartSlaveMonitor(tree, monitor.Listen(), done), done)
	defer exit(clienthandler.Start(tree, done), done)
	defer monitor.Close()
	defer slog.Suppress()
	defer zerror.PrintFinalOutput()
	defer exit(statuschart.Start(tree, done), done)

	c := make(chan os.Signal, 1)
	signal.Notify(c, terminatingSignals...)

	for {
		select {
		case sig := <-c:
			if sig == syscall.SIGINT {
				return 0
			} else {
				return 1
			}
		}
	}
}
Ejemplo n.º 2
0
func doRun() int {
	slog.Colorized("{green}Starting {yellow}Z{red}e{blue}u{magenta}s{green} server v" + zeusversion.VERSION)

	zerror.Init()
	var tree *processtree.ProcessTree = config.BuildProcessTree()

	done := make(chan bool)

	// Start processes and register them for exit when the function returns.
	filesChanged, filemonitorDone := filemonitor.Start(done)

	defer exit(processtree.StartSlaveMonitor(tree, done), done)
	defer exit(clienthandler.Start(tree, done), done)
	defer exit(filemonitorDone, done)
	defer exit(restarter.Start(tree, filesChanged, done), done)
	defer slog.Suppress()
	defer zerror.PrintFinalOutput()
	defer exit(statuschart.Start(tree, done), done)

	c := make(chan os.Signal, 1)
	signal.Notify(c, terminatingSignals...)

	for {
		select {
		case sig := <-c:
			if sig == syscall.SIGINT {
				return 0
			} else {
				return 1
			}
		}
	}
}
Ejemplo n.º 3
0
func main() {
	for Args = os.Args[1:]; Args != nil && len(Args) > 0 && Args[0][0] == '-'; Args = Args[1:] {
		switch Args[0] {
		case "--no-color":
			color = false
			slog.DisableColor()
		case "--log":
			tracefile, err := os.OpenFile(Args[1], os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
			if err == nil {
				slog.TraceLogger = slog.NewTraceLogger(tracefile)
				Args = Args[1:]
			} else {
				fmt.Printf("Could not open trace file %s", Args[1])
				return
			}
		case "--file-change-delay":
			if len(Args) > 1 {
				delay, err := time.ParseDuration(Args[1])
				if err != nil {
					execManPage("zeus")
				}
				Args = Args[1:]
				restarter.FileChangeWindow = delay
			} else {
				execManPage("zeus")
			}
		case "--version":
			printVersion()
			return
		}
	}
	if len(Args) == 0 {
		execManPage("zeus")
	}

	if generalHelpRequested(Args) {
		execManPage("zeus")
	} else if Args[0] == "help" {
		commandSpecificHelp(Args)
	} else if Args[0] == "version" {
		printVersion()
	} else if Args[0] == "start" {
		zeusmaster.Run()
	} else if Args[0] == "init" {
		zeusInit()
	} else if Args[0] == "commands" {
		zeusCommands()
	} else {
		tree := config.BuildProcessTree()
		for _, name := range tree.AllCommandsAndAliases() {
			if Args[0] == name {
				zeusclient.Run()
				return
			}
		}

		commandNotFound(Args[0])
	}
}
Ejemplo n.º 4
0
Archivo: zeus.go Proyecto: burke/zeus
func zeusCommands(configFile string) {
	tree := config.BuildProcessTree(configFile, nil)
	for _, command := range tree.Commands {
		alia := strings.Join(command.Aliases, ", ")
		var aliasPart string
		if len(alia) > 0 {
			aliasPart = " (alias: " + alia + ")"
		}
		println("zeus " + command.Name + aliasPart)
	}
}
Ejemplo n.º 5
0
func main() {
	if len(os.Args) == 1 {
		execManPage("zeus")
	}

	var args []string
	if os.Args[1] == "--no-color" {
		color = false
		slog.DisableColor()
		args = os.Args[2:]
	} else {
		args = os.Args[1:]
	}

	if generalHelpRequested(args) {
		execManPage("zeus")
	} else if args[0] == "help" {
		commandSpecificHelp(args)
	} else if args[0] == "version" || args[0] == "--version" {
		println("Zeus version " + zeusversion.VERSION)
	} else if args[0] == "start" {
		zeusmaster.Run()
	} else if args[0] == "init" {
		zeusInit()
	} else if args[0] == "commands" {
		zeusCommands()
	} else {
		tree := config.BuildProcessTree()
		for _, name := range tree.AllCommandsAndAliases() {
			if args[0] == name {
				zeusclient.Run()
				return
			}
		}

		commandNotFound(args[0])
	}
}
Ejemplo n.º 6
0
Archivo: zeus.go Proyecto: burke/zeus
func main() {
	args := os.Args[1:]
	configFile := "zeus.json"
	fileChangeDelay := filemonitor.DefaultFileChangeDelay

	for ; args != nil && len(args) > 0 && args[0][0] == '-'; args = args[1:] {
		switch args[0] {
		case "--no-color":
			color = false
			slog.DisableColor()
		case "--log":
			tracefile, err := os.OpenFile(args[1], os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
			if err == nil {
				slog.SetTraceLogger(slog.NewTraceLogger(tracefile))
				args = args[1:]
			} else {
				fmt.Printf("Could not open trace file %s\n", args[1])
				return
			}
		case "--file-change-delay":
			if len(args) > 1 {
				delay, err := time.ParseDuration(args[1])
				if err != nil {
					execManPage("zeus")
				}
				args = args[1:]
				fileChangeDelay = delay
			} else {
				execManPage("zeus")
			}
		case "--config":
			_, err := os.Stat(args[1])
			if err != nil {
				fmt.Printf("Config file doesn't exist: %s (%e)\n", args[1], err)
				return
			}
			configFile = args[1]
			args = args[1:]
		case "--version":
			printVersion()
			return
		}
	}
	if len(args) == 0 {
		execManPage("zeus")
		return
	}

	if generalHelpRequested(args) {
		execManPage("zeus")
	} else if args[0] == "help" {
		commandSpecificHelp(args)
	} else if args[0] == "version" {
		printVersion()
	} else if args[0] == "start" {
		os.Exit(zeusmaster.Run(configFile, fileChangeDelay))
	} else if args[0] == "init" {
		zeusInit()
	} else if args[0] == "commands" {
		zeusCommands(configFile)
	} else {
		tree := config.BuildProcessTree(configFile, nil)
		for _, name := range tree.AllCommandsAndAliases() {
			if args[0] == name {
				// Don't confuse the master by sending *full* args to
				// it; just those that are not zeus-specific.
				os.Exit(zeusclient.Run(args, os.Stdin, os.Stdout))
			}
		}

		commandNotFound(args[0])
	}
}
Ejemplo n.º 7
0
func main() {
	for Args = os.Args[1:]; Args != nil && len(Args) > 0 && Args[0][0] == '-'; Args = Args[1:] {
		switch Args[0] {
		case "--no-color":
			color = false
			slog.DisableColor()
		case "--log":
			tracefile, err := os.OpenFile(Args[1], os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
			if err == nil {
				slog.SetTraceLogger(slog.NewTraceLogger(tracefile))
				Args = Args[1:]
			} else {
				fmt.Printf("Could not open trace file %s\n", Args[1])
				return
			}
		case "--file-change-delay":
			if len(Args) > 1 {
				delay, err := time.ParseDuration(Args[1])
				if err != nil {
					execManPage("zeus")
				}
				Args = Args[1:]
				restarter.FileChangeWindow = delay
			} else {
				execManPage("zeus")
			}
		case "--config":
			_, err := os.Stat(Args[1])
			if err != nil {
				fmt.Printf("Config file doesn't exist: %s (%e)\n", Args[1], err)
				return
			}
			config.ConfigFile = Args[1]
			Args = Args[1:]
		case "--version":
			printVersion()
			return
		}
	}
	if len(Args) == 0 {
		execManPage("zeus")
	}

	// Don't confuse the master by sending *full* args to it; just those that are
	// not zeus-specific.
	config.Args = Args

	if generalHelpRequested(Args) {
		execManPage("zeus")
	} else if Args[0] == "help" {
		commandSpecificHelp(Args)
	} else if Args[0] == "version" {
		printVersion()
	} else if Args[0] == "start" {
		zeusmaster.Run()
	} else if Args[0] == "init" {
		zeusInit()
	} else if Args[0] == "commands" {
		zeusCommands()
	} else {
		tree := config.BuildProcessTree()
		for _, name := range tree.AllCommandsAndAliases() {
			if Args[0] == name {
				zeusclient.Run()
				return
			}
		}

		commandNotFound(Args[0])
	}
}