#!/bin/bash

# Setup SkyArtShop as a systemd service
# This will make your server run automatically on boot and restart on crashes

echo "🚀 Setting up SkyArtShop as a system service..."

# Create log directory
echo "📁 Creating log directory..."
sudo mkdir -p /var/log/skyartshop
sudo chown pts:pts /var/log/skyartshop

# Copy service file to systemd
echo "📋 Installing service file..."
sudo cp skyartshop.service /etc/systemd/system/

# Reload systemd to recognize new service
echo "🔄 Reloading systemd..."
sudo systemctl daemon-reload

# Enable service to start on boot
echo "✅ Enabling service to start on boot..."
sudo systemctl enable skyartshop

# Start the service
echo "▶️  Starting service..."
sudo systemctl start skyartshop

# Wait a moment for service to start
sleep 2

# Check service status
echo ""
echo "📊 Service Status:"
sudo systemctl status skyartshop --no-pager

echo ""
echo "✨ Setup complete!"
echo ""
echo "📝 Useful commands:"
echo "  • Check status:  sudo systemctl status skyartshop"
echo "  • Start service: sudo systemctl start skyartshop"
echo "  • Stop service:  sudo systemctl stop skyartshop"
echo "  • Restart:       sudo systemctl restart skyartshop"
echo "  • View logs:     sudo journalctl -u skyartshop -f"
echo "  • View errors:   tail -f /var/log/skyartshop/error.log"
echo "  • View output:   tail -f /var/log/skyartshop/output.log"
echo ""
echo "🌐 Your server should now be running on http://localhost:5000"
