qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r533828 - in /incubator/qpid/trunk/qpid/cpp: README qpidc.spec.in src/Makefile.am src/qpid/broker/Daemon.cpp src/qpid/broker/Daemon.h src/qpidd.cpp src/tests/Makefile.am src/tests/daemon_test src/tests/test_env
Date Mon, 30 Apr 2007 19:03:55 GMT
Author: aconway
Date: Mon Apr 30 12:03:53 2007
New Revision: 533828

URL: http://svn.apache.org/viewvc?view=rev&rev=533828
Log:
Resolves: QPID-298, QPID-304: qpidd flags to control broker daemon.

* README: added new dependency, libdaemon.
* qpidc.spec.in: libdaemon dependencies.
* broker/Daemon.h|cpp: Daemon and pid file management, wrapper for libdaemon.
* qpidd.cpp modifid flags
  -d [ --daemon ] - waits till deamon is listening before returning.
* qpidd.cpp: new flags
  -q [ --quit ]                     Stop the running daemon politely.
  -k [ --kill ]                     Kill the running daemon harshly.
  -c [ --check ]                    If daemon is running return 0.
  --wait SECONDS (=10)              Maximum wait for daemon response.
  --ppid                            Print daemon pid to stdout
* tests/dameon_test: Test daemon startup, shutdown.
* test_env: minor fix.

Added:
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp
      - copied, changed from r533819, incubator/qpid/branches/M2/cpp/lib/broker/Daemon.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.h
      - copied unchanged from r533819, incubator/qpid/branches/M2/cpp/lib/broker/Daemon.h
    incubator/qpid/trunk/qpid/cpp/src/tests/daemon_test
      - copied, changed from r533819, incubator/qpid/branches/M2/cpp/tests/daemon_test
Modified:
    incubator/qpid/trunk/qpid/cpp/README
    incubator/qpid/trunk/qpid/cpp/qpidc.spec.in
    incubator/qpid/trunk/qpid/cpp/src/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/tests/test_env

Modified: incubator/qpid/trunk/qpid/cpp/README
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/README?view=diff&rev=533828&r1=533827&r2=533828
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/README (original)
+++ incubator/qpid/trunk/qpid/cpp/README Mon Apr 30 12:03:53 2007
@@ -38,7 +38,7 @@
  * apr     <http://apr.apache.org>          (1.2.7)
  * boost   <http://www.boost.org>           (1.33.1)
  * cppunit <http://cppunit.sourceforge.net> (1.11.4)
-
+ * libdaemon <http://www.stud.uni-hamburg.de/users/lennart/projects/libdaemon> (0.10)
 Using tools:
 
  * boost-jam  <http://boost.sourceforge.net/>          (3.1.13)

Modified: incubator/qpid/trunk/qpid/cpp/qpidc.spec.in
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/qpidc.spec.in?view=diff&rev=533828&r1=533827&r2=533828
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/qpidc.spec.in (original)
+++ incubator/qpid/trunk/qpid/cpp/qpidc.spec.in Mon Apr 30 12:03:53 2007
@@ -20,11 +20,13 @@
 BuildRequires: e2fsprogs-devel
 BuildRequires: graphviz
 BuildRequires: help2man
+BuildRequires: libdaemon-devel
 BuildRequires: libtool
 BuildRequires: pkgconfig
 
-Requires: boost
 Requires: apr
+Requires: boost
+Requires: libdaemon
 
 Requires(post):/sbin/chkconfig
 Requires(preun):/sbin/chkconfig

Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?view=diff&rev=533828&r1=533827&r2=533828
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Mon Apr 30 12:03:53 2007
@@ -5,10 +5,9 @@
 # -I top_builddir for config.h
 INCLUDES = -I$(top_builddir)  -I$(top_srcdir)/gen 
 
-qpidd_LDADD = \
-  libqpidbroker.la \
-  libqpidcommon.la \
-  -lboost_program_options 
+qpidd_LDADD =					\
+  libqpidbroker.la				\
+  libqpidcommon.la
 
 sbin_PROGRAMS = qpidd
 qpidd_SOURCES = qpidd.cpp
@@ -104,7 +103,7 @@
   qpid/CommonOptions.cpp
 
 
-libqpidbroker_la_LIBADD = libqpidcommon.la 
+libqpidbroker_la_LIBADD = libqpidcommon.la -ldaemon -lboost_filesystem
 libqpidbroker_la_LDFLAGS = -version-info $(LIBTOOL_VERSION_INFO_ARG)
 libqpidbroker_la_SOURCES = \
   qpid/broker/AccumulatedAck.cpp \
@@ -118,6 +117,7 @@
   qpid/broker/BrokerQueue.cpp \
   qpid/broker/Connection.cpp \
   qpid/broker/ConnectionFactory.cpp \
+  qpid/broker/Daemon.cpp \
   qpid/broker/DeliverableMessage.cpp \
   qpid/broker/DeliveryRecord.cpp \
   qpid/broker/DirectExchange.cpp \
@@ -204,6 +204,7 @@
   qpid/broker/ConnectionFactory.h \
   qpid/broker/ConnectionToken.h \
   qpid/broker/Content.h \
+  qpid/broker/Daemon.h \
   qpid/broker/DeliveryRecord.h \
   qpid/broker/HeadersExchange.h \
   qpid/broker/LazyLoadedContent.h \

Copied: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp (from r533819, incubator/qpid/branches/M2/cpp/lib/broker/Daemon.cpp)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp?view=diff&rev=533828&p1=incubator/qpid/branches/M2/cpp/lib/broker/Daemon.cpp&r1=533819&p2=incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp&r2=533828
==============================================================================
--- incubator/qpid/branches/M2/cpp/lib/broker/Daemon.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Daemon.cpp Mon Apr 30 12:03:53 2007
@@ -15,8 +15,8 @@
  * limitations under the License.
  *
  */
-#include "QpidError.h"
 #include "Daemon.h"
+#include "qpid/QpidError.h"
 #include <libdaemon/daemon.h>
 #include <errno.h>
 #include <unistd.h>

Modified: incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp?view=diff&rev=533828&r1=533827&r2=533828
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpidd.cpp Mon Apr 30 12:03:53 2007
@@ -24,29 +24,51 @@
 #include <signal.h>
 #include "config.h"
 #include "qpid/sys/posix/check.h"
+#include "qpid/broker/Daemon.h"
 
 using namespace qpid;
 using namespace qpid::broker;
 using namespace qpid::sys;
 using namespace std;
 
+Broker::shared_ptr brokerPtr;
+
+void handle_signal(int /*signal*/){
+    std::cerr << "Shutting down..." << std::endl;
+    brokerPtr->shutdown();
+}
+
+
 /** Command line options */
 struct QpiddOptions : public Broker::Options
 {
     bool help;
     bool version;
     bool daemon;
+    bool quit;
+    bool kill;
+    bool check;
+    bool ppid;
+    int wait;
     string config;
     po::options_description desc;
     
     QpiddOptions() :
         help(false), version(false), daemon(false),
+        quit(false), kill(false), check(false), ppid(false), wait(10),
         config("/etc/qpidd.conf"),
         desc("Options")
     {
         using namespace po;
         desc.add_options()
-            ("daemon,d", optValue(daemon), "Run as a daemon");
+            ("daemon,d", optValue(daemon), "Run as a daemon.")
+            ("quit,q", optValue(quit), "Stop the running daemon politely.")
+            ("kill,k", optValue(kill), "Kill the running daemon harshly.")
+            ("check,c", optValue(check), "If daemon is running return 0.")
+            ("wait", optValue(wait, "SECONDS"),
+             "Maximum wait for daemon response.")
+            ("ppid", optValue(ppid), "Print daemon pid to stdout" );
+        po::options_description brokerOpts;
         Broker::Options::addTo(desc);
         desc.add_options()
             ("config", optValue(config, "FILE"), "Configuation file")
@@ -86,43 +108,80 @@
     config.usage(out); return out;
 }
 
-Broker::shared_ptr brokerPtr;
-
-void handle_signal(int /*signal*/){
-    if (brokerPtr) {
-        cerr << "Shutting down..." << endl;
-        brokerPtr->shutdown();
-    }
-}
-
 int main(int argc, char* argv[])
 {
     QpiddOptions config;
     try {
         config.parse(argc, argv);
+        string name=(boost::format("%s.%d")
+                     % Daemon::nameFromArgv0(argv[0])
+                     % (config.port)).str();
+        // Spelled 'demon' to avoid clash with daemon.h function.
+        Daemon demon(name, config.wait);
+
+        // Options that just print information.
         if(config.help) {
             config.usage(cout);
+            return 0;
         }
-        else if (config.version) {
+        if (config.version) {
             cout << "qpidd (" << PACKAGE_NAME << ") version "
                  << PACKAGE_VERSION << endl;
+            return 0;
         }
-        else {
-            brokerPtr=Broker::create(config);
-            signal(SIGINT, handle_signal);
-            if (config.daemon) {
-                if (daemon(0, 0) < 0) // daemon(nochdir, noclose)
-                    throw QPID_ERROR(
-                        INTERNAL_ERROR,
-                        "Failed to detach as daemon: "+ strError(errno));
+
+        // Options that affect an already running daemon.
+        if (config.quit || config.kill || config.check) {
+            pid_t pid = demon.check();
+            if (config.ppid && pid > 0)
+                cout << pid << endl;
+            if (config.kill)
+                demon.kill();
+            else if (config.quit)
+                demon.quit();
+            if (config.check && pid <= 0)
+                return 1;
+            return 0;
+        }
+
+        // Starting the broker:
+        signal(SIGINT, handle_signal);
+        if (config.daemon) {
+            pid_t pid = demon.fork();
+            if (pid == 0) {  // Child
+                try {
+                    brokerPtr=Broker::create(config);
+                    demon.ready();   // Notify parent we're ready.
+                    brokerPtr->run();
+                } catch (const exception& e) {
+                    // TODO aconway 2007-04-26: Log this, cerr is lost.
+                    cerr << "Broker daemon failed: " << e.what() << endl;
+                    demon.failed(); // Notify parent we failed.
+                    return 1;
+                }
+            }
+            else if (pid > 0) { // Parent
+                if (config.ppid)
+                    cout << pid << endl;
+                return 0;
             }
-            brokerPtr->run();
+            else { // pid < 0
+                throw Exception("fork failed"+strError(errno));
+            }
+        } // Non-daemon broker.
+        else {
+            brokerPtr = Broker::create(config);
+            brokerPtr->run(); 
         }
         return 0;
     }
-    catch(const exception& e) {
+    catch(const po::error& e) {
+        // Command line parsing error.
         cerr << "Error: " << e.what() << endl
              << "Type 'qpidd --help' for usage." << endl;
+    }
+    catch(const exception& e) {
+        cerr << "Error: " << e.what() << endl;
     }
     return 1;
 }

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am?view=diff&rev=533828&r1=533827&r2=533828
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am Mon Apr 30 12:03:53 2007
@@ -57,7 +57,7 @@
 TESTS_ENVIRONMENT = VALGRIND=$(VALGRIND) srcdir=$(srcdir)
 
 CLIENT_TESTS = client_test quick_topictest
-TESTS = run-unit-tests start_broker $(CLIENT_TESTS) python_tests kill_broker
+TESTS = run-unit-tests start_broker $(CLIENT_TESTS) python_tests kill_broker daemon_test
 
 EXTRA_DIST =					\
   test_env					\

Copied: incubator/qpid/trunk/qpid/cpp/src/tests/daemon_test (from r533819, incubator/qpid/branches/M2/cpp/tests/daemon_test)
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/daemon_test?view=diff&rev=533828&p1=incubator/qpid/branches/M2/cpp/tests/daemon_test&r1=533819&p2=incubator/qpid/trunk/qpid/cpp/src/tests/daemon_test&r2=533828
==============================================================================
--- incubator/qpid/branches/M2/cpp/tests/daemon_test (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/daemon_test Mon Apr 30 12:03:53 2007
@@ -4,19 +4,21 @@
 #
 
 TEMP=`mktemp`
+qpidd=../qpidd
+client_tests=./client_test
 trap 'rm -f $TEMP' 0
 
 fail() { echo FAIL: $0:$* 1>&2; exit 1; }
 
 # Start and stop daemon.
-PID=`qpidd --check --ppid` && fail $LINENO: qpidd already running $PID
-qpidd -d || $LINENO: qpidd -d failed
-qpidd --check || fail $LINENO: qpidd --check says qpidd didnt start
-client_test > $TEMP || fail $LINENO:  client_test: `cat $TEMP`
-qpidd -q || fail $LINENO: qpidd -q failed
-qpidd -d || fail $LINENO: restart after quit failed.
-qpidd -k || fail $LINENO: qpidd -k failed
+PID=`$qpidd --check --ppid` && fail $LINENO: $qpidd already running $PID
+$qpidd -d || $LINENO: $qpidd -d failed
+$qpidd --check || fail $LINENO: $qpidd --check says $qpidd didnt start
+./client_test > $TEMP || fail $LINENO:  client_test: `cat $TEMP`
+$qpidd -q || fail $LINENO: $qpidd -q failed
+$qpidd -d || fail $LINENO: restart after quit failed.
+$qpidd -k || fail $LINENO: $qpidd -k failed
 # Supress expected message re. cleanup of old PID file.
-PID=`qpidd --check --ppid 2>/dev/null` && fail $LINENO: $PID still running after
kill. 
+PID=`$qpidd --check --ppid 2>/dev/null` && fail $LINENO: $PID still running after
kill. 
 
 true

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/test_env
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/test_env?view=diff&rev=533828&r1=533827&r2=533828
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/test_env (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/test_env Mon Apr 30 12:03:53 2007
@@ -6,7 +6,7 @@
 # Use VALGRIND if set, else look on path. 
 test -z "$VALGRIND" && VALGRIND=`which valgrind 2>/dev/null`
 # No valgrind, just run the command
-test -z "$VALGRIND" && exec  libtool --mode=execute "$@"
+test -z "$VALGRIND" && { exec  libtool --mode=execute "$@"; exit $?; }
 
 test "$VERBOSE" = yes && set -x
 test -z "$vg_log" && vg_log=valgrind.out



Mime
View raw message