func main() { defer shutdown.Exit() usage := `usage: flynn-host [-h|--help] [--version] <command> [<args>...] Options: -h, --help Show this message --version Show current version Commands: help Show usage for a specific command init Create cluster configuration for daemon daemon Start the daemon update Update Flynn components download Download container images bootstrap Bootstrap layer 1 inspect Get low-level information about a job log Get the logs of a job ps List jobs stop Stop running jobs destroy-volumes Destroys the local volume database collect-debug-info Collect debug information into an anonymous gist or tarball version Show current version See 'flynn-host help <command>' for more information on a specific command. ` args, _ := docopt.Parse(usage, nil, true, version.String(), true) cmd := args.String["<command>"] cmdArgs := args.All["<args>"].([]string) if cmd == "help" { if len(cmdArgs) == 0 { // `flynn help` fmt.Println(usage) return } else { // `flynn help <command>` cmd = cmdArgs[0] cmdArgs = []string{"--help"} } } if cmd == "daemon" { // merge in args and env from config file, if available var c *config.Config if n := os.Getenv("FLYNN_HOST_CONFIG"); n != "" { var err error c, err = config.Open(n) if err != nil { log.Fatalf("error opening config file %s: %s", n, err) } } else { var err error c, err = config.Open(configFile) if err != nil && !os.IsNotExist(err) { log.Fatalf("error opening config file %s: %s", configFile, err) } if c == nil { c = &config.Config{} } } cmdArgs = append(cmdArgs, c.Args...) for k, v := range c.Env { os.Setenv(k, v) } } if err := cli.Run(cmd, cmdArgs); err != nil { if err == cli.ErrInvalidCommand { fmt.Printf("ERROR: %q is not a valid command\n\n", cmd) fmt.Println(usage) shutdown.ExitWithCode(1) } shutdown.Fatal(err) } }
func main() { // when starting a container with libcontainer, we first exec the // current binary with libcontainer-init as the first argument, // which triggers the following code to initialise the container // environment (namespaces, network etc.) then exec containerinit if len(os.Args) > 1 && os.Args[1] == "libcontainer-init" { runtime.GOMAXPROCS(1) runtime.LockOSThread() factory, _ := libcontainer.New("") if err := factory.StartInitialization(); err != nil { log.Fatal(err) } } defer shutdown.Exit() usage := `usage: flynn-host [-h|--help] [--version] <command> [<args>...] Options: -h, --help Show this message --version Show current version Commands: help Show usage for a specific command init Create cluster configuration for daemon daemon Start the daemon update Update Flynn components download Download container images bootstrap Bootstrap layer 1 inspect Get low-level information about a job log Get the logs of a job ps List jobs stop Stop running jobs signal Signal a job destroy-volumes Destroys the local volume database collect-debug-info Collect debug information into an anonymous gist or tarball list Lists ID and IP of each host version Show current version fix Fix a broken cluster tags Manage flynn-host daemon tags discover Return low-level information about a service See 'flynn-host help <command>' for more information on a specific command. ` args, _ := docopt.Parse(usage, nil, true, version.String(), true) cmd := args.String["<command>"] cmdArgs := args.All["<args>"].([]string) if cmd == "help" { if len(cmdArgs) == 0 { // `flynn help` fmt.Println(usage) return } else { // `flynn help <command>` cmd = cmdArgs[0] cmdArgs = []string{"--help"} } } if cmd == "daemon" { // merge in args and env from config file, if available var c *config.Config if n := os.Getenv("FLYNN_HOST_CONFIG"); n != "" { var err error c, err = config.Open(n) if err != nil { shutdown.Fatalf("error opening config file %s: %s", n, err) } } else { var err error c, err = config.Open(configFile) if err != nil && !os.IsNotExist(err) { shutdown.Fatalf("error opening config file %s: %s", configFile, err) } if c == nil { c = &config.Config{} } } cmdArgs = append(cmdArgs, c.Args...) for k, v := range c.Env { os.Setenv(k, v) } } if err := cli.Run(cmd, cmdArgs); err != nil { if err == cli.ErrInvalidCommand { fmt.Printf("ERROR: %q is not a valid command\n\n", cmd) fmt.Println(usage) shutdown.ExitWithCode(1) } else if _, ok := err.(cli.ErrAlreadyLogged); ok { shutdown.ExitWithCode(1) } shutdown.Fatal(err) } }