dev / templates / bot / deploy / install-fleet.sh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
# One-time fleet provisioning on the VPS. Run as root from /opt/ardegazu-__NAME__
# after the code is in place (rsync or git pull) and `npm install` has run.
#
#   sh deploy/install-fleet.sh                    # a fleet of one: __NAME__
#   sh deploy/install-fleet.sh __NAME__ alta treia    # a bigger fleet
#
# Creates the shared user, per-instance state dirs and seeds, cross-links the
# sibling friend links into every config, installs the units, and starts the
# fleet staggered. Existing seeds are kept — they ARE the bots' identities.
set -eu

BOTS="${*:-__NAME__}"
STATE=/var/lib/ardegazu-__NAME__
ETC=/etc/ardegazu-__NAME__
OPT=/opt/ardegazu-__NAME__

id ardegazu-__NAME__ >/dev/null 2>&1 || useradd -r -s /usr/sbin/nologin ardegazu-__NAME__

mkdir -p "$ETC" "$STATE/models"

# seeds + friend links (link.js creates a missing seed, keeps an existing one)
LINKS=""
for b in $BOTS; do
  mkdir -p "$STATE/$b"
  link=$(node "$OPT/dist/fleet/link.js" "$STATE/$b/seed" "$b")
  echo "$b: $link"
  LINKS="$LINKS $b=$link"
done

# the matchmaker needs partners: enable it only for a fleet of two or more
# (games stays [] until a learned/hostable game is added — see the docs)
N=0
for b in $BOTS; do N=$((N + 1)); done
MM=false
[ "$N" -ge 2 ] && MM=true

# per-instance configs: every bot lists the other bots' links as siblings
for b in $BOTS; do
  sibs=""
  for kv in $LINKS; do
    n=${kv%%=*}; l=${kv#*=}
    [ "$n" = "$b" ] && continue
    frag="#${l#*#}"
    sibs="$sibs\"$frag\","
  done
  sibs=${sibs%,}
  cat > "$ETC/$b.json" << EOF
{
  "name": "$b",
  "dataDir": "$STATE/$b",
  "origin": "https://chat.ardegazu.ro",
  "social": { "enabled": true, "autoAcceptFriends": true, "autoJoinInvites": true },
  "rooms": [],
  "fleet": {
    "siblings": [$sibs],
    "matchmaker": { "enabled": $MM, "games": [], "maxConcurrentSelfPlay": 1, "partners": 4 }
  },
  "learning": { "modelDir": "$STATE/models" }
}
EOF
done

cp "$OPT/deploy/ardegazu-__NAME__@.service" /etc/systemd/system/

# trainer units ship only while the bot learns (dropping RL deletes them)
TRAINER=false
if [ -f "$OPT/deploy/ardegazu-__NAME__-trainer.service" ]; then
  TRAINER=true
  cp "$OPT/deploy/ardegazu-__NAME__-trainer.service" /etc/systemd/system/
  cp "$OPT/deploy/ardegazu-__NAME__-trainer.timer" /etc/systemd/system/
  [ -f "$ETC/trainer.json" ] || cat > "$ETC/trainer.json" << EOF
{
  "modelDir": "$STATE/models",
  "episodeDirs": ["$STATE/*/episodes"]
}
EOF
fi

chown -R ardegazu-__NAME__:ardegazu-__NAME__ "$STATE"
chmod 0775 "$STATE/models"
systemctl daemon-reload

for b in $BOTS; do
  systemctl enable --now "ardegazu-__NAME__@$b"
  echo "started ardegazu-__NAME__@$b"
  sleep 20
done
[ "$TRAINER" = true ] && systemctl enable --now ardegazu-__NAME__-trainer.timer
echo "fleet up — journalctl -u 'ardegazu-__NAME__@*' -f"

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/dev.git