Make hupper watch for proxy changes too

Signed-off-by: Dave Tucker <dt@docker.com>
This commit is contained in:
Dave Tucker 2016-05-17 09:04:56 +01:00
parent 7318e24b87
commit bbd7a761cf
2 changed files with 65 additions and 40 deletions

View File

@ -13,16 +13,18 @@ start()
PIDFILE=/run/hupper.pid PIDFILE=/run/hupper.pid
DOCKERPIDFILE=/run/docker.pid DOCKERPIDFILE=/run/docker.pid
WATCH=$(mobyconfig watch /etc/docker/daemon.json) WATCH_CONFIG=$(mobyconfig watch /etc/docker/daemon.json)
WATCH_PROXY=$(mobyconfig watch proxy)
[ -z "${WATCH}" ] && exit 1 [ -z "${WATCH_CONFIG}" ] && exit 1
[ -z "${WATCH_PROXY}" ] && exit 1
start-stop-daemon --start --quiet \ start-stop-daemon --start --quiet \
--background \ --background \
--exec /bin/hupper \ --exec /bin/hupper \
--make-pidfile --pidfile ${PIDFILE} \ --make-pidfile --pidfile ${PIDFILE} \
-- -pidfile ${PIDFILE} -huppidfile ${DOCKERPIDFILE} \ -- -pidfile ${PIDFILE} -huppidfile ${DOCKERPIDFILE} \
-path ${WATCH} -path ${WATCH_CONFIG} -path ${WATCH_PROXY}
eend $? "Failed to start hupper" eend $? "Failed to start hupper"
} }

View File

@ -2,23 +2,36 @@ package main
import ( import (
"flag" "flag"
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"os/exec" "os/exec"
"strconv" "strconv"
"sync"
"syscall" "syscall"
) )
var ( var (
path string paths stringSlice
huppidfile string huppidfile string
pidfile string pidfile string
) )
type stringSlice []string
func (s *stringSlice) String() string {
return fmt.Sprintf("%s", *s)
}
func (s *stringSlice) Set(value string) error {
*s = append(*s, value)
return nil
}
func init() { func init() {
flag.StringVar(&path, "path", "", "path of the file to watch") flag.Var(&paths, "path", "paths of the files to watch")
flag.StringVar(&huppidfile, "huppidfile", "", "pidfile for process to signal") flag.StringVar(&huppidfile, "huppidfile", "", "pidfile for process to signal")
flag.StringVar(&pidfile, "pidfile", "", "my pidfile") flag.StringVar(&pidfile, "pidfile", "", "my pidfile")
} }
@ -27,7 +40,7 @@ func main() {
log.SetFlags(0) log.SetFlags(0)
flag.Parse() flag.Parse()
if path == "" { if len(paths) < 1 {
log.Fatal("watch path not set") log.Fatal("watch path not set")
} }
@ -41,6 +54,10 @@ func main() {
_ = ioutil.WriteFile(pidfile, pidbytes, 0644) _ = ioutil.WriteFile(pidfile, pidbytes, 0644)
} }
var wg sync.WaitGroup
wg.Add(len(paths))
for _, path := range paths {
watch, err := os.Open(path) watch, err := os.Open(path)
if err != nil { if err != nil {
log.Fatalln("Failed to open file", path, err) log.Fatalln("Failed to open file", path, err)
@ -52,6 +69,8 @@ func main() {
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
log.Fatalln("Error reading watch file", err) log.Fatalln("Error reading watch file", err)
} }
go func() {
for { for {
_, err := watch.Read(buf) _, err := watch.Read(buf)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
@ -64,6 +83,7 @@ func main() {
// however at present we cannot check changes, and most do // however at present we cannot check changes, and most do
restart := true restart := true
if restart { if restart {
log.Println("Restarting docker")
cmd := exec.Command("service", "docker", "restart") cmd := exec.Command("service", "docker", "restart")
// not much we can do if it does not restart // not much we can do if it does not restart
_ = cmd.Run() _ = cmd.Run()
@ -80,4 +100,7 @@ func main() {
syscall.Kill(pid, syscall.SIGHUP) syscall.Kill(pid, syscall.SIGHUP)
} }
} }
}()
}
wg.Wait()
} }