You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
watchtower/main.go

62 lines
966 B
Go

package main // import "github.com/CenturyLinkLabs/watchtower"
import (
"fmt"
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/CenturyLinkLabs/watchtower/updater"
"github.com/codegangsta/cli"
)
var (
wg sync.WaitGroup
)
func main() {
app := cli.NewApp()
app.Name = "watchtower"
app.Usage = "Automatically update running Docker containers"
app.Action = start
app.Flags = []cli.Flag{
cli.IntFlag{
Name: "interval, i",
Value: 300,
Usage: "poll interval (in seconds)",
},
}
handleSignals()
app.Run(os.Args)
}
func handleSignals() {
// Graceful shut-down on SIGINT/SIGTERM
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
go func() {
<-c
wg.Wait()
os.Exit(1)
}()
}
func start(c *cli.Context) {
secs := time.Duration(c.Int("interval")) * time.Second
for {
wg.Add(1)
if err := updater.Run(); err != nil {
fmt.Println(err)
}
wg.Done()
time.Sleep(secs)
}
}