mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-08 11:58:49 +03:00
Ensure user always sees fatal errors at startup
This commit is contained in:
parent
53e117802f
commit
49cb225cbd
1 changed files with 11 additions and 11 deletions
|
@ -75,7 +75,7 @@ func Run() {
|
||||||
if revoke != "" {
|
if revoke != "" {
|
||||||
err := caddytls.Revoke(revoke)
|
err := caddytls.Revoke(revoke)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
mustLogFatalf(err.Error())
|
||||||
}
|
}
|
||||||
fmt.Printf("Revoked certificate for %s\n", revoke)
|
fmt.Printf("Revoked certificate for %s\n", revoke)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
@ -97,36 +97,36 @@ func Run() {
|
||||||
// Set CPU cap
|
// Set CPU cap
|
||||||
err := setCPU(cpu)
|
err := setCPU(cpu)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mustLogFatal(err)
|
mustLogFatalf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Caddyfile input
|
// Get Caddyfile input
|
||||||
caddyfile, err := caddy.LoadCaddyfile(serverType)
|
caddyfile, err := caddy.LoadCaddyfile(serverType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mustLogFatal(err)
|
mustLogFatalf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start your engines
|
// Start your engines
|
||||||
instance, err := caddy.Start(caddyfile)
|
instance, err := caddy.Start(caddyfile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mustLogFatal(err)
|
mustLogFatalf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Twiddle your thumbs
|
// Twiddle your thumbs
|
||||||
instance.Wait()
|
instance.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
// mustLogFatal wraps log.Fatal() in a way that ensures the
|
// mustLogFatalf wraps log.Fatalf() in a way that ensures the
|
||||||
// output is always printed to stderr so the user can see it
|
// output is always printed to stderr so the user can see it
|
||||||
// if the user is still there, even if the process log was not
|
// if the user is still there, even if the process log was not
|
||||||
// enabled. If this process is an upgrade, however, and the user
|
// enabled. If this process is an upgrade, however, and the user
|
||||||
// might not be there anymore, this just logs to the process
|
// might not be there anymore, this just logs to the process
|
||||||
// log and exits.
|
// log and exits.
|
||||||
func mustLogFatal(args ...interface{}) {
|
func mustLogFatalf(format string, args ...interface{}) {
|
||||||
if !caddy.IsUpgrade() {
|
if !caddy.IsUpgrade() {
|
||||||
log.SetOutput(os.Stderr)
|
log.SetOutput(os.Stderr)
|
||||||
}
|
}
|
||||||
log.Fatal(args...)
|
log.Fatalf(format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// confLoader loads the Caddyfile using the -conf flag.
|
// confLoader loads the Caddyfile using the -conf flag.
|
||||||
|
@ -178,16 +178,16 @@ func moveStorage() {
|
||||||
// Just use a default config to get default (file) storage
|
// Just use a default config to get default (file) storage
|
||||||
fileStorage, err := new(caddytls.Config).StorageFor(caddytls.DefaultCAUrl)
|
fileStorage, err := new(caddytls.Config).StorageFor(caddytls.DefaultCAUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("[ERROR] Unable to get new path for certificate storage: %v", err)
|
mustLogFatalf("[ERROR] Unable to get new path for certificate storage: %v", err)
|
||||||
}
|
}
|
||||||
newPath := fileStorage.(*caddytls.FileStorage).Path
|
newPath := fileStorage.(*caddytls.FileStorage).Path
|
||||||
err = os.MkdirAll(string(newPath), 0700)
|
err = os.MkdirAll(string(newPath), 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("[ERROR] Unable to make new certificate storage path: %v\n\nPlease follow instructions at:\nhttps://github.com/mholt/caddy/issues/902#issuecomment-228876011", err)
|
mustLogFatalf("[ERROR] Unable to make new certificate storage path: %v\n\nPlease follow instructions at:\nhttps://github.com/mholt/caddy/issues/902#issuecomment-228876011", err)
|
||||||
}
|
}
|
||||||
err = os.Rename(oldPath, string(newPath))
|
err = os.Rename(oldPath, string(newPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("[ERROR] Unable to migrate certificate storage: %v\n\nPlease follow instructions at:\nhttps://github.com/mholt/caddy/issues/902#issuecomment-228876011", err)
|
mustLogFatalf("[ERROR] Unable to migrate certificate storage: %v\n\nPlease follow instructions at:\nhttps://github.com/mholt/caddy/issues/902#issuecomment-228876011", err)
|
||||||
}
|
}
|
||||||
// convert mixed case folder and file names to lowercase
|
// convert mixed case folder and file names to lowercase
|
||||||
var done bool // walking is recursive and preloads the file names, so we must restart walk after a change until no changes
|
var done bool // walking is recursive and preloads the file names, so we must restart walk after a change until no changes
|
||||||
|
@ -200,7 +200,7 @@ func moveStorage() {
|
||||||
lowerPath := filepath.Join(filepath.Dir(path), lowerBase)
|
lowerPath := filepath.Join(filepath.Dir(path), lowerBase)
|
||||||
err = os.Rename(path, lowerPath)
|
err = os.Rename(path, lowerPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("[ERROR] Unable to lower-case: %v\n\nPlease follow instructions at:\nhttps://github.com/mholt/caddy/issues/902#issuecomment-228876011", err)
|
mustLogFatalf("[ERROR] Unable to lower-case: %v\n\nPlease follow instructions at:\nhttps://github.com/mholt/caddy/issues/902#issuecomment-228876011", err)
|
||||||
}
|
}
|
||||||
// terminate traversal and restart since Walk needs the updated file list with new file names
|
// terminate traversal and restart since Walk needs the updated file list with new file names
|
||||||
done = false
|
done = false
|
||||||
|
|
Loading…
Reference in a new issue