#!/data/data/com.termux/files/usr/bin/bash
#
# runit service: sms-api
# Runs the Flask SMS API server under termux-services supervision.
# Install: ln -s ~/sms-server/termux-sms/services/sms-api $PREFIX/var/service/
#

# Source environment (API key, etc.)
[ -f "$HOME/.bashrc" ] && . "$HOME/.bashrc"

# Ensure log directory exists
mkdir -p "$HOME/logs"

# Acquire wake lock (idempotent — safe to call multiple times)
termux-wake-lock 2>/dev/null

# exec replaces the shell with python so runit tracks the real PID
exec python "$HOME/sms-server/termux-sms/termux-sms-api-server.py" \
  >> "$HOME/logs/sms-api.log" 2>&1
