mirror of
https://github.com/costela/docker-etchosts.git
synced 2025-05-11 09:55:48 +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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
docker "docker.io/go-docker"
|
docker "docker.io/go-docker"
|
||||||
|
|
||||||
|
@ -48,6 +51,13 @@ func main() {
|
||||||
|
|
||||||
log.SetLevel(logLevelMap[strings.ToLower(config.LogLevel)])
|
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()
|
client, err := docker.NewEnvClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("error starting docker client: %s", err)
|
log.Fatalf("error starting docker client: %s", err)
|
||||||
|
@ -60,3 +70,9 @@ func main() {
|
||||||
syncAndListenForEvents(client)
|
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