MCPcopy Create free account
hub / github.com/linuxkit/linuxkit / main

Function main

pkg/init/cmd/service/main.go:42–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40}
41
42func 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

Callers

nothing calls this directly

Calls 7

volumeInitCmdFunction · 0.85
runcInitFunction · 0.85
systemInitCmdFunction · 0.85
stopCmdFunction · 0.85
startCmdFunction · 0.85
restartCmdFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected