summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2023-11-09 13:55:16 -0500
committerMalfurious <m@lfurio.us>2023-11-15 23:11:08 -0500
commit8ead8ec8ac5e4bad5d4f03de005f89212fd8a495 (patch)
treeab1e645a8b61a76332ef37308470f7dfd6aef094
parent453c2a4f37bdf6b061f54a075e7ff4b80d805fe8 (diff)
downloadcychedelic-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>
-rw-r--r--dmt/Dockerfile1
-rwxr-xr-xdmt/dmt36
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"]
diff --git a/dmt/dmt b/dmt/dmt
new file mode 100755
index 0000000..9de6e37
--- /dev/null
+++ b/dmt/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