Add start-service.bat script for Resource Monitor Service v2.0
- Introduced a batch script to simplify the startup process for the Resource Monitor Service. - Included checks for .NET 9.0 Runtime installation. - Added build and run commands for the service with appropriate error handling. - Provided user instructions and API documentation links in the script output.
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
#!/bin/bash
|
||||
# Resource Monitor Service - Installation Script for Windows Service
|
||||
|
||||
SERVICE_NAME="ResourceMonitorService"
|
||||
SERVICE_DISPLAY_NAME="Resource Monitor Service v2.0"
|
||||
SERVICE_DESCRIPTION="Monitors VM resources for Unraid integration"
|
||||
INSTALL_PATH="C:\Services\ResourceMonitor"
|
||||
|
||||
echo "=== Resource Monitor Service - Windows Service Installer ==="
|
||||
echo
|
||||
|
||||
# Check if running as administrator
|
||||
if [[ ! $(id -u) -eq 0 ]]; then
|
||||
echo "ERROR: This script must be run as Administrator"
|
||||
echo "Please run PowerShell as Administrator and try again"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Installing Resource Monitor Service as Windows Service..."
|
||||
|
||||
# Create installation directory
|
||||
echo "Creating installation directory..."
|
||||
mkdir -p "$INSTALL_PATH"
|
||||
|
||||
# Build the service in release mode
|
||||
echo "Building service..."
|
||||
dotnet publish --configuration Release --output "$INSTALL_PATH"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "ERROR: Build failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Stop existing service if running
|
||||
echo "Stopping existing service (if running)..."
|
||||
sc stop "$SERVICE_NAME" 2>/dev/null
|
||||
|
||||
# Remove existing service if it exists
|
||||
echo "Removing existing service (if exists)..."
|
||||
sc delete "$SERVICE_NAME" 2>/dev/null
|
||||
|
||||
# Install the service
|
||||
echo "Installing Windows Service..."
|
||||
sc create "$SERVICE_NAME" \
|
||||
binPath="\"$INSTALL_PATH\\ResourceMonitorService.exe\" --windows-service" \
|
||||
DisplayName="$SERVICE_DISPLAY_NAME" \
|
||||
Description="$SERVICE_DESCRIPTION" \
|
||||
start=auto
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "ERROR: Failed to create Windows Service"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Configure service recovery options
|
||||
echo "Configuring service recovery options..."
|
||||
sc failure "$SERVICE_NAME" reset=300 actions=restart/5000/restart/5000/restart/10000
|
||||
|
||||
# Configure firewall rule
|
||||
echo "Configuring Windows Firewall..."
|
||||
powershell -Command "New-NetFirewallRule -DisplayName 'Resource Monitor Service' -Direction Inbound -Protocol TCP -LocalPort 5000 -Action Allow -Profile Any" 2>/dev/null
|
||||
|
||||
# Start the service
|
||||
echo "Starting service..."
|
||||
sc start "$SERVICE_NAME"
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo
|
||||
echo "=== Installation Complete ==="
|
||||
echo "Service Name: $SERVICE_NAME"
|
||||
echo "Installation Path: $INSTALL_PATH"
|
||||
echo "Service URL: http://localhost:5000"
|
||||
echo "API Health Check: http://localhost:5000/api/health"
|
||||
echo
|
||||
echo "The service is now running and will start automatically with Windows."
|
||||
echo "You can manage it through Services.msc or using sc commands:"
|
||||
echo " - Stop: sc stop $SERVICE_NAME"
|
||||
echo " - Start: sc start $SERVICE_NAME"
|
||||
echo " - Status: sc query $SERVICE_NAME"
|
||||
echo
|
||||
echo "To uninstall: sc stop $SERVICE_NAME && sc delete $SERVICE_NAME"
|
||||
else
|
||||
echo "ERROR: Failed to start service"
|
||||
echo "Check Windows Event Log for details"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user