mirror of
https://github.com/costela/docker-etchosts.git
synced 2025-05-10 17:35:41 +02:00
add cleanup on exit
This commit is contained in:
parent
03a5f533ca
commit
97d926b432
1 changed files with 16 additions and 0 deletions
16
main.go
16
main.go
|
@ -18,7 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
docker "docker.io/go-docker"
|
||||
|
||||
|
@ -48,6 +51,13 @@ func main() {
|
|||
|
||||
log.SetLevel(logLevelMap[strings.ToLower(config.LogLevel)])
|
||||
|
||||
quitSig := make(chan os.Signal)
|
||||
signal.Notify(quitSig, syscall.SIGTERM, syscall.SIGINT)
|
||||
go func() {
|
||||
<-quitSig
|
||||
cleanup()
|
||||
}()
|
||||
|
||||
client, err := docker.NewEnvClient()
|
||||
if err != nil {
|
||||
log.Fatalf("error starting docker client: %s", err)
|
||||
|
@ -60,3 +70,9 @@ func main() {
|
|||
syncAndListenForEvents(client)
|
||||
}
|
||||
}
|
||||
|
||||
func cleanup() {
|
||||
log.Info("cleaning up hosts file")
|
||||
writeToEtcHosts(ipsToNamesMap{})
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue