@rizom/ops 0.2.0-alpha.259 → 0.2.0-alpha.260

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rizom/ops",
3
- "version": "0.2.0-alpha.259",
3
+ "version": "0.2.0-alpha.260",
4
4
  "description": "Operator CLI for managing private brain fleet registry repos",
5
5
  "keywords": [
6
6
  "brains",
@@ -4,6 +4,10 @@ const WATCHDOG_PATH = "/usr/local/sbin/brains-health-watchdog";
4
4
  const SERVICE_PATH = "/etc/systemd/system/brains-health-watchdog.service";
5
5
  const TIMER_PATH = "/etc/systemd/system/brains-health-watchdog.timer";
6
6
 
7
+ export const BRAIN_WATCHDOG_LABEL = "ai.rizom.brain.watchdog";
8
+ export const BRAIN_WATCHDOG_LABEL_VALUE = "true";
9
+ export const BRAIN_WATCHDOG_LABEL_FILTER: string = `${BRAIN_WATCHDOG_LABEL}=${BRAIN_WATCHDOG_LABEL_VALUE}`;
10
+
7
11
  export const healthWatchdogScript: string = `#!/usr/bin/env bash
8
12
  set -euo pipefail
9
13
  umask 077
@@ -26,7 +30,7 @@ while read -r container_id; do
26
30
  [ -n "$container_id" ] || continue
27
31
  service_name=$(docker inspect --format '{{ index .Config.Labels "service" }}' "$container_id" 2>/dev/null || true)
28
32
  container_name=$(docker inspect --format '{{ .Name }}' "$container_id" 2>/dev/null | tr -d '/' || true)
29
- state_key=$(printf '%s-%s' "$service_name" "$container_name" | tr -c 'A-Za-z0-9_.-' '_')
33
+ state_key=$(printf '%s-%s-%s' "$service_name" "$container_name" "$container_id" | tr -c 'A-Za-z0-9_.-' '_')
30
34
  state_path="$state_dir/$state_key.restarts"
31
35
  recent_path="$state_path.tmp"
32
36
  now_epoch=$(date -u +%s)
@@ -62,7 +66,7 @@ while read -r container_id; do
62
66
 
63
67
  logger -t brains-health-watchdog "restarting unhealthy container=$container_name service=$service_name incident=$incident_path"
64
68
  docker restart "$container_id"
65
- done < <(docker ps --filter health=unhealthy --filter label=service --format '{{.ID}}')
69
+ done < <(docker ps --filter health=unhealthy --filter label=${BRAIN_WATCHDOG_LABEL_FILTER} --format '{{.ID}}')
66
70
  `;
67
71
 
68
72
  export const healthWatchdogServiceUnit: string = `[Unit]
@@ -108,6 +112,13 @@ ${installCommand(TIMER_PATH, healthWatchdogTimerUnit, "0644")}
108
112
 
109
113
  $SUDO systemctl daemon-reload
110
114
  $SUDO systemctl enable --now brains-health-watchdog.timer
115
+
116
+ labelled_containers=""
117
+ if ! labelled_containers=$($SUDO docker ps --filter label=${BRAIN_WATCHDOG_LABEL_FILTER} --format '{{.ID}}' 2>/dev/null); then
118
+ echo "Warning: unable to verify running Brain containers with label ${BRAIN_WATCHDOG_LABEL_FILTER}." >&2
119
+ elif [ -z "$labelled_containers" ]; then
120
+ echo "Warning: no running Brain containers found with label ${BRAIN_WATCHDOG_LABEL_FILTER}." >&2
121
+ fi
111
122
  `;
112
123
  }
113
124