feat: rename rails/ to tools/ and add service tool suites
Rename the `rails/` directory to `tools/` for agent discoverability — agents frequently failed to locate helper scripts due to the non-intuitive directory name. Add backward-compat symlink `rails/ → tools/`. New tool suites: - Authentik: auth-token, user-list, user-create, group-list, app-list, flow-list, admin-status (8 scripts) - Coolify: team-list, project-list, service-list, service-status, deploy, env-set (7 scripts) - Woodpecker: pipeline-list, pipeline-status, pipeline-trigger (3 stubs) - GLPI: session-init, computer-list, ticket-list, ticket-create, user-list (6 scripts) - Health: stack-health.sh — stack-wide connectivity check Infrastructure: - Shared credential loader at tools/_lib/credentials.sh - install.sh creates symlink + chmod on tool scripts - All ~253 rails/ path references updated across 68+ files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
114
tools/portainer/stack-start.sh
Executable file
114
tools/portainer/stack-start.sh
Executable file
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# stack-start.sh - Start an inactive Portainer stack
|
||||
#
|
||||
# Usage: stack-start.sh -n <stack-name>
|
||||
#
|
||||
# Environment variables:
|
||||
# PORTAINER_URL - Portainer instance URL (e.g., https://portainer.example.com:9443)
|
||||
# PORTAINER_API_KEY - API access token
|
||||
#
|
||||
# Options:
|
||||
# -n name Stack name (required)
|
||||
# -i id Stack ID (alternative to -n)
|
||||
# -h Show this help
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Default values
|
||||
STACK_NAME=""
|
||||
STACK_ID=""
|
||||
|
||||
# Parse arguments
|
||||
while getopts "n:i:h" opt; do
|
||||
case $opt in
|
||||
n) STACK_NAME="$OPTARG" ;;
|
||||
i) STACK_ID="$OPTARG" ;;
|
||||
h)
|
||||
head -16 "$0" | grep "^#" | sed 's/^# \?//'
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 -n <stack-name>" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Validate environment
|
||||
if [[ -z "${PORTAINER_URL:-}" ]]; then
|
||||
echo "Error: PORTAINER_URL environment variable not set" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "${PORTAINER_API_KEY:-}" ]]; then
|
||||
echo "Error: PORTAINER_API_KEY environment variable not set" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$STACK_NAME" && -z "$STACK_ID" ]]; then
|
||||
echo "Error: Either -n <stack-name> or -i <stack-id> is required" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove trailing slash from URL
|
||||
PORTAINER_URL="${PORTAINER_URL%/}"
|
||||
|
||||
# Function to make API requests
|
||||
api_request() {
|
||||
local method="$1"
|
||||
local endpoint="$2"
|
||||
|
||||
curl -s -w "\n%{http_code}" -X "$method" \
|
||||
-H "X-API-Key: ${PORTAINER_API_KEY}" \
|
||||
"${PORTAINER_URL}${endpoint}"
|
||||
}
|
||||
|
||||
# Get stack info by name
|
||||
if [[ -n "$STACK_NAME" ]]; then
|
||||
response=$(api_request GET "/api/stacks")
|
||||
http_code=$(echo "$response" | tail -n1)
|
||||
body=$(echo "$response" | sed '$d')
|
||||
|
||||
if [[ "$http_code" != "200" ]]; then
|
||||
echo "Error: Failed to list stacks (HTTP $http_code)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
stack_info=$(echo "$body" | jq --arg name "$STACK_NAME" '.[] | select(.Name == $name)')
|
||||
|
||||
if [[ -z "$stack_info" || "$stack_info" == "null" ]]; then
|
||||
echo "Error: Stack '$STACK_NAME' not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
STACK_ID=$(echo "$stack_info" | jq -r '.Id')
|
||||
ENDPOINT_ID=$(echo "$stack_info" | jq -r '.EndpointId')
|
||||
else
|
||||
response=$(api_request GET "/api/stacks/${STACK_ID}")
|
||||
http_code=$(echo "$response" | tail -n1)
|
||||
body=$(echo "$response" | sed '$d')
|
||||
|
||||
if [[ "$http_code" != "200" ]]; then
|
||||
echo "Error: Failed to get stack (HTTP $http_code)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
stack_info="$body"
|
||||
STACK_NAME=$(echo "$stack_info" | jq -r '.Name')
|
||||
ENDPOINT_ID=$(echo "$stack_info" | jq -r '.EndpointId')
|
||||
fi
|
||||
|
||||
echo "Starting stack '$STACK_NAME' (ID: $STACK_ID)..."
|
||||
|
||||
response=$(api_request POST "/api/stacks/${STACK_ID}/start?endpointId=${ENDPOINT_ID}")
|
||||
http_code=$(echo "$response" | tail -n1)
|
||||
body=$(echo "$response" | sed '$d')
|
||||
|
||||
if [[ "$http_code" == "200" ]]; then
|
||||
echo "Successfully started stack '$STACK_NAME'"
|
||||
else
|
||||
echo "Error: Failed to start stack (HTTP $http_code)" >&2
|
||||
echo "$body" | jq '.' 2>/dev/null || echo "$body" >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user