add process to send HUP signals to docker on config updates

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
Justin Cormack 2016-01-22 11:58:38 +00:00
parent 2fc1137a74
commit b8e4dd03dd
5 changed files with 110 additions and 0 deletions

1
alpine/packages/hupper/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
hupper

View File

@ -0,0 +1,15 @@
FROM golang:alpine
RUN apk update && apk upgrade && apk add git
RUN mkdir -p /go/src/hupper
WORKDIR /go/src/hupper
COPY . /go/src/hupper/
ARG GOARCH
ARG GOOS
RUN go get && go install
RUN [ -f /go/bin/*/hupper ] && mv /go/bin/*/hupper /go/bin/ || true

View File

@ -0,0 +1,10 @@
all: hupper
hupper: Dockerfile main.go
docker build --build-arg GOOS=$(OS) --build-arg GOARCH=$(ARCH) -t hupper:build .
docker run hupper:build cat /go/bin/hupper > hupper
chmod 755 hupper
clean:
rm -f hupper
docker images -q hupper:build | xargs docker rmi -f

View File

@ -0,0 +1,39 @@
#!/sbin/openrc-run
description="docker config update manager"
depend()
{
need 9pinit docker
}
start()
{
[ -d /Database ] || exit 0
ebegin "Starting docker config update manager"
[ -n "${PIDFILE}" ] || PIDFILE=/var/run/hupper.pid
start-stop-daemon --start --quiet \
--background \
--exec /bin/hupper \
--make-pidfile --pidfile ${PIDFILE} \
--
eend $? "Failed to start hupper"
}
stop()
{
[ -d /Databse ] || exit 0
ebegin "Stopping docker config update manager"
[ -n "${PIDFILE}" ] || PIDFILE=/var/run/hupper.pid
start-stop-daemon --stop --quiet --pidfile ${PIDFILE}
eend $? "Failed to stop hupper"
}

View File

@ -0,0 +1,45 @@
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"strconv"
"syscall"
)
var (
path string
pidfile string
)
func init() {
flag.StringVar(&path, "path", "/Database/branch/master/watch/com.docker.driver.amd64-linux.node/etc.node/docker.node/daemon.json.node/tree.live", "path of the file to watch")
flag.StringVar(&pidfile, "pidfile", "/run/docker.pid", "pidfile for process to signal")
}
func main() {
log.SetFlags(0)
flag.Parse()
watch, err := os.Open(path)
if err != nil {
log.Fatalln("Failed to open file", path, err)
}
buf := make([]byte, 512)
for {
_, err := watch.Read(buf)
if err != nil {
log.Fatalln("Error reading watch file", err)
}
bytes, err := ioutil.ReadFile(pidfile)
pidstring := string(bytes[:])
if err != nil {
pid, err := strconv.Atoi(pidstring)
if err != nil {
syscall.Kill(pid, syscall.SIGHUP)
}
}
}
}