Updated service to use uv run with absolute path to avoid PATH issues in systemd environment. Service file changes: - ExecStart: Uses absolute path to uv (/home/berwn/.local/bin/uv) - Runs: uv run --no-project python rotary_phone_web.py - This ensures uv manages dependencies correctly Install script improvements: - Auto-detects uv location with 'which uv' - Falls back to $HOME/.local/bin/uv if not in PATH - Validates uv exists before proceeding - Substitutes actual uv path into service file - Shows detected uv path in output This fixes: ModuleNotFoundError: No module named 'waitress' Now uv properly manages the virtual environment and dependencies are available to the service. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
147 lines
4.3 KiB
Bash
147 lines
4.3 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Wedding Phone Service Installer
|
|
# Installs the wedding phone as a systemd service
|
|
#
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo "=========================================="
|
|
echo "Wedding Phone Service Installer"
|
|
echo "=========================================="
|
|
echo ""
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -eq 0 ]; then
|
|
echo -e "${RED}ERROR: Do not run this script as root or with sudo${NC}"
|
|
echo "This script will prompt for sudo password when needed"
|
|
exit 1
|
|
fi
|
|
|
|
# Get the directory where this script is located
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
SERVICE_FILE="$SCRIPT_DIR/wedding-phone.service"
|
|
|
|
echo "Project directory: $SCRIPT_DIR"
|
|
echo ""
|
|
|
|
# Check if config.json exists
|
|
if [ ! -f "$SCRIPT_DIR/config.json" ]; then
|
|
echo -e "${YELLOW}WARNING: config.json not found${NC}"
|
|
echo "Creating config.json from config.example.json..."
|
|
if [ -f "$SCRIPT_DIR/config.example.json" ]; then
|
|
cp "$SCRIPT_DIR/config.example.json" "$SCRIPT_DIR/config.json"
|
|
echo -e "${GREEN}✓ Created config.json${NC}"
|
|
echo -e "${YELLOW}Please edit config.json to configure your system before starting the service${NC}"
|
|
echo ""
|
|
else
|
|
echo -e "${RED}ERROR: config.example.json not found${NC}"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Check if UV is installed
|
|
if ! command -v uv &> /dev/null; then
|
|
echo -e "${RED}ERROR: UV is not installed${NC}"
|
|
echo "Install UV with: curl -LsSf https://astral.sh/uv/install.sh | sh"
|
|
exit 1
|
|
fi
|
|
|
|
echo -e "${GREEN}✓ UV is installed${NC}"
|
|
|
|
# Install dependencies
|
|
echo ""
|
|
echo "Installing dependencies..."
|
|
cd "$SCRIPT_DIR"
|
|
make sync
|
|
|
|
echo -e "${GREEN}✓ Dependencies installed${NC}"
|
|
echo ""
|
|
|
|
# Find uv location
|
|
UV_PATH=$(which uv)
|
|
if [ -z "$UV_PATH" ]; then
|
|
UV_PATH="$HOME/.local/bin/uv"
|
|
if [ ! -f "$UV_PATH" ]; then
|
|
echo -e "${RED}ERROR: Cannot find uv executable${NC}"
|
|
echo "Checked: $(which uv), $HOME/.local/bin/uv"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo -e "${GREEN}✓ Found uv at: $UV_PATH${NC}"
|
|
|
|
# Update the service file with the correct path
|
|
echo "Configuring service file..."
|
|
TEMP_SERVICE="/tmp/wedding-phone.service"
|
|
CURRENT_USER=$(whoami)
|
|
USER_HOME=$(eval echo ~$CURRENT_USER)
|
|
|
|
cat "$SERVICE_FILE" | \
|
|
sed "s|User=berwn|User=$CURRENT_USER|g" | \
|
|
sed "s|Group=berwn|Group=$CURRENT_USER|g" | \
|
|
sed "s|/home/berwn/wedding-phone|$SCRIPT_DIR|g" | \
|
|
sed "s|/home/berwn/.local/bin/uv|$UV_PATH|g" | \
|
|
sed "s|/home/berwn/.local/bin|$USER_HOME/.local/bin|g" \
|
|
> "$TEMP_SERVICE"
|
|
|
|
echo -e "${GREEN}✓ Service file configured for user: $CURRENT_USER${NC}"
|
|
echo -e "${GREEN}✓ Working directory: $SCRIPT_DIR${NC}"
|
|
echo -e "${GREEN}✓ UV path: $UV_PATH${NC}"
|
|
echo ""
|
|
|
|
# Install the service
|
|
echo "Installing systemd service..."
|
|
sudo cp "$TEMP_SERVICE" /etc/systemd/system/wedding-phone.service
|
|
sudo systemctl daemon-reload
|
|
|
|
echo -e "${GREEN}✓ Service installed${NC}"
|
|
echo ""
|
|
|
|
# Ask if user wants to enable and start the service
|
|
read -p "Do you want to enable and start the service now? (y/n) " -n 1 -r
|
|
echo ""
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
echo "Enabling service to start on boot..."
|
|
sudo systemctl enable wedding-phone.service
|
|
echo -e "${GREEN}✓ Service enabled${NC}"
|
|
|
|
echo ""
|
|
echo "Starting service..."
|
|
sudo systemctl start wedding-phone.service
|
|
echo -e "${GREEN}✓ Service started${NC}"
|
|
|
|
echo ""
|
|
echo "Service status:"
|
|
sudo systemctl status wedding-phone.service --no-pager
|
|
else
|
|
echo ""
|
|
echo "Service installed but not started."
|
|
echo "To enable and start later, run:"
|
|
echo " sudo systemctl enable wedding-phone.service"
|
|
echo " sudo systemctl start wedding-phone.service"
|
|
fi
|
|
|
|
echo ""
|
|
echo "=========================================="
|
|
echo "Installation Complete!"
|
|
echo "=========================================="
|
|
echo ""
|
|
echo "Useful commands:"
|
|
echo " Start service: sudo systemctl start wedding-phone"
|
|
echo " Stop service: sudo systemctl stop wedding-phone"
|
|
echo " Restart service: sudo systemctl restart wedding-phone"
|
|
echo " View logs: sudo journalctl -u wedding-phone -f"
|
|
echo " Service status: sudo systemctl status wedding-phone"
|
|
echo " Disable service: sudo systemctl disable wedding-phone"
|
|
echo ""
|
|
|
|
# Clean up
|
|
rm -f "$TEMP_SERVICE"
|