Files
code-tools/terraform/scripts/agentapi/agentapi-start.sh
2025-09-29 00:47:39 +00:00

37 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# AgentAPI start script
# This script starts the AgentAPI server with proper user permissions
install_agentapi=${1:-false}
port=${2:-3284}
target_user="${USER:-coder}"
# Ensure we have proper permissions
umask 022
if [ "$install_agentapi" = "true" ]; then
echo "Starting AgentAPI on port $port..."
# Check if AgentAPI is installed
if ! command -v agentapi >/dev/null 2>&1; then
echo "Error: agentapi command not found"
exit 1
fi
# Start AgentAPI as the appropriate user
current_uid=$(id -u)
if [ "$current_uid" -eq 0 ]; then
echo "Running as root - switching to $target_user for AgentAPI"
chown -R "$target_user:$target_user" "/home/coder" 2>/dev/null || true
# Start AgentAPI as the target user
exec sudo -u "$target_user" -E -H agentapi serve --port="$port"
else
echo "Running as user $(whoami) - starting AgentAPI directly"
exec agentapi serve --port="$port"
fi
else
echo "AgentAPI installation disabled, skipping start..."
exit 0
fi