diff options
-rw-r--r-- | client/test_func.py | 1 | ||||
-rwxr-xr-x | modules/service.py | 60 |
2 files changed, 61 insertions, 0 deletions
diff --git a/client/test_func.py b/client/test_func.py index 21c2009..ede9bbf 100644 --- a/client/test_func.py +++ b/client/test_func.py @@ -8,6 +8,7 @@ import xmlrpclib s = xmlrpclib.ServerProxy("http://127.0.0.1:51234") print s.test_add(1, 2) +print s.service_restart("httpd") diff --git a/modules/service.py b/modules/service.py new file mode 100755 index 0000000..f0693b0 --- /dev/null +++ b/modules/service.py @@ -0,0 +1,60 @@ +#!/usr/bin/python + +## func +## +## Copyright 2007, Red Hat, Inc +## Michael DeHaan <mdehaan@redhat.com> +## +## 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. +## +## + + +from codes import * +from modules import web_svc + +import subprocess +import os + +class Service(web_svc.WebSvc): + + def __init__(self): + self.methods = { + "service_start" : self.start, + "service_stop" : self.stop, + "service_restart" : self.restart, + "service_reload" : self.reload, + "service_status" : self.status + } + web_svc.WebSvc.__init__(self) + + def __command(self, service_name, command): + + filename = os.path.join("/etc/rc.d/init.d/",service_name) + if os.path.exists(filename): + return subprocess.call(["/sbin/service", service_name, command]) + else: + raise FuncException("Service not installed: %s" % service_name) + + def start(self, service_name): + return self.__command(service_name, "start") + + def stop(self, service_name): + return self.__command(service_name, "start") + + def restart(self, service_name): + return self.__command(service_name, "restart") + + def reload(self, service_name): + return self.__command(service_name, "reload") + + def status(self, service_name): + return self.__command(service_name, "status") + +methods = Service() +register_rpc = methods.register_rpc |