#!/bin/bash

# Define the service names to start
service_names=("Service1" "Service2")

# Function to check if a service is already running
check_service_status() {
    local service_name="$1"
    if systemctl is-active --quiet "$service_name"; then
        echo "Service $service_name is already running."
        return 0  # Service is already running
    else
        return 1  # Service is not running
    fi
}

# Start each service
for service_name in "${service_names[@]}"; do
    # Check if the service is already running
    if check_service_status "$service_name"; then
        continue  # Skip starting the service if it's already running
    fi

    # Start the service
    sudo systemctl start "$service_name"

    # Check if the service started successfully
    if [ $? -eq 0 ]; then
        echo "Service $service_name started successfully."
    else
        echo "Failed to start service $service_name."
    fi
done