[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
Branch: 	RHEL4
Changes by:	kupcevic sourceware org	2007-02-28 23:21:40

Modified files:
	ricci/docs     : service_api.html 
	ricci/modules/service: ServiceManager.cpp ServiceManager.h 
	                       ServiceModule.cpp 

Log message:
	add restart fcn to modservice

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/docs/service_api.html.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.1.4.1&r2=1.1.4.2
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/service/ServiceManager.cpp.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.7.2.2&r2=1.7.2.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/service/ServiceManager.h.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.2&r2=1.2.4.1
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/service/ServiceModule.cpp.diff?cvsroot=cluster&only_with_tag=RHEL4&r1=1.3&r2=1.3.4.1

--- conga/ricci/docs/service_api.html	2007/02/05 21:27:22	1.1.4.1
+++ conga/ricci/docs/service_api.html	2007/02/28 23:21:40	1.1.4.2
@@ -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:41:19	1.7.2.2
+++ conga/ricci/modules/service/ServiceManager.cpp	2007/02/28 23:21:40	1.7.2.3
@@ -172,7 +172,15 @@
 Service::start()
 {
   running();
-  run_service(name(), true);
+  run_service(name(), START);
+  *_running = true;
+}
+
+void 
+Service::restart()
+{
+  running();
+  run_service(name(), RESTART);
   *_running = true;
 }
 
@@ -180,7 +188,7 @@
 Service::stop()
 {
   running();
-  run_service(name(), false);
+  run_service(name(), STOP);
   *_running = false;
 }
 
@@ -217,7 +225,7 @@
 }
 
 void 
-Service::run_service(const String& name, bool on)
+Service::run_service(const String& name, ActionState state)
 {
   String path(INITD_DIR_PATH);
   path += name;
@@ -225,20 +233,27 @@
   String out, err;
   int status;
   vector<String> args;
-  if (on)
-    args.push_back("start");
-  else
-    args.push_back("stop");
+  switch (state) {
+    case START:
+      args.push_back("start");
+      break;
+    case STOP:
+      args.push_back("stop");
+      break;
+    case RESTART:
+      args.push_back("restart");
+      break;
+  }
   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 (state == START || state == RESTART) {
       if (!running)
-	throw String("service ") + name + " " + String(on?"start":"stop") + " failed";
+	throw String("service ") + name + " " + String(state == START ? "start" : "restart") + " failed";
     } else {
       if (running)
-	throw String("service ") + name + " " + String(on?"start":"stop") + " failed";
+	throw String("service ") + name + " stop failed";
     }
   }
 }
@@ -363,6 +378,19 @@
 }
 
 void 
+ServiceSet::restart()
+{
+  name();
+  try {
+    // ordered sequence: last started, first to be stoped
+    stop();
+    start();
+  } catch (String e) {
+    throw String("service set '") + name() + "' failed to restart";
+  }
+}
+
+void 
 ServiceSet::stop()
 {
   name();
@@ -589,6 +617,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/28 23:21:40	1.2.4.1
@@ -48,6 +48,7 @@
   
   void enable();
   void disable();
+  void restart();
   void start();
   void stop();
   
@@ -61,9 +62,15 @@
   mutable counting_auto_ptr<bool> _enabled;
   mutable counting_auto_ptr<bool> _running;
   
+  enum ActionState {
+    START,
+    STOP,
+    RESTART
+  };
+  
   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, ActionState state);
   
   friend class ServiceManager;
 
@@ -84,6 +91,7 @@
   void enable();
   void disable();
   void start();
+  void restart();
   void stop();
   
   std::list<Service> servs;
@@ -107,6 +115,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/28 23:21:40	1.3.4.1
@@ -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;


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