Standardize exit codes and improve shutdown handling; update gitignore

This commit is contained in:
Matthew Holt 2019-07-12 10:07:11 -06:00
parent 2141626269
commit b780f0f49b
No known key found for this signature in database
GPG key ID: 2A349DD577D586A5
7 changed files with 243 additions and 38 deletions

View file

@ -23,10 +23,15 @@ import (
"log"
"net"
"os"
"github.com/caddyserver/caddy/v2"
)
// Main executes the main function of the caddy command.
// Main implements the main function of the caddy command.
// Call this if Caddy is to be the main() if your program.
func Main() {
caddy.TrapSignals()
if len(os.Args) <= 1 {
fmt.Println(usageString())
return
@ -35,7 +40,7 @@ func Main() {
subcommand, ok := commands[os.Args[1]]
if !ok {
fmt.Printf("%q is not a valid command\n", os.Args[1])
os.Exit(2)
os.Exit(caddy.ExitCodeFailedStartup)
}
if exitCode, err := subcommand(); err != nil {