Skip to content

Instantly share code, notes, and snippets.

@d4nnr
Created February 20, 2014 05:12
Show Gist options
  • Save d4nnr/9107429 to your computer and use it in GitHub Desktop.
Save d4nnr/9107429 to your computer and use it in GitHub Desktop.
#!/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 "##########################################################"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment