From de702414b9c62595d4daee5598f9d45ac0f70862 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Mon, 9 May 2022 09:29:39 -0700 Subject: [PATCH] moving all filesystem references to /scrutiny to /opt/scrutiny fixes #230 --- CONTRIBUTING.md | 4 +-- README.md | 10 +++--- .../collector-metrics/collector-metrics.go | 4 +-- docker/Dockerfile | 32 +++++++++---------- docker/Dockerfile.collector | 10 +++--- docker/Dockerfile.web | 26 +++++++-------- docker/docker-compose.yml | 2 +- docs/TROUBLESHOOTING_DEVICE_COLLECTOR.md | 2 +- example.collector.yaml | 2 +- example.scrutiny.yaml | 6 ++-- rootfs/etc/cron.d/scrutiny | 2 +- rootfs/etc/services.d/collector-once/run | 2 +- rootfs/etc/services.d/influxdb/run | 10 +++--- webapp/backend/cmd/scrutiny/scrutiny.go | 4 +-- webapp/backend/pkg/config/config.go | 10 +++--- 15 files changed, 63 insertions(+), 63 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e4730dc..8683e89 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,14 +6,14 @@ There are multiple ways to develop on the scrutiny codebase locally. The two mos ## Docker Development ``` -docker build -f docker/Dockerfile . -t analogj/scrutiny +docker build -f docker/Dockerfile . -t chcr.io/analogj/scrutiny:master-omnibus docker run -it --rm -p 8080:8080 \ -v /run/udev:/run/udev:ro \ --cap-add SYS_RAWIO \ --device=/dev/sda \ --device=/dev/sdb \ ghcr.io/analogj/scrutiny:master-omnibus -/scrutiny/bin/scrutiny-collector-metrics run +/opt/scrutiny/bin/scrutiny-collector-metrics run ``` diff --git a/README.md b/README.md index e29e5c7..2bebda4 100644 --- a/README.md +++ b/README.md @@ -72,8 +72,8 @@ If you're using Docker, getting started is as simple as running the following co ```bash docker run -it --rm -p 8080:8080 \ - -v `pwd`/scrutiny:/scrutiny/config \ - -v `pwd`/influxdb2:/scrutiny/influxdb \ + -v `pwd`/scrutiny:/opt/scrutiny/config \ + -v `pwd`/influxdb2:/opt/scrutiny/influxdb \ -v /run/udev:/run/udev:ro \ --cap-add SYS_RAWIO \ --device=/dev/sda \ @@ -102,7 +102,7 @@ docker run --rm -p 8086:8086 \ influxdb:2.2 docker run --rm -p 8080:8080 \ - -v `pwd`/scrutiny:/scrutiny/config \ + -v `pwd`/scrutiny:/opt/scrutiny/config \ --name scrutiny-web \ ghcr.io/analogj/scrutiny:master-web @@ -135,11 +135,11 @@ For users of the docker Hub/Spoke deployment or manual install: initially the da After the first collector run, you'll be greeted with a list of all your hard drives and their current smart status. ```bash -docker exec scrutiny /scrutiny/bin/scrutiny-collector-metrics run +docker exec scrutiny /opt/scrutiny/bin/scrutiny-collector-metrics run ``` # Configuration -By default Scrutiny looks for its YAML configuration files in `/scrutiny/config` +By default Scrutiny looks for its YAML configuration files in `/opt/scrutiny/config` There are two configuration files available: diff --git a/collector/cmd/collector-metrics/collector-metrics.go b/collector/cmd/collector-metrics/collector-metrics.go index cbf11a1..d06be83 100644 --- a/collector/cmd/collector-metrics/collector-metrics.go +++ b/collector/cmd/collector-metrics/collector-metrics.go @@ -29,8 +29,8 @@ func main() { } //we're going to load the config file manually, since we need to validate it. - err = config.ReadConfig("/scrutiny/config/collector.yaml") // Find and read the config file - if _, ok := err.(errors.ConfigFileMissingError); ok { // Handle errors reading the config file + err = config.ReadConfig("/opt/scrutiny/config/collector.yaml") // Find and read the config file + if _, ok := err.(errors.ConfigFileMissingError); ok { // Handle errors reading the config file //ignore "could not find config file" } else if err != nil { os.Exit(1) diff --git a/docker/Dockerfile b/docker/Dockerfile index 1939676..46b6bf9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -16,22 +16,22 @@ FROM node:lts-slim as frontendbuild #reduce logging, disable angular-cli analytics for ci environment ENV NPM_CONFIG_LOGLEVEL=warn NG_CLI_ANALYTICS=false -WORKDIR /scrutiny/src -COPY webapp/frontend /scrutiny/src +WORKDIR /opt/scrutiny/src +COPY webapp/frontend /opt/scrutiny/src RUN npm install -g @angular/cli@9.1.4 && \ mkdir -p /scrutiny/dist && \ npm install && \ - ng build --output-path=/scrutiny/dist --deploy-url="/web/" --base-href="/web/" --prod + ng build --output-path=/opt/scrutiny/dist --deploy-url="/web/" --base-href="/web/" --prod ######## FROM ubuntu:bionic as runtime ARG TARGETARCH EXPOSE 8080 -WORKDIR /scrutiny -ENV PATH="/scrutiny/bin:${PATH}" -ENV INFLUXD_CONFIG_PATH=/scrutiny/influxdb +WORKDIR /opt/scrutiny +ENV PATH="/opt/scrutiny/bin:${PATH}" +ENV INFLUXD_CONFIG_PATH=/opt/scrutiny/influxdb RUN apt-get update && apt-get install -y cron smartmontools=7.0-0ubuntu1~ubuntu18.04.1 ca-certificates curl tzdata \ && update-ca-certificates \ @@ -48,18 +48,18 @@ RUN dpkg -i /tmp/influxdb2-2.2.0-${TARGETARCH}.deb && rm -rf /tmp/influxdb2-2.2. 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/ -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 && \ +COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny /opt/scrutiny/bin/ +COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-selftest /opt/scrutiny/bin/ +COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-metrics /opt/scrutiny/bin/ +COPY --from=frontendbuild /opt/scrutiny/dist /opt/scrutiny/web +RUN chmod +x /opt/scrutiny/bin/scrutiny && \ + chmod +x /opt/scrutiny/bin/scrutiny-collector-selftest && \ + chmod +x /opt/scrutiny/bin/scrutiny-collector-metrics && \ chmod 0644 /etc/cron.d/scrutiny && \ rm -f /etc/cron.daily/* && \ - mkdir -p /scrutiny/web && \ - mkdir -p /scrutiny/config && \ - chmod -R ugo+rwx /scrutiny/config + mkdir -p /opt/scrutiny/web && \ + mkdir -p /opt/scrutiny/config && \ + chmod -R ugo+rwx /opt/scrutiny/config CMD ["/init"] diff --git a/docker/Dockerfile.collector b/docker/Dockerfile.collector index 76bf838..d1cb698 100644 --- a/docker/Dockerfile.collector +++ b/docker/Dockerfile.collector @@ -12,16 +12,16 @@ RUN go mod vendor && \ ######## FROM ubuntu:bionic as runtime WORKDIR /scrutiny -ENV PATH="/scrutiny/bin:${PATH}" +ENV PATH="/opt/scrutiny/bin:${PATH}" RUN apt-get update && apt-get install -y cron smartmontools=7.0-0ubuntu1~ubuntu18.04.1 ca-certificates tzdata && 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 && \ +COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-selftest /opt/scrutiny/bin/ +COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny-collector-metrics /opt/scrutiny/bin/ +RUN chmod +x /opt/scrutiny/bin/scrutiny-collector-selftest && \ + chmod +x /opt/scrutiny/bin/scrutiny-collector-metrics && \ chmod +x /entrypoint-collector.sh && \ chmod 0644 /etc/cron.d/scrutiny && \ rm -f /etc/cron.daily/apt /etc/cron.daily/dpkg /etc/cron.daily/passwd diff --git a/docker/Dockerfile.web b/docker/Dockerfile.web index e942b5f..8307f01 100644 --- a/docker/Dockerfile.web +++ b/docker/Dockerfile.web @@ -14,27 +14,27 @@ FROM node:lts-slim as frontendbuild #reduce logging, disable angular-cli analytics for ci environment ENV NPM_CONFIG_LOGLEVEL=warn NG_CLI_ANALYTICS=false -WORKDIR /scrutiny/src -COPY webapp/frontend /scrutiny/src +WORKDIR /opt/scrutiny/src +COPY webapp/frontend /opt/scrutiny/src RUN npm install -g @angular/cli@9.1.4 && \ - mkdir -p /scrutiny/dist && \ + mkdir -p /opt/scrutiny/dist && \ npm install && \ - ng build --output-path=/scrutiny/dist --deploy-url="/web/" --base-href="/web/" --prod + ng build --output-path=/opt/scrutiny/dist --deploy-url="/web/" --base-href="/web/" --prod ######## FROM ubuntu:bionic as runtime EXPOSE 8080 -WORKDIR /scrutiny -ENV PATH="/scrutiny/bin:${PATH}" +WORKDIR /opt/scrutiny +ENV PATH="/opt/scrutiny/bin:${PATH}" RUN apt-get update && apt-get install -y ca-certificates curl tzdata && update-ca-certificates -COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny /scrutiny/bin/ -COPY --from=frontendbuild /scrutiny/dist /scrutiny/web -RUN chmod +x /scrutiny/bin/scrutiny && \ - mkdir -p /scrutiny/web && \ - mkdir -p /scrutiny/config && \ - chmod -R ugo+rwx /scrutiny/config -CMD ["/scrutiny/bin/scrutiny", "start"] +COPY --from=backendbuild /go/src/github.com/analogj/scrutiny/scrutiny /opt/scrutiny/bin/ +COPY --from=frontendbuild /opt/scrutiny/dist /opt/scrutiny/web +RUN chmod +x /opt/scrutiny/bin/scrutiny && \ + mkdir -p /opt/scrutiny/web && \ + mkdir -p /opt/scrutiny/config && \ + chmod -R ugo+rwx /opt/scrutiny/config +CMD ["/opt/scrutiny/bin/scrutiny", "start"] diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index e610919..7cba636 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -10,7 +10,7 @@ services: - "8080:8080" volumes: - /run/udev:/run/udev:ro - - ./config:/scrutiny/config + - ./config:/opt/scrutiny/config - ./influxdb:/var/lib/influxdb2 devices: - "/dev/sda" diff --git a/docs/TROUBLESHOOTING_DEVICE_COLLECTOR.md b/docs/TROUBLESHOOTING_DEVICE_COLLECTOR.md index 73eb4b0..50858f4 100644 --- a/docs/TROUBLESHOOTING_DEVICE_COLLECTOR.md +++ b/docs/TROUBLESHOOTING_DEVICE_COLLECTOR.md @@ -64,7 +64,7 @@ using a collector config file. See [example.collector.yaml](/example.collector.y > If you're unsure, run `smartctl --scan` on your host, and pass all listed devices to the container. ```yaml -# /scrutiny/config/collector.yaml +# /opt/scrutiny/config/collector.yaml devices: # Dell PERC/Broadcom Megaraid example: https://github.com/AnalogJ/scrutiny/issues/30 - device: /dev/bus/0 diff --git a/example.collector.yaml b/example.collector.yaml index 8cf7abc..113aebf 100644 --- a/example.collector.yaml +++ b/example.collector.yaml @@ -1,6 +1,6 @@ # Commented Scrutiny Configuration File # -# The default location for this file is /scrutiny/config/collector.yaml. +# The default location for this file is /opt/scrutiny/config/collector.yaml. # In some cases to improve clarity default values are specified, # uncommented. Other example values are commented out. # diff --git a/example.scrutiny.yaml b/example.scrutiny.yaml index 2fbe455..587885b 100644 --- a/example.scrutiny.yaml +++ b/example.scrutiny.yaml @@ -1,6 +1,6 @@ # Commented Scrutiny Configuration File # -# The default location for this file is /scrutiny/config/scrutiny.yaml. +# The default location for this file is /opt/scrutiny/config/scrutiny.yaml. # In some cases to improve clarity default values are specified, # uncommented. Other example values are commented out. # @@ -22,10 +22,10 @@ web: host: 0.0.0.0 database: # can also set absolute path here - location: /scrutiny/config/scrutiny.db + location: /opt/scrutiny/config/scrutiny.db src: frontend: - path: /scrutiny/web + path: /opt/scrutiny/web influxdb: host: 0.0.0.0 port: 8086 diff --git a/rootfs/etc/cron.d/scrutiny b/rootfs/etc/cron.d/scrutiny index f112b8e..2ba9927 100644 --- a/rootfs/etc/cron.d/scrutiny +++ b/rootfs/etc/cron.d/scrutiny @@ -11,5 +11,5 @@ MAILTO="" # correctly route collector logs (STDOUT & STDERR) to Cron foreground (collectable by Docker STDOUT) # cron schedule to run daily at midnight: '0 0 * * *' # System environmental variables are stripped by cron, source our dump of the docker environmental variables before each command (/env.sh) -{COLLECTOR_CRON_SCHEDULE} root . /env.sh; /scrutiny/bin/scrutiny-collector-metrics run >/proc/1/fd/1 2>/proc/1/fd/2 +{COLLECTOR_CRON_SCHEDULE} root . /env.sh; /opt/scrutiny/bin/scrutiny-collector-metrics run >/proc/1/fd/1 2>/proc/1/fd/2 # An empty line is required at the end of this file for a valid cron file. diff --git a/rootfs/etc/services.d/collector-once/run b/rootfs/etc/services.d/collector-once/run index 02ac223..7bd73e8 100644 --- a/rootfs/etc/services.d/collector-once/run +++ b/rootfs/etc/services.d/collector-once/run @@ -10,4 +10,4 @@ s6-svc -O /var/run/s6/services/collector-once until $(curl --output /dev/null --silent --head --fail http://localhost:8080/api/health); do echo "scrutiny api not ready" && sleep 5; done echo "starting scrutiny collector" -/scrutiny/bin/scrutiny-collector-metrics run +/opt/scrutiny/bin/scrutiny-collector-metrics run diff --git a/rootfs/etc/services.d/influxdb/run b/rootfs/etc/services.d/influxdb/run index d30ad11..99cf1e1 100644 --- a/rootfs/etc/services.d/influxdb/run +++ b/rootfs/etc/services.d/influxdb/run @@ -1,13 +1,13 @@ #!/usr/bin/with-contenv bash -mkdir -p /scrutiny/influxdb/ +mkdir -p /opt/scrutiny/influxdb/ -if [ -f "/scrutiny/influxdb/config.yaml" ]; then +if [ -f "/opt/scrutiny/influxdb/config.yaml" ]; then echo "influxdb config file already exists. skipping." else -cat << 'EOF' > /scrutiny/influxdb/config.yaml -bolt-path: /scrutiny/influxdb/influxd.bolt -engine-path: /scrutiny/influxdb/engine +cat << 'EOF' > /opt/scrutiny/influxdb/config.yaml +bolt-path: /opt/scrutiny/influxdb/influxd.bolt +engine-path: /opt/scrutiny/influxdb/engine http-bind-address: ":8086" reporting-disabled: true EOF diff --git a/webapp/backend/cmd/scrutiny/scrutiny.go b/webapp/backend/cmd/scrutiny/scrutiny.go index b02475e..103fd6b 100644 --- a/webapp/backend/cmd/scrutiny/scrutiny.go +++ b/webapp/backend/cmd/scrutiny/scrutiny.go @@ -27,8 +27,8 @@ func main() { } //we're going to load the config file manually, since we need to validate it. - err = config.ReadConfig("/scrutiny/config/scrutiny.yaml") // Find and read the config file - if _, ok := err.(errors.ConfigFileMissingError); ok { // Handle errors reading the config file + err = config.ReadConfig("/opt/scrutiny/config/scrutiny.yaml") // Find and read the config file + if _, ok := err.(errors.ConfigFileMissingError); ok { // Handle errors reading the config file //ignore "could not find config file" } else if err != nil { os.Exit(1) diff --git a/webapp/backend/pkg/config/config.go b/webapp/backend/pkg/config/config.go index 14d26a3..71de1be 100644 --- a/webapp/backend/pkg/config/config.go +++ b/webapp/backend/pkg/config/config.go @@ -30,8 +30,8 @@ func (c *configuration) Init() error { //set defaults c.SetDefault("web.listen.port", "8080") c.SetDefault("web.listen.host", "0.0.0.0") - c.SetDefault("web.src.frontend.path", "/scrutiny/web") - c.SetDefault("web.database.location", "/scrutiny/config/scrutiny.db") + c.SetDefault("web.src.frontend.path", "/opt/scrutiny/web") + c.SetDefault("web.database.location", "/opt/scrutiny/config/scrutiny.db") c.SetDefault("log.level", "INFO") c.SetDefault("log.file", "") @@ -49,9 +49,9 @@ func (c *configuration) Init() error { //c.SetDefault("disks.include", []string{}) //c.SetDefault("disks.exclude", []string{}) - //c.SetDefault("notify.metric.script", "/scrutiny/config/notify-metrics.sh") - //c.SetDefault("notify.long.script", "/scrutiny/config/notify-long-test.sh") - //c.SetDefault("notify.short.script", "/scrutiny/config/notify-short-test.sh") + //c.SetDefault("notify.metric.script", "/opt/scrutiny/config/notify-metrics.sh") + //c.SetDefault("notify.long.script", "/opt/scrutiny/config/notify-long-test.sh") + //c.SetDefault("notify.short.script", "/opt/scrutiny/config/notify-short-test.sh") //c.SetDefault("collect.metric.enable", true) //c.SetDefault("collect.metric.command", "-a -o on -S on")