From b607a0938d2fcdda80bfd5ca63312f571c607b40 Mon Sep 17 00:00:00 2001 From: John Eckersberg Date: Fri, 20 Feb 2009 11:55:05 -0500 Subject: Add httpd module. Can return information from mod_status and do graceful service restart. --- func/minion/modules/httpd.py | 67 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 func/minion/modules/httpd.py (limited to 'func/minion/modules/httpd.py') diff --git a/func/minion/modules/httpd.py b/func/minion/modules/httpd.py new file mode 100644 index 0000000..2579ae8 --- /dev/null +++ b/func/minion/modules/httpd.py @@ -0,0 +1,67 @@ +# +# Copyright 2009 +# John Eckersberg +# +# This software may be freely redistributed under the terms of the GNU +# general public license. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import func_module + +class ServerStatusUnavailable(Exception): + pass + +class MalformedServerStatus(Exception): + pass + +class Httpd(func_module.FuncModule): + + # Update these if need be. + version = "0.0.1" + api_version = "0.0.1" + description = "Gather information from and manipulate Apache HTTPD" + + import service + import urllib2 + + HTTPD_SERVICE_NAME = 'httpd' + + def server_status(self, host="localhost", request="server-status", ssl=False): + """ + Returns a dictionary representing output from mod_status. + + :Parameters: + - `host`: the hostname to query against. + - `request`: the location of the mod_status handler. + - `ssl`: whether or not to use HTTPS. + """ + if ssl: + proto = "https" + else: + proto = "http" + + try: + status = self.urllib2.urlopen("%s://%s/%s?auto" % (proto, host, request)).read() + except Exception, e: + raise ServerStatusUnavailable, e + + result = {} + for line in status.split('\n'): + if not line: + continue + try: + k,v = [foo.strip() for foo in line.split(':')] + except ValueError: + raise MalformedServerStatus + result[k] = v + + return result + + def graceful(self): + """ + Issue a graceful restart to the httpd service. + """ + return self.service.Service()._Service__command(Httpd.HTTPD_SERVICE_NAME, 'graceful') -- cgit