mercredi 21 septembre 2011

Script du jour

Il peut être utile de savoir (re)démarrer un service quand celui ci est arreté...
petite demo avec le service apache2
vi service_down_to_up.sh copie colle ... #!/bin/bash
# Service Process Monitor
# Restart a Service When It Goes Down
# ----------------------------------------------------------
# Copyright (c) 2011 David H.
# ----------------------------------------------------------

SERVICE_NAME="apache2"
RESTART="service $SERVICE_NAME restart"

# path to pgrep command
PGREP=$(which pgrep)

# find service pid
$PGREP ${SERVICE_NAME}

[ $? -ne 0 ] && $RESTART || : # if service not running

sudo chmod +x service_down_to_up.sh
./service_down_to_up.sh

Aucun commentaire:

Enregistrer un commentaire