#!/bin/bash # Installation script for home-pump service on Raspberry Pi/Ubuntu set -e echo "Home Pump Service Installation Script" echo "======================================" # Check if running as root if [ "$EUID" -ne 0 ]; then echo "Please run as root (use sudo)" exit 1 fi # Configuration PROJECT_DIR="/home/pi/home-pump" SERVICE_FILE="scripts/home-pump.service" JAR_FILE="target/home-pump-1.0.0.jar" # Check if project directory exists if [ ! -d "$PROJECT_DIR" ]; then echo "Error: Project directory $PROJECT_DIR not found" echo "Please adjust PROJECT_DIR in this script or create the directory" exit 1 fi cd "$PROJECT_DIR" # Check if JAR file exists if [ ! -f "$JAR_FILE" ]; then echo "Error: JAR file not found at $JAR_FILE" echo "Please build the project first using: mvn clean package" exit 1 fi # Install systemd service echo "Installing systemd service..." cp "$SERVICE_FILE" /etc/systemd/system/home-pump.service systemctl daemon-reload echo "✓ Systemd service installed" # Enable service to start on boot systemctl enable home-pump.service echo "✓ Service enabled to start on boot" # Start the service systemctl start home-pump.service echo "✓ Service started" # Wait a bit and check status sleep 3 if systemctl is-active --quiet home-pump.service; then echo "" echo "✓✓✓ Installation completed successfully! ✓✓✓" echo "" echo "Service status:" systemctl status home-pump.service --no-pager -l echo "" echo "How it works:" echo " - Application monitors health internally" echo " - On consecutive failures (default 3), app exits with error code" echo " - Systemd automatically restarts the service (Restart=on-failure)" echo " - No external monitoring script needed" echo "" echo "Useful commands:" echo " - View logs: journalctl -u home-pump.service -f" echo " - Check status: systemctl status home-pump.service" echo " - Restart service: sudo systemctl restart home-pump.service" echo " - Stop service: sudo systemctl stop home-pump.service" echo " - Health check: curl http://localhost:8080/health" else echo "" echo "⚠ Warning: Service installed but not running properly" echo "Check logs with: journalctl -u home-pump.service -n 50" fi