Script BASH estado de servicios; iniciar y reiniciar...

Facilitando la vida del SysAdmin :]




Este script es para verificar el estado de los servicios del servidor, si algún servicio está caído automaticamente se inicia y si está en ejecución automaticamente se reinicia. La utilidad le das tu :].

Código.
#!/bin/bash
#Este script revisa los servicios httpd, mysqld y postfix si estan parados los inicia y si estan en ejecucion los reinicia.
# Lista de servicios
echo "##########################################################"
echo "##########################################################"
SERVICIOS=(mysqld)
# Funcion para inicializar/reiniciar servicios
function servicioInit (){
if ! service $1 status &>/dev/null; then
echo -n -e "\t El servicio esta parado, !! INICIAR $1 !!..."
service $1 start
echo '---Inicio OK---'
service mysqld status
else
echo -n -e "\t El servicio $1 esta en ejecucion, sin embargo se va a !! REINICIAR !!"
service $1 restart
echo '---Reinicio-OK---'
service mysqld status
fi
}
for ((i=0; i<${#SERVICIOS[*]}; i++)) do #if $estado = "start"; then if [ -z $1 ]; then echo "Verificando servicio: ${SERVICIO[$i]} ->"
servicioInit ${SERVICIOS[$i]}
done
echo "##########################################################"
echo "##########################################################"
SERVICIOS=(httpd)
# Funcion para inicializar/reiniciar servicios
function servicioInit (){
if ! service $1 status &>/dev/null; then
echo -n -e "\t El servicio esta parado, !! INICIAR $1 !!..."
service $1 start
echo '---Inicio OK---'
service httpd status
else
echo -n -e "\t El servicio $1 esta en ejecucion, sin embargo se va a !! REINICIAR !!"
service $1 restart
echo '---Reinicio-OK---'
service httpd status
fi
}
for ((i=0; i<${#SERVICIOS[*]}; i++)) do #if $estado = "start"; then if [ -z $1 ]; then echo "Verificando servicio: ${SERVICIO[$i]} ->"
servicioInit ${SERVICIOS[$i]}
done
echo "##########################################################"
echo "##########################################################"
SERVICIOS=(postfix)
# Funcion para inicializar/reiniciar servicios
function servicioInit (){
if ! service $1 status &>/dev/null; then
echo -n -e "\t El servicio esta parado, !! INICIAR $1 !!..."
service $1 start
echo '---Inicio OK---'
service postfix status
else
echo -n -e "\t El servicio $1 esta en ejecucion, sin embargo se va a !! REINICIAR !!"
service $1 restart
echo '---Reinicio-OK---'
service postfix status
fi
}
for ((i=0; i<${#SERVICIOS[*]}; i++)) do #if $estado = "start"; then if [ -z $1 ]; then echo "Verificando servicio: ${SERVICIO[$i]} ->"
servicioInit ${SERVICIOS[$i]}
done
echo "##########################################################"
echo "##########################################################"

Comentarios

Entradas populares