#!/bin/bash
set -e

echo "Updating Momentry API service with DB connection pool settings..."

# Backup existing plist
sudo cp /Library/LaunchDaemons/com.momentry.api.plist /Library/LaunchDaemons/com.momentry.api.plist.backup.$(date +%Y%m%d_%H%M%S)

# Stop the service
sudo launchctl unload /Library/LaunchDaemons/com.momentry.api.plist 2>/dev/null || true

# Copy updated plist
sudo cp /Users/accusys/momentry_core_0.1/com.momentry.api.updated.plist /Library/LaunchDaemons/com.momentry.api.plist

# Start the service
sudo launchctl load /Library/LaunchDaemons/com.momentry.api.plist

echo "API service updated successfully."
echo "Checking service status..."
launchctl list | grep com.momentry.api || echo "Service not listed in user domain; check system domain."
