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)
| 181 | // logging initialization, directives setup, configuration reading. After all that, it |
| 182 | // calls moduleMain to initialize and run modules. |
| 183 | func 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 | |
| 232 | func VerifyConfig(c *cli.Context) error { |
| 233 | err := os.Setenv("PATH", config.LibexecDirectory+string(filepath.ListSeparator)+os.Getenv("PATH")) |
nothing calls this directly
no test coverage detected