#!/usr/bin/env bash if [[ -n "${ATLAS_SERVICES_SH_LOADED:-}" ]]; then return 0 fi ATLAS_SERVICES_SH_LOADED=1 atlas_service_exists() { local service_name="$1" systemctl list-unit-files --type=service --no-legend "$service_name" 2>/dev/null | awk '{print $1}' | grep -qx "$service_name" } atlas_service_active() { local service_name="$1" systemctl is-active --quiet "$service_name" 2>/dev/null } atlas_service_status() { local service_name="$1" if ! atlas_service_exists "$service_name"; then printf 'missing\n' elif atlas_service_active "$service_name"; then printf 'active\n' else printf 'inactive\n' fi } atlas_service_enable() { local service_name="$1" if ! atlas_service_exists "$service_name"; then atlas_log_warn "Service not found: ${service_name}" return "${ATLAS_EXIT_PREREQ:-3}" fi atlas_log_info "Enabling service ${service_name}" atlas_sudo_run systemctl enable "$service_name" } atlas_service_start() { local service_name="$1" if ! atlas_service_exists "$service_name"; then atlas_log_warn "Service not found: ${service_name}" return "${ATLAS_EXIT_PREREQ:-3}" fi atlas_log_info "Starting service ${service_name}" atlas_sudo_run systemctl start "$service_name" } atlas_service_restart() { local service_name="$1" if ! atlas_service_exists "$service_name"; then atlas_log_warn "Service not found: ${service_name}" return "${ATLAS_EXIT_PREREQ:-3}" fi atlas_log_info "Restarting service ${service_name}" atlas_sudo_run systemctl restart "$service_name" }