conga/ricci/modules/service ServiceManager.cpp ...
CVSROOT: /cvs/cluster
Module name: conga
Changes by: kupcevic at sourceware.org 2007-02-24 09:39:23
Modified files:
ricci/modules/service: ServiceManager.cpp ServiceManager.h
Log message:
- restart set in proper order
- localize internal enum
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/service/ServiceManager.cpp.diff?cvsroot=cluster&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/service/ServiceManager.h.diff?cvsroot=cluster&r1=1.3&r2=1.4
ricci/modules/service/ServiceManager.cpp +24 -20
@@ -172,7 +172,7 @@ Service::start() { running(); - run_service(name(), SERVICE_START); + run_service(name(), START); *_running = true; }
@@ -180,7 +180,7 @@ Service::restart() { running(); - run_service(name(), SERVICE_RESTART); + run_service(name(), RESTART); *_running = true; }
@@ -188,7 +188,7 @@ Service::stop() { running(); - run_service(name(), SERVICE_STOP); + run_service(name(), STOP); *_running = false; }
@@ -225,7 +225,7 @@ } void -Service::run_service(const String& name, int state) +Service::run_service(const String& name, ActionState state) { String path(INITD_DIR_PATH); path += name;
@@ -233,22 +233,27 @@ String out, err; int status; vector<String> args; - if (state == SERVICE_START) - args.push_back("start"); - else if (state == SERVICE_RESTART) - args.push_back("restart"); - else if (state == SERVICE_STOP) - 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 (state == SERVICE_START || state == SERVICE_RESTART) { - if (!running) - throw String("service ") + name + " " + String(state == SERVICE_START ? "start" : "restart") + " failed"; + bool running = service_running(name); + if (state == START || state == RESTART) { + if (!running) + throw String("service ") + name + " " + String(state == START ? "start" : "restart") + " failed"; } else { - if (running) - throw String("service ") + name + " " + String("stop") + " failed"; + if (running) + throw String("service ") + name + " stop failed"; } } }
@@ -377,10 +382,9 @@ { name(); try { - for (list<Service>::iterator iter = servs.begin(); - iter != servs.end(); - iter++) - iter->restart(); + // ordered sequence: last started, first to be stoped + stop(); + start(); } catch (String e) { throw String("service set '") + name() + "' failed to restart"; }
ricci/modules/service/ServiceManager.h +7 -6
@@ -34,11 +34,6 @@class ServiceManager; -enum { -SERVICE_STOP , -SERVICE_START , -SERVICE_RESTART -};class Service {
@@ -67,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, int state); + static void run_service(const String& name, ActionState state); friend class ServiceManager;