mar 28 2009

Shell Script per Auto Restart Apache HTTPD quando il servizio è down

Published by Dev at 08:30 under Opensource, Tutorial

Questo è uno semplice script di shell testato su CentOS / RHEL / Fedora / Debian / Ubuntu Linux. Dovrebbe funzionare in base a qualsiasi altro sistema operativo UNIX Like.
Il suo scopo è molto semplice, cioè fare un restart del servizio di apache qualora fosse “morto”.

Ecco il codice:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
# Apache Process Monitor
# Restart Apache Web Server When It Goes Down
# -------------------------------------------------------------------------
# Copyright (c) 2003 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# RHEL / CentOS / Fedora Linux restart command
RESTART="/sbin/service httpd restart"
 
# uncomment if you are using Debian / Ubuntu Linux
#RESTART="/etc/init.d/apache2 restart"
 
#path to pgrep command
PGREP="/usr/bin/pgrep"
 
# Httpd daemon name,
# Under RHEL/CentOS/Fedora it is httpd
# Under Debian 4.x it is apache2
HTTPD="httpd"
 
# find httpd pid
$PGREP ${HTTPD}
 
if [ $? -ne 0 ] # if apache not running
then
 # restart apache
 $RESTART
fi



A quanto punto è sufficiente impostarlo nel cronjob

*/5 * * * * /path/to/script.sh >/dev/null 2>&1

Articoli Correlati:

Segnala presso:
  • del.icio.us
  • Google
  • Live
  • Segnalo
  • Slashdot
  • Facebook
  • Upnews
  • Wikio IT
  • Digg
  • E-mail this story to a friend!
  • Ma.gnolia
  • MySpace
  • Diggita
  • LinkedIn
  • OKNotizie
  • ZicZac

No responses yet



Trackback URI | Comments RSS

Leave a Reply