summaryrefslogblamecommitdiffstats
path: root/dmt/dmt
blob: 9de6e374d4a04eb7626a36fc178ba588dd15f23a (plain) (tree)



































                                                                                
#!/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