From 011642a70889547901d0a8a91e88006849291b17 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Sat, 24 Apr 2021 12:27:09 -0700 Subject: [PATCH] WIP. Removed references to Jobber, replaced with Cron. Created crontab at /etc/cron.d/scrutiny Running cron in foreground. Adding timezone support Working Collector image (untested master). --- .dockerignore | 6 ++++ docker/Dockerfile | 12 ++++---- docker/Dockerfile.collector | 16 +++++----- docker/entrypoint-collector.sh | 9 ++++++ rootfs/etc/cont-init.d/01-timezone | 7 +++++ rootfs/etc/cron.d/scrutiny | 15 ++++++++++ rootfs/etc/services.d/{jobber => cron}/finish | 2 +- rootfs/etc/services.d/cron/run | 10 +++++++ rootfs/etc/services.d/jobber/run | 5 ---- rootfs/scrutiny/.gitinclude | 0 rootfs/scrutiny/jobber/jobber.yaml | 30 ------------------- 11 files changed, 60 insertions(+), 52 deletions(-) create mode 100644 .dockerignore create mode 100755 docker/entrypoint-collector.sh create mode 100644 rootfs/etc/cont-init.d/01-timezone create mode 100644 rootfs/etc/cron.d/scrutiny rename rootfs/etc/services.d/{jobber => cron}/finish (70%) create mode 100644 rootfs/etc/services.d/cron/run delete mode 100644 rootfs/etc/services.d/jobber/run create mode 100644 rootfs/scrutiny/.gitinclude delete mode 100644 rootfs/scrutiny/jobber/jobber.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..161765d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +/dist +/vendor +/.idea +/.github +/.git +/webapp/frontend/node_modules diff --git a/docker/Dockerfile b/docker/Dockerfile index 43dc873..5409a22 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -31,15 +31,13 @@ EXPOSE 8080 WORKDIR /scrutiny ENV PATH="/scrutiny/bin:${PATH}" -ADD https://github.com/dshearer/jobber/releases/download/v1.4.4/jobber_1.4.4-1_amd64.deb /tmp/ -RUN apt install /tmp/jobber_1.4.4-1_amd64.deb - -RUN apt-get update && apt-get install -y smartmontools=7.0-0ubuntu1~ubuntu18.04.1 ca-certificates curl && update-ca-certificates +RUN apt-get update && apt-get install -y cron smartmontools=7.0-0ubuntu1~ubuntu18.04.1 ca-certificates curl && update-ca-certificates ADD https://github.com/just-containers/s6-overlay/releases/download/v1.21.8.0/s6-overlay-amd64.tar.gz /tmp/ RUN tar xzf /tmp/s6-overlay-amd64.tar.gz -C / COPY /rootfs / +COPY /rootfs/etc/cron.d/scrutiny /etc/cron.d/scrutiny COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny /scrutiny/bin/ COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-selftest /scrutiny/bin/ COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-metrics /scrutiny/bin/ @@ -47,11 +45,11 @@ COPY --from=frontendbuild /scrutiny/dist /scrutiny/web RUN chmod +x /scrutiny/bin/scrutiny && \ chmod +x /scrutiny/bin/scrutiny-collector-selftest && \ chmod +x /scrutiny/bin/scrutiny-collector-metrics && \ + chmod 0644 /etc/cron.d/scrutiny && \ + rm -f /etc/cron.daily/* && \ mkdir -p /scrutiny/web && \ mkdir -p /scrutiny/config && \ - mkdir -p /scrutiny/jobber && \ - chmod -R ugo+rwx /scrutiny/config && \ - chmod -R ugo+rwx /scrutiny/jobber + chmod -R ugo+rwx /scrutiny/config CMD ["/init"] diff --git a/docker/Dockerfile.collector b/docker/Dockerfile.collector index 6899899..5d67b5d 100644 --- a/docker/Dockerfile.collector +++ b/docker/Dockerfile.collector @@ -11,20 +11,18 @@ RUN go mod vendor && \ ######## FROM ubuntu:bionic as runtime -EXPOSE 8080 WORKDIR /scrutiny ENV PATH="/scrutiny/bin:${PATH}" -ADD https://github.com/dshearer/jobber/releases/download/v1.4.4/jobber_1.4.4-1_amd64.deb /tmp/ -RUN apt install /tmp/jobber_1.4.4-1_amd64.deb - -RUN apt-get update && apt-get install -y smartmontools=7.0-0ubuntu1~ubuntu18.04.1 ca-certificates && update-ca-certificates - -COPY /rootfs/scrutiny /scrutiny +RUN apt-get update && apt-get install -y cron smartmontools=7.0-0ubuntu1~ubuntu18.04.1 ca-certificates && update-ca-certificates +COPY /docker/entrypoint-collector.sh /entrypoint-collector.sh +COPY /rootfs/etc/cron.d/scrutiny /etc/cron.d/scrutiny COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-selftest /scrutiny/bin/ COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-metrics /scrutiny/bin/ RUN chmod +x /scrutiny/bin/scrutiny-collector-selftest && \ - chmod +x /scrutiny/bin/scrutiny-collector-metrics + chmod +x /scrutiny/bin/scrutiny-collector-metrics && \ + chmod 0644 /etc/cron.d/scrutiny && \ + rm -f /etc/cron.daily/apt /etc/cron.daily/dpkg /etc/cron.daily/passwd -CMD ["/usr/lib/x86_64-linux-gnu/jobberrunner", "/scrutiny/jobber/jobber.yaml"] +CMD ["/entrypoint-collector.sh"] diff --git a/docker/entrypoint-collector.sh b/docker/entrypoint-collector.sh new file mode 100755 index 0000000..d55f5b0 --- /dev/null +++ b/docker/entrypoint-collector.sh @@ -0,0 +1,9 @@ +# Cron runs in its own isolated environment (usually using only /etc/environment ) +# So when the container starts up, we will do a dump of the runtime environment into a .env file that we +# will then source into the crontab file (/etc/cron.d/scrutiny.sh) + +printenv | sed 's/^\(.*\)$/export \1/g' > /env.sh + +# now that we have the env start cron in the foreground +echo "starting cron" +cron -f diff --git a/rootfs/etc/cont-init.d/01-timezone b/rootfs/etc/cont-init.d/01-timezone new file mode 100644 index 0000000..83fb30c --- /dev/null +++ b/rootfs/etc/cont-init.d/01-timezone @@ -0,0 +1,7 @@ +#!/usr/bin/with-contenv bash + +if [ -n "${TZ}" ] +then + ln -snf "/usr/share/zoneinfo/${TZ}" /etc/localtime + echo "${TZ}" > /etc/timezone +fi diff --git a/rootfs/etc/cron.d/scrutiny b/rootfs/etc/cron.d/scrutiny new file mode 100644 index 0000000..cc1e15a --- /dev/null +++ b/rootfs/etc/cron.d/scrutiny @@ -0,0 +1,15 @@ +# Example of job definition: +# .---------------- minute (0 - 59) +# | .------------- hour (0 - 23) +# | | .---------- day of month (1 - 31) +# | | | .------- month (1 - 12) OR jan,feb,mar,apr ... +# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat +# | | | | | +# * * * * * user-name command to be executed + +# TODO: correctly route collector logs (STDOUT & STDERR), print to Cron foreground (collectable by Docker STDOUT?) +# TODO: change cron schedule to daily at midnight: '0 0 0 * * *' +# System environmental variables are stripped by cron, source our dump of the docker environmental variables before each command +* * * * * root . /env.sh; /scrutiny/bin/scrutiny-collector-metrics run >> /var/log/scrutiny.log 2>&1 +* * * * * root date >> /var/log/cron.log +# An empty line is required at the end of this file for a valid cron file. diff --git a/rootfs/etc/services.d/jobber/finish b/rootfs/etc/services.d/cron/finish similarity index 70% rename from rootfs/etc/services.d/jobber/finish rename to rootfs/etc/services.d/cron/finish index 42c85ad..48cf194 100644 --- a/rootfs/etc/services.d/jobber/finish +++ b/rootfs/etc/services.d/cron/finish @@ -1,4 +1,4 @@ #!/usr/bin/execlineb -S0 -echo "jobber/cron exiting" +echo "cron exiting" s6-svscanctl -t /var/run/s6/services diff --git a/rootfs/etc/services.d/cron/run b/rootfs/etc/services.d/cron/run new file mode 100644 index 0000000..5687bbe --- /dev/null +++ b/rootfs/etc/services.d/cron/run @@ -0,0 +1,10 @@ +#!/usr/bin/with-contenv bash + +# Cron runs in its own isolated environment (usually using only /etc/environment ) +# So when the container starts up, we will do a dump of the runtime environment into a .env file that we +# will then source into the crontab file (/etc/cron.d/scrutiny.sh) + +printenv | sed 's/^\(.*\)$/export \1/g' > /env.sh + +echo "starting cron" +cron -f diff --git a/rootfs/etc/services.d/jobber/run b/rootfs/etc/services.d/jobber/run deleted file mode 100644 index 0408f73..0000000 --- a/rootfs/etc/services.d/jobber/run +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/with-contenv bash - -echo "starting jobber/cron" - -su -c "/usr/lib/x86_64-linux-gnu/jobberrunner /scrutiny/jobber/jobber.yaml" root diff --git a/rootfs/scrutiny/.gitinclude b/rootfs/scrutiny/.gitinclude new file mode 100644 index 0000000..e69de29 diff --git a/rootfs/scrutiny/jobber/jobber.yaml b/rootfs/scrutiny/jobber/jobber.yaml deleted file mode 100644 index 64e8b7c..0000000 --- a/rootfs/scrutiny/jobber/jobber.yaml +++ /dev/null @@ -1,30 +0,0 @@ -version: 1.4 - -prefs: - logPath: /scrutiny/jobber/log.log - runLog: - type: file - path: /scrutiny/jobber/runlog - maxFileLen: 100m - maxHistories: 2 - -resultSinks: - - &filesystemSink - type: filesystem - path: /scrutiny/jobber - data: - - stdout - - stderr - maxAgeDays: 10 - -jobs: - MetricsJob: - cmd: /scrutiny/bin/scrutiny-collector-metrics run - # run daily at midnight. - time: '0 0 0 * * *' - onError: Backoff - notifyOnSuccess: - - *filesystemSink - notifyOnFailure: - - *filesystemSink -