#!/data/data/com.termux/files/usr/bin/bash
#
# Start all SMS Campaign Manager services via runit (termux-services)
# Prerequisite: run setup-services.sh first to install and register services
#

echo "Starting SMS Campaign Manager Services..."
echo ""

# Acquire wake lock
termux-wake-lock 2>/dev/null

# Source runit helpers
source "$PREFIX/etc/profile.d/start-services.sh" 2>/dev/null || true

# Ensure services are up
sv up sms-api 2>/dev/null && echo "  sms-api: started" || echo "  sms-api: failed (run setup-services.sh first)"
sv up sshd-custom 2>/dev/null && echo "  sshd-custom: started" || echo "  sshd-custom: failed (run setup-services.sh first)"

echo ""

# Wait for startup
sleep 3

# Status
echo "Service Status:"
sv status sms-api 2>/dev/null || echo "  sms-api: not registered"
sv status sshd-custom 2>/dev/null || echo "  sshd-custom: not registered"

echo ""
echo "Health Check:"
curl -s http://localhost:5001/health > /dev/null && echo "  SMS API: Healthy" || echo "  SMS API: Not responding"
