#!/bin/bash
# Run this ONCE on Oracle to set up AXIOM as an auto-restarting service
# After this, AXIOM will start on boot and restart if it crashes

# Create the systemd service file
sudo tee /etc/systemd/system/axiom.service > /dev/null << 'EOF'
[Unit]
Description=AXIOM Trading Terminal
After=network.target

[Service]
User=opc
WorkingDirectory=/home/opc/AXIOM
ExecStart=/usr/bin/python3 /home/opc/AXIOM/axiom-server.py --no-crawler
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF

# Enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable axiom
sudo systemctl restart axiom

echo ""
echo "AXIOM service installed!"
echo ""
echo "It will now:"
echo "  - Start automatically when Oracle reboots"
echo "  - Restart automatically if it crashes"
echo "  - Run forever without needing SSH"
echo ""
echo "Useful commands:"
echo "  sudo systemctl status axiom   — check if running"
echo "  sudo systemctl restart axiom  — restart"
echo "  sudo systemctl stop axiom     — stop"
echo ""
