Cleanup Socket and Pidfile on exit
These were previously left intact, even when exiting gracefully. As the daemon also fails if the socket already exists, it became the caller's responsibilityto check for and cleanup old socket files when performing graceful / deliberate restarts. Signed-off-by: Emily Shepherd <emily@redcoat.dev>
This commit is contained in:
parent
8c3664b2b1
commit
f89a005740
@ -15,6 +15,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -23,9 +24,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containernetworking/cni/pkg/skel"
|
"github.com/containernetworking/cni/pkg/skel"
|
||||||
@ -195,11 +198,27 @@ func runDaemon(
|
|||||||
return fmt.Errorf("Error getting listener: %v", err)
|
return fmt.Errorf("Error getting listener: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
srv := http.Server{}
|
||||||
|
exit := make(chan os.Signal, 1)
|
||||||
|
done := make(chan bool, 1)
|
||||||
|
signal.Notify(exit, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
<-exit
|
||||||
|
srv.Shutdown(context.TODO())
|
||||||
|
os.Remove(hostPrefix + socketPath)
|
||||||
|
os.Remove(pidfilePath)
|
||||||
|
|
||||||
|
done <- true
|
||||||
|
}()
|
||||||
|
|
||||||
dhcp := newDHCP(dhcpClientTimeout, resendMax)
|
dhcp := newDHCP(dhcpClientTimeout, resendMax)
|
||||||
dhcp.hostNetnsPrefix = hostPrefix
|
dhcp.hostNetnsPrefix = hostPrefix
|
||||||
dhcp.broadcast = broadcast
|
dhcp.broadcast = broadcast
|
||||||
rpc.Register(dhcp)
|
rpc.Register(dhcp)
|
||||||
rpc.HandleHTTP()
|
rpc.HandleHTTP()
|
||||||
http.Serve(l, nil)
|
srv.Serve(l)
|
||||||
|
|
||||||
|
<-done
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user