diff options
-rwxr-xr-x | acid/acid | 29 | ||||
-rwxr-xr-x | acid/acid-build | 2 | ||||
-rwxr-xr-x | acid/acid-remove | 4 | ||||
-rwxr-xr-x | acid/acid-source | 2 | ||||
-rw-r--r-- | docker-compose.yml | 9 |
5 files changed, 27 insertions, 19 deletions
@@ -1,9 +1,12 @@ -#!/bin/bash +#!/bin/bash -a # cychedelic ACID daemon # cychedelic is an automated Continuous Deployment solution. See the README for # more information. +CYCHE_SERVICE_DIR="/data/services" +CYCHE_LOG_DIR="/data/logs" +CYCHE_STATUS_FILE="/data/status" source config.sh now() { @@ -16,10 +19,17 @@ should_restart() { [ $runtime -gt $CYCHE_MAINT_TIME ] } +prune_logs() { + ls -A "$CYCHE_LOG_DIR" \ + | sort -n | head -n "$((CYCHE_LOG_SIZE*-1))" \ + | sed "s?^?$CYCHE_LOG_DIR/?" \ + | xargs rm -f +} + log_filename() { - latest=$(find /logs -type f | sort -rn | sed 's/^\/logs\/0*//;s/_.*$//;1q') - [ -z "$latest" ] && number="1" || number=$((latest+1)) - printf '/logs/%010i_%s_%s.log\n' "$number" "$(now)" "$1" + latest=$(ls -A "$CYCHE_LOG_DIR" | sort -rn | sed 's/_.*$//;1q') + [ -z "$latest" ] && number="0" || number=$((latest+1)) + printf '%s/%s_%s_%s.log' "$CYCHE_LOG_DIR" "$number" "$(now)" "$1" } do_job() { @@ -51,10 +61,10 @@ update() { log=$(log_filename "${arr[0]}") [ "$1" == "$forceopt" ] && f="--force" || f="" - touch /logs/active + echo "$log" >"$CYCHE_STATUS_FILE" do_job $line "$f" "$selfopt" >"$log" 2>&1 res=$? - rm -f /logs/active + truncate -s 0 "$CYCHE_STATUS_FILE" if [ $res -ne 0 ]; then echo "Updated ${arr[0]}" @@ -70,7 +80,7 @@ update() { remove() { next=$(printf '%s\n' "${CYCHE_SERVICES[@]}" | awk '{print $1}') - prev=$(ls -A '/services') + prev=$(ls -A "$CYCHE_SERVICE_DIR") removed=$(printf '%s\n' "$next" "$next" "$prev" | sort | uniq -u) for name in $removed; do @@ -85,14 +95,15 @@ remove() { # sleep briefly at the beginning to allow the previous cychedelic instance time # to die. echo "cychedelic ACID kicking in ..." -rm -f /logs/active +mkdir -p "$CYCHE_SERVICE_DIR" "$CYCHE_LOG_DIR" +truncate -s 0 "$CYCHE_STATUS_FILE" sleep "$CYCHE_STARTUP_TIME" remove update --force docker system prune --force --all -find /logs -type f | sort -n | head -n "$((CYCHE_LOG_SIZE*-1))" | xargs rm -f +prune_logs starttime=$(now) # monitor source changes diff --git a/acid/acid-build b/acid/acid-build index fd5b69d..87c281e 100755 --- a/acid/acid-build +++ b/acid/acid-build @@ -23,7 +23,7 @@ # This file exits early on any failure (non-zero). On a successful run in # `--self` mode, this file does not exit (we are killed by `compose down`). -cd "/services/$1" +cd "$CYCHE_SERVICE_DIR/$1" # For <file>, no absolute paths and no '../' if ! echo "$2" | grep -Evq '\.\.|^/'; then diff --git a/acid/acid-remove b/acid/acid-remove index 6094a23..2c96669 100755 --- a/acid/acid-remove +++ b/acid/acid-remove @@ -5,11 +5,11 @@ # Stop the service <name>, which was previously managed by cychedelic, and # remove associated files. -name=$(cat "/services/$1/.git/previous_slug") +name=$(cat "$CYCHE_SERVICE_DIR/$1/.git/previous_slug") [ -z "$name" ] && name="$1" docker compose --project-name "$name" down echo "Removing files..." -rm -rf "/services/$1" +rm -rf "$CYCHE_SERVICE_DIR/$1" echo "Done." diff --git a/acid/acid-source b/acid/acid-source index 2d507d6..29b1516 100755 --- a/acid/acid-source +++ b/acid/acid-source @@ -23,7 +23,7 @@ gethash() { "$1" # pattern } -cd '/services' +cd "$CYCHE_SERVICE_DIR" # For <name>, limit to a-z, 0-9, -, _ if ! echo "$1" | grep -Eq '^[-_a-z0-9]*$'; then diff --git a/docker-compose.yml b/docker-compose.yml index 111535f..ea05646 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,12 +5,9 @@ services: build: "acid" restart: "always" volumes: - - "logs:/logs" - - "services:/services" + - "data:/data" - "/var/run/docker.sock:/var/run/docker.sock:ro" volumes: - logs: - name: "cychedelic-logs" - services: - name: "cychedelic-services" + data: + name: "cychedelic_data" |