Python script to start, restart and stop the apache server

Ranjith Kumar ranjithtenz at gmail.com
Thu Jul 15 16:02:50 EDT 2010


Hi,
   I planned to write a python script to starts the apache server and when
the HTTPD goes down/drop it should auto restart and when user chooses stop
it should stop the apache server.
Here the start and stop should be user set but the restart when the server
goes down.

Similar to this program,
This is shell script,

#!/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

Johan Grönqvist and Daniel Fetchinson thanks for your reply.


-- 
Cheers
Ranjith,

http://ranjith10z.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100716/1e8e26c2/attachment.html>


More information about the Python-list mailing list