[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] conga/ricci docs/service_api.html modules/serv ...



CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe sourceware org	2007-02-23 22:02:59

Modified files:
	ricci/docs     : service_api.html 
	ricci/modules/service: ServiceManager.cpp ServiceManager.h 
	                       ServiceModule.cpp 
Added files:
	ricci/test_suite/service: restart.xml 

Log message:
	- Add a restart function to the service module

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/docs/service_api.html.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/service/ServiceManager.cpp.diff?cvsroot=cluster&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/service/ServiceManager.h.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/service/ServiceModule.cpp.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/test_suite/service/restart.xml.diff?cvsroot=cluster&r1=NONE&r2=1.1

--- conga/ricci/docs/service_api.html	2007/02/05 20:08:28	1.3
+++ conga/ricci/docs/service_api.html	2007/02/23 22:02:57	1.4
@@ -117,6 +117,18 @@
 		generic ones might get returned. 
 		</P>
 	</UL>
+	<LI><P>restart</P>
+	<UL>
+		<P ALIGN=LEFT>Restart services/sets.</P>
+		<P>Input variables: <BR>- “services” (list_xml) – list of
+		services/sets to restart. For format see “query”. 
+		</P>
+		<P>No output variables. 
+		</P>
+		<P ALIGN=LEFT>On failure: <BR>- No special errors defined, only
+		generic ones might get returned. 
+		</P>
+	</UL>
 	<LI><P>stop</P>
 	<UL>
 		<P ALIGN=LEFT>Stop services/sets. It is not error to stop already
--- conga/ricci/modules/service/ServiceManager.cpp	2007/02/05 21:20:42	1.9
+++ conga/ricci/modules/service/ServiceManager.cpp	2007/02/23 22:02:57	1.10
@@ -172,7 +172,15 @@
 Service::start()
 {
   running();
-  run_service(name(), true);
+  run_service(name(), SERVICE_START);
+  *_running = true;
+}
+
+void 
+Service::restart()
+{
+  running();
+  run_service(name(), SERVICE_RESTART);
   *_running = true;
 }
 
@@ -180,7 +188,7 @@
 Service::stop()
 {
   running();
-  run_service(name(), false);
+  run_service(name(), SERVICE_STOP);
   *_running = false;
 }
 
@@ -217,7 +225,7 @@
 }
 
 void 
-Service::run_service(const String& name, bool on)
+Service::run_service(const String& name, int state)
 {
   String path(INITD_DIR_PATH);
   path += name;
@@ -225,20 +233,22 @@
   String out, err;
   int status;
   vector<String> args;
-  if (on)
+  if (state == SERVICE_START)
     args.push_back("start");
-  else
+  else if (state == SERVICE_RESTART)
+	args.push_back("restart");
+  else if (state == SERVICE_STOP)
     args.push_back("stop");
   if (utils::execute(path, args, out, err, status, false) != 0)
     throw command_not_found_error_msg(path);
   if (status) {
-    bool running = service_running(name);
-    if (on) {
-      if (!running)
-	throw String("service ") + name + " " + String(on?"start":"stop") + " failed";
+	bool running = service_running(name);
+	if (state == SERVICE_START || state == SERVICE_RESTART) {
+		if (!running)
+			throw String("service ") + name + " " + String(state == SERVICE_START ? "start" : "restart") + " failed";
     } else {
-      if (running)
-	throw String("service ") + name + " " + String(on?"start":"stop") + " failed";
+		if (running)
+			throw String("service ") + name + " " + String("stop") + " failed";
     }
   }
 }
@@ -363,6 +373,20 @@
 }
 
 void 
+ServiceSet::restart()
+{
+  name();
+  try {
+    for (list<Service>::iterator iter = servs.begin();
+	 iter != servs.end();
+	 iter++)
+      iter->restart();
+  } catch (String e) {
+    throw String("service set '") + name() + "' failed to restart";
+  }
+}
+
+void 
 ServiceSet::stop()
 {
   name();
@@ -589,6 +613,34 @@
 }
 
 void 
+ServiceManager::restart(const std::list<String>& services, 
+		     const std::list<String>& sets)
+{
+  // check
+  for (list<String>::const_iterator iter = services.begin();
+       iter != services.end();
+       iter++)
+    if (_servs.find(*iter) == _servs.end())
+      throw String("no such service: ") + *iter;
+  for (list<String>::const_iterator iter = sets.begin();
+       iter != sets.end();
+       iter++)
+    if (_sets.find(*iter) == _sets.end())
+      throw String("no such service set: ") + *iter;
+  
+  // apply
+  for (list<String>::const_iterator iter = services.begin();
+       iter != services.end();
+       iter++)
+    _servs[*iter].restart();
+  
+  for (list<String>::const_iterator iter = sets.begin();
+       iter != sets.end();
+       iter++)
+    _sets[*iter].restart();
+}
+
+void 
 ServiceManager::stop(const std::list<String>& services, 
 		     const std::list<String>& sets)
 {
--- conga/ricci/modules/service/ServiceManager.h	2006/08/10 22:53:09	1.2
+++ conga/ricci/modules/service/ServiceManager.h	2007/02/23 22:02:57	1.3
@@ -34,6 +34,11 @@
 
 class ServiceManager;
 
+enum {
+	SERVICE_STOP,
+	SERVICE_START,
+	SERVICE_RESTART
+};
 
 class Service
 {
@@ -48,6 +53,7 @@
   
   void enable();
   void disable();
+  void restart();
   void start();
   void stop();
   
@@ -63,7 +69,7 @@
   
   static void enable_service(const String& name, bool on);
   static bool service_running(const String& name);
-  static void run_service(const String& name, bool on);
+  static void run_service(const String& name, int state);
   
   friend class ServiceManager;
 
@@ -84,6 +90,7 @@
   void enable();
   void disable();
   void start();
+  void restart();
   void stop();
   
   std::list<Service> servs;
@@ -107,6 +114,7 @@
   void disable(const std::list<String>& services, const std::list<String>& sets);
   
   void start(const std::list<String>& services, const std::list<String>& sets);
+  void restart(const std::list<String>& services, const std::list<String>& sets);
   void stop(const std::list<String>& services, const std::list<String>& sets);
   
   void lists(std::list<Service>& services, 
--- conga/ricci/modules/service/ServiceModule.cpp	2006/08/10 22:53:09	1.3
+++ conga/ricci/modules/service/ServiceModule.cpp	2007/02/23 22:02:57	1.4
@@ -31,6 +31,7 @@
 static VarMap enable(const VarMap& args);
 static VarMap disable(const VarMap& args);
 static VarMap start(const VarMap& args);
+static VarMap restart(const VarMap& args);
 static VarMap stop(const VarMap& args);
 static VarMap lists(const VarMap& args);
 static VarMap query(const VarMap& args);
@@ -53,6 +54,7 @@
   api_1_0["enable"]     = enable;
   api_1_0["disable"]    = disable;
   api_1_0["start"]      = start;
+  api_1_0["restart"]	= restart;
   api_1_0["stop"]       = stop;
   api_1_0["list"]       = lists;
   api_1_0["query"]      = query;
@@ -149,6 +151,34 @@
 }
 
 VarMap 
+restart(const VarMap& args)
+{
+  list<XMLObject> serv_list;
+  try {
+    VarMap::const_iterator iter = args.find("services");
+    if (iter == args.end())
+      throw APIerror("missing services variable");
+    serv_list = iter->second.get_list_XML();
+  } catch ( String e ) {
+    throw APIerror(e);
+  }
+  
+  list<String> services, sets;
+  for (list<XMLObject>::const_iterator iter = serv_list.begin();
+       iter != serv_list.end();
+       iter++) {
+    if (iter->tag() == "service")
+      services.push_back(iter->get_attr("name"));
+    else if (iter->tag() == "set")
+      sets.push_back(iter->get_attr("name"));
+  }
+  
+  ServiceManager().restart(services, sets);
+  
+  return VarMap();
+}
+
+VarMap 
 stop(const VarMap& args)
 {
   list<XMLObject> serv_list;
/cvs/cluster/conga/ricci/test_suite/service/restart.xml,v  -->  standard output
revision 1.1
--- conga/ricci/test_suite/service/restart.xml
+++ -	2007-02-23 22:03:00.030740000 +0000
@@ -0,0 +1,16 @@
+<?xml version="1.0" ?>
+<ricci version="1.0" function="process_batch" async="false">
+<batch>
+
+<module name="service">
+<request sequence="1254" API_version="1.0">
+<function_call name="restart">
+  <var mutable="false" name="services" type="list_xml">
+    <service name="httpd"/>
+  </var>
+</function_call>
+</request>
+</module>
+
+</batch>
+</ricci>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]