qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r1680550 - in /qpid/trunk/qpid/cpp: etc/qpidd.in src/posix/QpiddBroker.cpp
Date Wed, 20 May 2015 12:59:46 GMT
Author: aconway
Date: Wed May 20 12:59:46 2015
New Revision: 1680550

URL: http://svn.apache.org/r1680550
Log:
QPID-6548: SYSV init scripts do not work properly wiht SSL-only broker.

Previously the broker was writing a PID file with the port number as a suffix.
This was confusing the tools when using SSL and no explicit port, as the actual
listening port is 5671 but qpidd -c was looking for 5672.

This commit introduces a simple --pidfile option which writes the pid exactly
where you tell it with no frills. The original port-pidfile setup is over
complex and not really necessary, it can be deprecated at some future time.

Modified:
    qpid/trunk/qpid/cpp/etc/qpidd.in
    qpid/trunk/qpid/cpp/src/posix/QpiddBroker.cpp

Modified: qpid/trunk/qpid/cpp/etc/qpidd.in
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/etc/qpidd.in?rev=1680550&r1=1680549&r2=1680550&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/etc/qpidd.in (original)
+++ qpid/trunk/qpid/cpp/etc/qpidd.in Wed May 20 12:59:46 2015
@@ -100,16 +100,13 @@ lock() {
 start() {
     lock
     echo -n $"Starting Qpid AMQP daemon: "
-    daemon --pidfile $pidfile --check $prog --user qpidd $QPID_BIN --config $QPID_CONFIG
--daemon $QPIDD_OPTIONS --close-fd $FLOCK_FD
+    touch $pidfile
+    chown qpidd.qpidd $pidfile
+    [ -x /sbin/restorecon ] && /sbin/restorecon $pidfile
+    daemon --pidfile $pidfile --check $prog --user qpidd $QPID_BIN --config $QPID_CONFIG
--daemon $QPIDD_OPTIONS --close-fd $FLOCK_FD --pidfile $pidfile
     RETVAL=$?
     echo
     [ $RETVAL = 0 ] && touch $lockfile
-    if [ $RETVAL = 0 ]; then
-	touch $pidfile
-	chown qpidd.qpidd $pidfile
-        [ -x /sbin/restorecon ] && /sbin/restorecon $pidfile
-	runuser - -s /bin/sh qpidd -c "$QPID_BIN --config $QPID_CONFIG --check > $pidfile"
-    fi
     return $RETVAL
 }
 

Modified: qpid/trunk/qpid/cpp/src/posix/QpiddBroker.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/posix/QpiddBroker.cpp?rev=1680550&r1=1680549&r2=1680550&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/posix/QpiddBroker.cpp (original)
+++ qpid/trunk/qpid/cpp/src/posix/QpiddBroker.cpp Wed May 20 12:59:46 2015
@@ -27,21 +27,24 @@
 #include "qpid/log/Logger.h"
 
 #include <iostream>
+#include <fstream>
 #include <signal.h>
 #include <unistd.h>
 #include <sys/utsname.h>
 
 using std::cout;
 using std::endl;
+using std::ifstream;
+using std::ofstream;
 
 namespace qpid {
 namespace broker {
 
 BootstrapOptions::BootstrapOptions(const char* argv0)
-  : qpid::Options("Options"),
-    common("", QPIDD_CONF_FILE, QPIDC_CONF_FILE),
-    module(QPIDD_MODULE_DIR),
-    log(argv0)
+    : qpid::Options("Options"),
+      common("", QPIDD_CONF_FILE, QPIDC_CONF_FILE),
+      module(QPIDD_MODULE_DIR),
+      log(argv0)
 {
     add(common);
     add(module);
@@ -64,6 +67,7 @@ struct DaemonOptions : public qpid::Opti
     std::vector<int> closeFd;
     int wait;
     std::string piddir;
+    std::string pidfile;
     std::string transport;
 
     DaemonOptions() : qpid::Options("Daemon options"), daemon(false), quit(false), kill(false),
check(false), wait(600), transport(TCP)
@@ -80,6 +84,7 @@ struct DaemonOptions : public qpid::Opti
             ("daemon,d", pure_switch(daemon), "Run as a daemon. Logs to syslog by default
in this mode.")
             ("transport", optValue(transport, "TRANSPORT"), "The transport for which to return
the port")
             ("pid-dir", optValue(piddir, "DIR"), "Directory where port-specific PID file
is stored")
+            ("pidfile", optValue(pidfile, "FILE"), "File name to store the PID in daemon
mode. Used as-is, no directory or suffixes added.")
             ("close-fd", optValue(closeFd, "FD"), "File descriptors that the daemon should
close")
             ("wait,w", optValue(wait, "SECONDS"), "Sets the maximum wait time to initialize
or shutdown the daemon. If the daemon fails to initialize/shutdown, prints an error and returns
1")
             ("check,c", pure_switch(check), "Prints the daemon's process ID to stdout and
returns 0 if the daemon is running, otherwise returns 1")
@@ -98,10 +103,10 @@ struct QpiddPosixOptions : public QpiddO
 };
 
 QpiddOptions::QpiddOptions(const char* argv0)
-  : qpid::Options("Options"),
-    common("", QPIDD_CONF_FILE, QPIDC_CONF_FILE),
-    module(QPIDD_MODULE_DIR),
-    log(argv0)
+    : qpid::Options("Options"),
+      common("", QPIDD_CONF_FILE, QPIDC_CONF_FILE),
+      module(QPIDD_MODULE_DIR),
+      log(argv0)
 {
     add(common);
     add(module);
@@ -127,11 +132,23 @@ struct ScopedSetBroker {
     ~ScopedSetBroker() { qpid::broker::SignalHandler::setBroker(0); }
 };
 
+namespace {
+
+/// Write a pid file if requested
+void writePid(const std::string& filename) {
+    if (!filename.empty()) {
+        ofstream pidfile(filename.c_str());
+        pidfile << ::getpid() << endl;
+        pidfile.close();
+    }
+}
+}
+
 struct QpiddDaemon : public Daemon {
     QpiddPosixOptions *options;
 
     QpiddDaemon(std::string pidDir, QpiddPosixOptions *opts)
-      : Daemon(pidDir), options(opts) {}
+        : Daemon(pidDir), options(opts) {}
 
     /** Code for parent process */
     void parent() {
@@ -153,6 +170,7 @@ struct QpiddDaemon : public Daemon {
         if (options->parent->broker.enableMgmt && (options->parent->broker.port
== 0 || options->daemon.transport != TCP)) {
             boost::dynamic_pointer_cast<qmf::org::apache::qpid::broker::Broker>(brokerPtr->GetManagementObject())->set_port(port);
         }
+        writePid(options->daemon.pidfile);
         brokerPtr->run();
     }
 };
@@ -160,18 +178,25 @@ struct QpiddDaemon : public Daemon {
 int QpiddBroker::execute (QpiddOptions *options) {
     // Options that affect a running daemon.
     QpiddPosixOptions *myOptions =
-      static_cast<QpiddPosixOptions *>(options->platform.get());
+        static_cast<QpiddPosixOptions *>(options->platform.get());
     if (myOptions == 0)
         throw Exception("Internal error obtaining platform options");
 
     if (myOptions->daemon.check || myOptions->daemon.quit || myOptions->daemon.kill)
{
-        pid_t pid;
-        try {
-            pid = Daemon::getPid(myOptions->daemon.piddir, options->broker.port);
-        } catch (const Exception& e) {
-            // This is not a critical error, usually means broker is not running
-            QPID_LOG(notice, "Broker is not running: " << e.what());
-            return 1;
+        pid_t pid = 0;
+        if (!myOptions->daemon.pidfile.empty()) {
+            ifstream pidfile(myOptions->daemon.pidfile.c_str());
+            pidfile >> pid;
+            pidfile.close();
+        }
+        if (pid == 0) {
+            try {
+                pid = Daemon::getPid(myOptions->daemon.piddir, options->broker.port);
+            } catch (const Exception& e) {
+                // This is not a critical error, usually means broker is not running
+                QPID_LOG(notice, "Broker is not running: " << e.what());
+                return 1;
+            }
         }
         if (pid < 0)
             return 1;
@@ -211,6 +236,7 @@ int QpiddBroker::execute (QpiddOptions *
                 boost::dynamic_pointer_cast<qmf::org::apache::qpid::broker::Broker>(brokerPtr->GetManagementObject())->set_port(port);
             }
         }
+        writePid(myOptions->daemon.pidfile);
         brokerPtr->run();
     }
     return 0;



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message