2015-05-22 20:37:40 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-09-30 03:21:17 +02:00
|
|
|
"github.com/samalba/dockerclient"
|
2015-05-22 20:37:40 +02:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
func eventCallback(e *dockerclient.Event, ec chan error, args ...interface{}) {
|
|
|
|
log.Println(e)
|
|
|
|
}
|
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
var (
|
|
|
|
client *dockerclient.DockerClient
|
|
|
|
)
|
|
|
|
|
2015-05-22 20:37:40 +02:00
|
|
|
func waitForInterrupt() {
|
|
|
|
sigChan := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
|
|
|
|
for _ = range sigChan {
|
2015-09-30 03:21:17 +02:00
|
|
|
client.StopAllMonitorEvents()
|
2015-05-22 20:37:40 +02:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
docker, err := dockerclient.NewDockerClient(os.Getenv("DOCKER_HOST"), nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
client = docker
|
|
|
|
|
|
|
|
client.StartMonitorEvents(eventCallback, nil)
|
2015-05-22 20:37:40 +02:00
|
|
|
|
|
|
|
waitForInterrupt()
|
|
|
|
}
|