#!/usr/bin/bash

srv_status=$(/usr/bin/systemctl is-enabled $1)
srv_name=$1
#Logging to syslog
/usr/bin/logger  -t $0 "Service restart auto-remediation initiated on $1"

srv_restart() {
if [[ $srv_status == "enabled" ]]; then
    /usr/bin/systemctl restart $srv_name
    if /usr/bin/systemctl is-active --quiet $srv_name; then
        echo "restarted $srv_name on the server and the service is active now"
    else
        echo "$srv_name is not starting please check manually in logs"
    fi
else
    echo "$srv_name is not in enabled state, please check with VHS"
fi
}

if [[ $srv_name != mysqld.service && $srv_name != postgresql.service ]];then
    srv_restart
else
    echo "You are not suppose to restart this service, Please escalte it to VHS team"
fi

/usr/bin/logger  -t $0 "Service restart auto-remediation is done"
