From 3c37d91bc4fcf54679ec98d9ae2bd435045d0261 Mon Sep 17 00:00:00 2001 From: RTSDA Date: Wed, 20 Aug 2025 09:26:24 -0400 Subject: [PATCH] Add complete runit service configuration and deployment scripts - Add runit service files for spotify-tracker daemon - Include log service configuration with svlogd - Create automated deploy.sh script for server setup - Add comprehensive deployment documentation - Service runs as dedicated spotify-tracker user - Includes service management commands and troubleshooting guide --- README-deployment.md | 60 +++++++++++++++++++++++++++++++ deploy.sh | 68 +++++++++++++++++++++++++++++++++++ runit/spotify-tracker/log/run | 2 ++ runit/spotify-tracker/run | 12 +++++++ 4 files changed, 142 insertions(+) create mode 100644 README-deployment.md create mode 100755 deploy.sh create mode 100755 runit/spotify-tracker/log/run create mode 100755 runit/spotify-tracker/run diff --git a/README-deployment.md b/README-deployment.md new file mode 100644 index 0000000..9814f26 --- /dev/null +++ b/README-deployment.md @@ -0,0 +1,60 @@ +# Spotify Tracker Deployment Guide + +## Quick Setup + +1. **Clone and deploy:** + ```bash + git clone + cd spotify-tracker + chmod +x deploy.sh + sudo ./deploy.sh + ``` + +2. **Configure Caddy:** + ``` + spotify.tougie.live { + reverse_proxy localhost:8888 + } + ``` + +3. **Update Spotify App Settings:** + - Go to https://developer.spotify.com/dashboard + - Set redirect URI to: `https://spotify.tougie.live` + +## Service Management + +```bash +# Check service status +sv status spotify-tracker + +# Start/stop/restart service +sv start spotify-tracker +sv stop spotify-tracker +sv restart spotify-tracker + +# View logs +tail -f /var/log/spotify-tracker/current +``` + +## API Endpoints + +After deployment, these endpoints will be available: + +- `https://spotify.tougie.live/auth` - OAuth setup page +- `https://spotify.tougie.live/current` - Current track (JSON) +- `https://spotify.tougie.live/phantombot` - Current track (text for PhantomBot) +- `https://spotify.tougie.live/health` - Health check + +## Configuration + +The service runs as user `spotify-tracker` and stores: +- Config: `/home/spotify-tracker/.config/spotify-tracker/` +- Logs: `/var/log/spotify-tracker/` +- Binary: `/opt/spotify-tracker/target/release/spotify-tracker` + +## Troubleshooting + +1. **Check service status:** `sv status spotify-tracker` +2. **View logs:** `tail -f /var/log/spotify-tracker/current` +3. **Restart service:** `sv restart spotify-tracker` +4. **Check permissions:** Ensure `spotify-tracker` user owns `/opt/spotify-tracker` \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..1d55275 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,68 @@ +#!/bin/bash +set -e + +# Spotify Tracker Deployment Script +echo "🎵 Deploying Spotify Tracker..." + +# Configuration +SERVICE_NAME="spotify-tracker" +INSTALL_DIR="/opt/spotify-tracker" +SERVICE_DIR="/etc/sv/spotify-tracker" +USER="spotify-tracker" +GROUP="spotify-tracker" + +# Check if running as root +if [ "$EUID" -ne 0 ]; then + echo "Please run as root" + exit 1 +fi + +# Create user if it doesn't exist +if ! id "$USER" &>/dev/null; then + echo "Creating user: $USER" + useradd -r -s /bin/false -d "$INSTALL_DIR" "$USER" +fi + +# Create directories +echo "Creating directories..." +mkdir -p "$INSTALL_DIR" +mkdir -p "/var/log/$SERVICE_NAME" +mkdir -p "$SERVICE_DIR" +mkdir -p "$SERVICE_DIR/log" + +# Build the application +echo "Building Spotify Tracker..." +cd "$INSTALL_DIR" +cargo build --release + +# Set ownership +echo "Setting permissions..." +chown -R "$USER:$GROUP" "$INSTALL_DIR" +chown -R "$USER:$GROUP" "/var/log/$SERVICE_NAME" + +# Copy runit service files +echo "Installing runit service..." +cp runit/spotify-tracker/run "$SERVICE_DIR/run" +cp runit/spotify-tracker/log/run "$SERVICE_DIR/log/run" + +# Make scripts executable +chmod +x "$SERVICE_DIR/run" +chmod +x "$SERVICE_DIR/log/run" + +# Enable and start service +echo "Starting service..." +ln -sf "$SERVICE_DIR" /var/service/ + +echo "✅ Deployment complete!" +echo "" +echo "Service commands:" +echo " sv status spotify-tracker - Check status" +echo " sv start spotify-tracker - Start service" +echo " sv stop spotify-tracker - Stop service" +echo " sv restart spotify-tracker - Restart service" +echo " tail -f /var/log/spotify-tracker/current - View logs" +echo "" +echo "Configure Caddy with:" +echo " spotify.tougie.live {" +echo " reverse_proxy localhost:8888" +echo " }" \ No newline at end of file diff --git a/runit/spotify-tracker/log/run b/runit/spotify-tracker/log/run new file mode 100755 index 0000000..697ce10 --- /dev/null +++ b/runit/spotify-tracker/log/run @@ -0,0 +1,2 @@ +#!/bin/sh +exec chpst -u spotify-tracker:spotify-tracker svlogd -tt /var/log/spotify-tracker \ No newline at end of file diff --git a/runit/spotify-tracker/run b/runit/spotify-tracker/run new file mode 100755 index 0000000..80c437e --- /dev/null +++ b/runit/spotify-tracker/run @@ -0,0 +1,12 @@ +#!/bin/sh +exec 2>&1 + +# Set working directory +cd /opt/spotify-tracker || exit 1 + +# Set environment +export RUST_LOG=info +export RUST_BACKTRACE=1 + +# Run the spotify tracker server +exec chpst -u spotify-tracker:spotify-tracker ./target/release/spotify-tracker server --port 8888 \ No newline at end of file