diff options
author | Malfurious <m@lfurio.us> | 2023-11-09 13:55:16 -0500 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2023-11-15 23:11:08 -0500 |
commit | 8ead8ec8ac5e4bad5d4f03de005f89212fd8a495 (patch) | |
tree | ab1e645a8b61a76332ef37308470f7dfd6aef094 /dmt | |
parent | 453c2a4f37bdf6b061f54a075e7ff4b80d805fe8 (diff) | |
download | cychedelic-8ead8ec8ac5e4bad5d4f03de005f89212fd8a495.tar.gz cychedelic-8ead8ec8ac5e4bad5d4f03de005f89212fd8a495.zip |
dmt: Implement API endpoint /api/status
This returns high-level information describing the current state of the
system.
The intent of the `version` field is primarily to act as a "page should
be reloaded" indicator to the front-end javascript code. This would
inform the client to reload (possibly) new markup or script whenever the
version field changes. This field could return an accurate version
spec of cychedelic or DMT, however just returns a random string at the
moment which is tied to the DMT docker image build.
Signed-off-by: Malfurious <m@lfurio.us>
Diffstat (limited to 'dmt')
-rw-r--r-- | dmt/Dockerfile | 1 | ||||
-rwxr-xr-x | dmt/dmt | 36 |
2 files changed, 37 insertions, 0 deletions
diff --git a/dmt/Dockerfile b/dmt/Dockerfile index 6d53838..f440d5e 100644 --- a/dmt/Dockerfile +++ b/dmt/Dockerfile @@ -14,6 +14,7 @@ ENV GOPATH="/usr/local" COPY . . RUN go install github.com/uriel/cgd@latest +RUN tr -dc a-z </dev/urandom | head -c 12 >/version EXPOSE 80 CMD ["cgd", "-a", ":80", "-c", "dmt"] @@ -0,0 +1,36 @@ +#!/bin/bash -a + +# cychedelic DMT daemon +# cychedelic is an automated Continuous Deployment solution. See the README for +# more information. + +CYCHE_LOG_DIR="/data/logs" +CYCHE_STATUS_FILE="/data/status" +CYCHE_VERSION_FILE="/version" + +integer() { + [ "$1" -eq "$1" ] >/dev/null 2>&1 +} + +newest_job() { + ls -A "$CYCHE_LOG_DIR" | sort -rn | head -n1 +} + +oldest_job() { + ls -A "$CYCHE_LOG_DIR" | sort -n | head -n1 +} + +api_status() { + status=$(cat "$CYCHE_STATUS_FILE") + [ "$status" == "" ] && active="false" || active="true" + integer "$status" && job="$status" || job="-1" + + printf 'Content-type: text/json\n\n{' + printf '"version":"%s",' "$(cat "$CYCHE_VERSION_FILE")" + printf '"active":%s,' "$active" + printf '"job":%i,' "$job" + printf '"newest":%i,' "$(newest_job)" + printf '"oldest":%i}' "$(oldest_job)" +} + +api_status |