summaryrefslogtreecommitdiff
path: root/scripts/claude-daemon-setup.sh
blob: 0652e2770d9de369263a4f8e4f1ba665a19c789a (plain)
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
#!/bin/bash
# Set up Claude Code remote-control daemons for each app repo (run as root on Hetzner VPS).
set -e

# Install Claude Code if not present
if ! command -v claude &>/dev/null; then
  npm install -g @anthropic-ai/claude-code
fi

# Create non-root user for claude sessions (root is blocked by claude security policy)
if ! id claude-agent &>/dev/null; then
  useradd -r -m -s /bin/bash claude-agent
fi
usermod -aG docker claude-agent
chown -R claude-agent:claude-agent /app

# Copy credentials from root to claude-agent
cp /root/.claude.json /home/claude-agent/.claude.json
chown claude-agent:claude-agent /home/claude-agent/.claude.json

declare -A REPOS=(
  ["infra"]="/app/infra"
  ["tokyo"]="/app"
  ["whoisband"]="/app/whois-band"
)

for NAME in "${!REPOS[@]}"; do
  DIR="${REPOS[$NAME]}"
  SERVICE="claude-${NAME}.service"

  cat > "/etc/systemd/system/${SERVICE}" << EOF
[Unit]
Description=Claude Code Remote Session - ${NAME}
After=network.target

[Service]
Type=simple
User=claude-agent
WorkingDirectory=${DIR}
ExecStart=/usr/bin/script -q -c "claude --remote-control ${NAME}" /dev/null
Restart=always
RestartSec=15
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
EOF

  systemctl daemon-reload
  systemctl enable "${SERVICE}"
  systemctl restart "${SERVICE}"
  echo "Started: ${SERVICE} (WorkingDirectory: ${DIR})"
done

echo ""
echo "All Claude Code daemons running. Connect via https://claude.ai/code"
echo ""
echo "Useful commands:"
echo "  systemctl status claude-infra"
echo "  systemctl status claude-tokyo"
echo "  systemctl status claude-whoisband"
echo "  journalctl -u claude-tokyo -f"