mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-22 16:46:53 +01:00
improve error checking (#1938)
This commit is contained in:
parent
ac1f3bfaaa
commit
74d4fd3c29
3 changed files with 39 additions and 12 deletions
|
@ -25,9 +25,15 @@ func TestAssetsPath(t *testing.T) {
|
||||||
t.Errorf("Expected path to be a .caddy folder, got: %v", actual)
|
t.Errorf("Expected path to be a .caddy folder, got: %v", actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Setenv("CADDYPATH", "testpath")
|
err := os.Setenv("CADDYPATH", "testpath")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Could not set CADDYPATH")
|
||||||
|
}
|
||||||
if actual, expected := AssetsPath(), "testpath"; actual != expected {
|
if actual, expected := AssetsPath(), "testpath"; actual != expected {
|
||||||
t.Errorf("Expected path to be %v, got: %v", expected, actual)
|
t.Errorf("Expected path to be %v, got: %v", expected, actual)
|
||||||
}
|
}
|
||||||
os.Setenv("CADDYPATH", "")
|
err = os.Setenv("CADDYPATH", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Could not set CADDYPATH")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
31
caddy.go
31
caddy.go
|
@ -206,12 +206,15 @@ func (i *Instance) Restart(newCaddyfile Input) (*Instance, error) {
|
||||||
|
|
||||||
// success! stop the old instance
|
// success! stop the old instance
|
||||||
for _, shutdownFunc := range i.onShutdown {
|
for _, shutdownFunc := range i.onShutdown {
|
||||||
err := shutdownFunc()
|
err = shutdownFunc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i.Stop()
|
err = i.Stop()
|
||||||
|
if err != nil {
|
||||||
|
return i, err
|
||||||
|
}
|
||||||
|
|
||||||
// Execute instantiation events
|
// Execute instantiation events
|
||||||
EmitEvent(InstanceStartupEvent, newInst)
|
EmitEvent(InstanceStartupEvent, newInst)
|
||||||
|
@ -483,14 +486,14 @@ func startWithListenerFds(cdyfile Input, inst *Instance, restartFds map[string]r
|
||||||
if !IsUpgrade() && restartFds == nil {
|
if !IsUpgrade() && restartFds == nil {
|
||||||
// first startup means not a restart or upgrade
|
// first startup means not a restart or upgrade
|
||||||
for _, firstStartupFunc := range inst.onFirstStartup {
|
for _, firstStartupFunc := range inst.onFirstStartup {
|
||||||
err := firstStartupFunc()
|
err = firstStartupFunc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, startupFunc := range inst.onStartup {
|
for _, startupFunc := range inst.onStartup {
|
||||||
err := startupFunc()
|
err = startupFunc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -653,7 +656,10 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
|
||||||
if fdIndex, ok := loadedGob.ListenerFds["tcp"+addr]; ok {
|
if fdIndex, ok := loadedGob.ListenerFds["tcp"+addr]; ok {
|
||||||
file := os.NewFile(fdIndex, "")
|
file := os.NewFile(fdIndex, "")
|
||||||
ln, err = net.FileListener(file)
|
ln, err = net.FileListener(file)
|
||||||
file.Close()
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = file.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -661,7 +667,10 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
|
||||||
if fdIndex, ok := loadedGob.ListenerFds["udp"+addr]; ok {
|
if fdIndex, ok := loadedGob.ListenerFds["udp"+addr]; ok {
|
||||||
file := os.NewFile(fdIndex, "")
|
file := os.NewFile(fdIndex, "")
|
||||||
pc, err = net.FilePacketConn(file)
|
pc, err = net.FilePacketConn(file)
|
||||||
file.Close()
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = file.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -684,7 +693,10 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
file.Close()
|
err = file.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// packetconn
|
// packetconn
|
||||||
if old.packet != nil {
|
if old.packet != nil {
|
||||||
|
@ -696,7 +708,10 @@ func startServers(serverList []Server, inst *Instance, restartFds map[string]res
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
file.Close()
|
err = file.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
upgrade.go
10
upgrade.go
|
@ -136,7 +136,10 @@ func Upgrade() error {
|
||||||
|
|
||||||
// immediately close our dup'ed fds and the write end of our signal pipe
|
// immediately close our dup'ed fds and the write end of our signal pipe
|
||||||
for _, f := range extraFiles {
|
for _, f := range extraFiles {
|
||||||
f.Close()
|
err = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// feed Caddyfile to the child
|
// feed Caddyfile to the child
|
||||||
|
@ -144,7 +147,10 @@ func Upgrade() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
wpipe.Close()
|
err = wpipe.Close()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// determine whether child startup succeeded
|
// determine whether child startup succeeded
|
||||||
answer, readErr := ioutil.ReadAll(sigrpipe)
|
answer, readErr := ioutil.ReadAll(sigrpipe)
|
||||||
|
|
Loading…
Reference in a new issue