MCPcopy Index your code
hub / github.com/foxcpp/maddy / Run

Function Run

maddy.go:183–230  ·  view source on GitHub ↗

Run is the entry point for all server-running code. It takes care of command line arguments processing, logging initialization, directives setup, configuration reading. After all that, it calls moduleMain to initialize and run modules.

(c *cli.Context)

Source from the content-addressed store, hash-verified

181// logging initialization, directives setup, configuration reading. After all that, it
182// calls moduleMain to initialize and run modules.
183func Run(c *cli.Context) error {
184 certmagic.UserAgent = "maddy/" + Version
185
186 if c.NArg() != 0 {
187 return cli.Exit(fmt.Sprintln("usage:", os.Args[0], "[options]"), 2)
188 }
189
190 if c.Bool("v") {
191 fmt.Println("maddy", BuildInfo())
192 return nil
193 }
194
195 var err error
196 log.DefaultLogger.Out, err = LogOutputOption(c.StringSlice("log"))
197 if err != nil {
198 systemdStatusErr(err)
199 return cli.Exit(err.Error(), 2)
200 }
201
202 initDebug(c)
203
204 err = os.Setenv("PATH", config.LibexecDirectory+string(filepath.ListSeparator)+os.Getenv("PATH"))
205 if err != nil {
206 systemdStatusErr(err)
207 return cli.Exit(err.Error(), 1)
208 }
209
210 hooks.AddHook(hooks.EventLogRotate, reinitLogging)
211 defer func(out log.Output) {
212 if err := out.Close(); err != nil {
213 log.Println("failed to close default logger output:", err)
214 }
215 }(log.DefaultLogger.Out)
216 defer hooks.RunHooks(hooks.EventShutdown)
217
218 defer func() {
219 if err := netresource.CloseAllListeners(); err != nil {
220 log.DefaultLogger.Error("CloseAllListeners failed", err)
221 }
222 }()
223
224 if err := moduleMain(c.Path("config")); err != nil {
225 systemdStatusErr(err)
226 return cli.Exit(err.Error(), 1)
227 }
228
229 return nil
230}
231
232func VerifyConfig(c *cli.Context) error {
233 err := os.Setenv("PATH", config.LibexecDirectory+string(filepath.ListSeparator)+os.Getenv("PATH"))

Callers

nothing calls this directly

Calls 13

AddHookFunction · 0.92
PrintlnFunction · 0.92
RunHooksFunction · 0.92
CloseAllListenersFunction · 0.92
BuildInfoFunction · 0.85
LogOutputOptionFunction · 0.85
initDebugFunction · 0.85
moduleMainFunction · 0.85
BoolMethod · 0.80
PrintlnMethod · 0.80
systemdStatusErrFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected