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
This commit is contained in:
parent
e666bbe9ff
commit
3c37d91bc4
60
README-deployment.md
Normal file
60
README-deployment.md
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
# Spotify Tracker Deployment Guide
|
||||||
|
|
||||||
|
## Quick Setup
|
||||||
|
|
||||||
|
1. **Clone and deploy:**
|
||||||
|
```bash
|
||||||
|
git clone <your-repo-url>
|
||||||
|
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`
|
68
deploy.sh
Executable file
68
deploy.sh
Executable file
|
@ -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 " }"
|
2
runit/spotify-tracker/log/run
Executable file
2
runit/spotify-tracker/log/run
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
exec chpst -u spotify-tracker:spotify-tracker svlogd -tt /var/log/spotify-tracker
|
12
runit/spotify-tracker/run
Executable file
12
runit/spotify-tracker/run
Executable file
|
@ -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
|
Loading…
Reference in a new issue