diff --git a/Dockerfile b/Dockerfile index 59c5898..aa3e844 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,36 @@ -FROM sutty/monit:latest +FROM sutty/daemonize:latest AS build MAINTAINER "f " + +ARG VERSION=1.2.2 + +RUN wget https://github.com/syncthing/syncthing/releases/download/v${VERSION}/syncthing-linux-amd64-v${VERSION}.tar.gz +RUN tar x -Of syncthing-linux-amd64-v${VERSION}.tar.gz syncthing-linux-amd64-v${VERSION}/syncthing \ + > /usr/local/bin/syncthing +RUN chmod +x /usr/local/bin/syncthing +RUN strip --strip-all /usr/local/bin/syncthing + +COPY ./syncthing_stop.sh /usr/local/bin/syncthing_stop +COPY ./syncthing_start.sh /usr/local/bin/syncthing_start +RUN chmod 755 /usr/local/bin/syncthing_stop /usr/local/bin/syncthing_start + +RUN echo /home/builder/packages/home > /etc/apk/repositories +RUN apk add --no-cache daemonize + +FROM sutty/monit:latest + +COPY --from=build /usr/local/bin/syncthing /usr/local/bin/syncthing +COPY --from=build /usr/local/bin/syncthing_stop /usr/local/bin/syncthing_stop +COPY --from=build /usr/local/bin/syncthing_start /usr/local/bin/syncthing_start +COPY --from=build /usr/sbin/daemonize /usr/sbin/daemonize +COPY ./monit.conf /etc/monit.d/syncthing.conf + +RUN addgroup -S syncthing +RUN adduser -s /bin/sh -G syncthing -S -h /home/syncthing syncthing +RUN monit -t + +RUN apk add --no-cache ca-certificates + +EXPOSE 22000 +EXPOSE 22000/udp + +VOLUME /home/syncthing diff --git a/monit.conf b/monit.conf new file mode 100644 index 0000000..993cdc9 --- /dev/null +++ b/monit.conf @@ -0,0 +1,3 @@ +check process syncthing with pidfile /tmp/syncthing.pid + start program = "/usr/local/bin/syncthing_start" as uid "syncthing" + stop program = "/usr/local/bin/syncthing_stop" diff --git a/syncthing_start.sh b/syncthing_start.sh new file mode 100644 index 0000000..461c61e --- /dev/null +++ b/syncthing_start.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +daemonize -p /tmp/syncthing.pid -l /tmp/syncthing.pid \ +/usr/local/bin/syncthing -no-browser \ + -logfile="/home/syncthing/syncthing.log" \ + -gui-address="http://0.0.0.0:8443" diff --git a/syncthing_stop.sh b/syncthing_stop.sh new file mode 100644 index 0000000..0e59585 --- /dev/null +++ b/syncthing_stop.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +ps aux | grep syncthing | tr -s " " | cut -d " " -f 2 | xargs kill