-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathapi-entrypoint.sh
More file actions
56 lines (48 loc) · 2.14 KB
/
Copy pathapi-entrypoint.sh
File metadata and controls
56 lines (48 loc) · 2.14 KB
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
#!/bin/sh
set -e
# Archil disk mounts (skipped when ARCHIL_MOUNT_TOKEN is not set)
if [ -n "$ARCHIL_MOUNT_TOKEN" ]; then
echo ""
echo "=== Archil Mount ==="
# Ensure /dev/fuse exists (needed in some VM environments like Fly.io Firecracker)
if [ ! -e /dev/fuse ]; then
mknod /dev/fuse c 10 229
chmod 666 /dev/fuse
fi
# NOTE: API data disk (/mnt/data) is now a Fly volume, auto-mounted by Fly.
# No Archil mount needed for it.
if [ -n "$ARCHIL_SHARED_DISK_NAME" ]; then
echo "Mounting shared disk ($ARCHIL_SHARED_DISK_NAME) at /workspace/shared..."
mkdir -p /workspace/shared
archil mount --shared "$ARCHIL_SHARED_DISK_NAME" /workspace/shared --region "$ARCHIL_REGION"
# Pre-create top-level shared directories so that workers' mkdir
# auto-grants delegation at the SUBDIR level (e.g., thoughts/$AGENT_ID),
# not the parent level (thoughts/). Then unmount/remount to release
# the parent-level delegations this mkdir created.
echo "Pre-creating shared directory structure..."
for category in thoughts memory downloads misc; do
mkdir -p "/workspace/shared/$category" 2>/dev/null || true
# API runs as root; make dirs world-writable so worker user can
# create per-agent subdirs. Safe because Archil delegations (not
# UNIX perms) enforce write isolation between agents.
chmod 777 "/workspace/shared/$category" 2>/dev/null || true
done
archil unmount /workspace/shared 2>/dev/null || true
archil mount --shared \
--region "$ARCHIL_REGION" "$ARCHIL_SHARED_DISK_NAME" /workspace/shared
echo "Shared directory structure ready (delegations released)"
fi
echo "===================="
# Graceful unmount on shutdown (flushes pending data to backing store)
cleanup_archil() {
echo "Unmounting Archil disks..."
archil unmount /workspace/shared 2>/dev/null || true
}
trap cleanup_archil EXIT INT TERM
fi
# Print version banner and run the server
echo "=== Agent Swarm API v$(cat /app/package.json | grep '"version"' | cut -d'"' -f4) ==="
echo "Port: $PORT"
echo "Database: $DATABASE_PATH"
echo "=============================="
exec /usr/local/bin/agent-swarm-api