()
| 40 | } |
| 41 | |
| 42 | func main() { |
| 43 | flag.Usage = func() { |
| 44 | fmt.Printf("USAGE: %s [options] COMMAND\n\n", filepath.Base(os.Args[0])) |
| 45 | fmt.Printf("Commands:\n") |
| 46 | fmt.Printf(" system-init Prepare the system at start of day\n") |
| 47 | fmt.Printf(" stop Stop a service\n") |
| 48 | fmt.Printf(" start Start a service\n") |
| 49 | fmt.Printf(" restart Restart a service\n") |
| 50 | fmt.Printf(" help Print this message\n") |
| 51 | fmt.Printf("\n") |
| 52 | fmt.Printf("Run '%s COMMAND --help' for more information on the command\n", filepath.Base(os.Args[0])) |
| 53 | fmt.Printf("\n") |
| 54 | fmt.Printf("Options:\n") |
| 55 | flag.PrintDefaults() |
| 56 | } |
| 57 | var ( |
| 58 | ctx = context.Background() |
| 59 | flagQuiet = flag.Bool("q", false, "Quiet execution") |
| 60 | flagVerbose = flag.Bool("v", false, "Verbose execution") |
| 61 | flagContainerdNamespace = flag.String("containerd-namespace", defaultContainerdNamespace, "containerd namespace to use with services") |
| 62 | ) |
| 63 | |
| 64 | // Set up logging |
| 65 | log.SetFormatter(new(infoFormatter)) |
| 66 | log.SetLevel(log.InfoLevel) |
| 67 | flag.Parse() |
| 68 | if *flagQuiet && *flagVerbose { |
| 69 | fmt.Printf("Can't set quiet and verbose flag at the same time\n") |
| 70 | os.Exit(1) |
| 71 | } |
| 72 | if *flagQuiet { |
| 73 | log.SetLevel(log.ErrorLevel) |
| 74 | } |
| 75 | if *flagVerbose { |
| 76 | // Switch back to the standard formatter |
| 77 | log.SetFormatter(defaultLogFormatter) |
| 78 | log.SetLevel(log.DebugLevel) |
| 79 | } |
| 80 | |
| 81 | ctx = namespaces.WithNamespace(ctx, *flagContainerdNamespace) |
| 82 | |
| 83 | args := flag.Args() |
| 84 | if len(args) < 1 { |
| 85 | // check if called form startup scripts |
| 86 | command := os.Args[0] |
| 87 | switch { |
| 88 | case strings.Contains(command, "volumes"): |
| 89 | os.Exit(volumeInitCmd(ctx)) |
| 90 | case strings.Contains(command, "onboot"): |
| 91 | os.Exit(runcInit(onbootPath, "onboot")) |
| 92 | case strings.Contains(command, "onshutdown"): |
| 93 | os.Exit(runcInit(shutdownPath, "shutdown")) |
| 94 | case strings.Contains(command, "containerd"): |
| 95 | systemInitCmd(ctx, []string{}) |
| 96 | os.Exit(0) |
| 97 | } |
| 98 | } |
| 99 |
nothing calls this directly
no test coverage detected