mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 17:26:28 +00:00
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:
parent
2fc1137a74
commit
b8e4dd03dd
1
alpine/packages/hupper/.gitignore
vendored
Normal file
1
alpine/packages/hupper/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
hupper
|
15
alpine/packages/hupper/Dockerfile
Normal file
15
alpine/packages/hupper/Dockerfile
Normal 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
|
10
alpine/packages/hupper/Makefile
Normal file
10
alpine/packages/hupper/Makefile
Normal 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
|
39
alpine/packages/hupper/etc/init.d/hupper
Executable file
39
alpine/packages/hupper/etc/init.d/hupper
Executable 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"
|
||||
}
|
45
alpine/packages/hupper/main.go
Normal file
45
alpine/packages/hupper/main.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user