The branch, master has been updated
       via  e7a4b7e35a1e4b826846e2494a3803abb57065ee (commit)
       via  1e989894764e4cd1d551c44784d91cb295cd790d (commit)
       via  abb64f62efaa70df4b87c030b96300eafd98e6a3 (commit)
       via  90cb337e5ccf397b69a64298559a428ff508f196 (commit)
       via  687e2eace4f48400cf5029914f62b6ddabb85378 (commit)
       via  996e74d3db0c50f91b320af8ab7c43ea6b1136af (commit)
       via  ba8866d40125bab06391a17d48ff06a4a9f9da89 (commit)
       via  59b019a97aad9a731f9080ea5be14d0dbdfe03d6 (commit)
      from  06ac62f890299021220214327f1b611c3cf00145 (commit)

http://gitweb.samba.org/?p=ctdb.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit e7a4b7e35a1e4b826846e2494a3803abb57065ee
Author: Martin Schwenke <mar...@meltin.net>
Date:   Mon Apr 15 19:15:22 2013 +1000

    initscript: Remove duplicate setting of $ctdbd
    
    Signed-off-by: Martin Schwenke <mar...@meltin.net>
    Reviewed-by: Michael Adam <ob...@samba.org>

commit 1e989894764e4cd1d551c44784d91cb295cd790d
Author: Martin Schwenke <mar...@meltin.net>
Date:   Tue Apr 16 11:40:55 2013 +1000

    util: Removed unused declaration of ctdbd_start()
    
    Signed-off-by: Martin Schwenke <mar...@meltin.net>
    Reviewed-by: Michael Adam <ob...@samba.org>

commit abb64f62efaa70df4b87c030b96300eafd98e6a3
Author: Martin Schwenke <mar...@meltin.net>
Date:   Mon Apr 15 13:31:42 2013 +1000

    include: Move ctdb_start_daemon() from ctdb_client.h to ctdb_private.h
    
    It really is internal.
    
    Signed-off-by: Martin Schwenke <mar...@meltin.net>
    Pair-programmed-with: Amitay Isaacs <ami...@gmail.com>
    Reviewed-by: Michael Adam <ob...@samba.org>

commit 90cb337e5ccf397b69a64298559a428ff508f196
Author: Martin Schwenke <mar...@meltin.net>
Date:   Mon Apr 15 15:42:55 2013 +1000

    scripts: ctdb-crash-cleanup.sh uses initscript to see if ctdbd is running
    
    "ctdb ping" can time out.  How many times should we try?
    
    Instead, depend on the initscript to implement something sane.
    
    Signed-off-by: Martin Schwenke <mar...@meltin.net>
    Reviewed-by: Michael Adam <ob...@samba.org>

commit 687e2eace4f48400cf5029914f62b6ddabb85378
Author: Martin Schwenke <mar...@meltin.net>
Date:   Mon Apr 15 15:18:12 2013 +1000

    initscript: Use a PID file to implement the "status" option
    
    Using "ctdb ping" and "ctdb status" is fraught with danger.  These
    commands can timeout when ctdbd is running, leading callers to believe
    that ctdbd is not running.  Timeouts could be increased but we would
    still have to handle potential timeouts.
    
    Everything else in the world implements the "status" option by
    checking if the relevant process is running.  This change makes CTDB
    do the same thing and uses standard distro functions.
    
    This change is backward compatible in sense that a missing
    /var/run/ctdb/ directory means that we don't do a PID file check but
    just depend on the distro's checking method.  Therefore, if CTDB was
    started with an older version of this script then "service ctdb
    status" will still work.
    
    This script does not support changing the value of CTDB_VALGRIND
    between calls.  If you start with CTDB_VALGRIND=yes then you need to
    check status with the same setting.  CTDB_VALGRIND is a debug
    variable, so this is acceptable.
    
    This also adds sourcing of /lib/lsb/init-functions to make the Debian
    function status_of_proc() available.
    
    Signed-off-by: Martin Schwenke <mar...@meltin.net>
    Pair-programmed-with: Amitay Isaacs <ami...@gmail.com>
    Reviewed-by: Michael Adam <ob...@samba.org>

commit 996e74d3db0c50f91b320af8ab7c43ea6b1136af
Author: Martin Schwenke <mar...@meltin.net>
Date:   Mon Apr 15 13:32:57 2013 +1000

    ctdbd: Add --pidfile option
    
    Default is not to create a pid file.
    
    Signed-off-by: Martin Schwenke <mar...@meltin.net>
    Pair-programmed-with: Amitay Isaacs <ami...@gmail.com>
    Reviewed-by: Michael Adam <ob...@samba.org>

commit ba8866d40125bab06391a17d48ff06a4a9f9da89
Author: Martin Schwenke <mar...@meltin.net>
Date:   Mon Apr 15 16:14:40 2013 +1000

    util: ctdb_fork() should call ctdb_set_child_info()
    
    For now we pass NULL as the child name.  Later we'll give ctdb_fork()
    and friends an extra argument and pass that through.
    
    Signed-off-by: Martin Schwenke <mar...@meltin.net>
    Pair-programmed-with: Amitay Isaacs <ami...@gmail.com>
    Reviewed-by: Michael Adam <ob...@samba.org>

commit 59b019a97aad9a731f9080ea5be14d0dbdfe03d6
Author: Martin Schwenke <mar...@meltin.net>
Date:   Tue Apr 16 11:11:11 2013 +1000

    util: New functions ctdb_set_child_info() and ctdb_is_child_process()
    
    Must be called by all child processes.
    
    Signed-off-by: Martin Schwenke <mar...@meltin.net>
    Reviewed-by: Michael Adam <ob...@samba.org>

-----------------------------------------------------------------------

Summary of changes:
 common/ctdb_fork.c           |   24 +++++++++++
 config/ctdb-crash-cleanup.sh |    2 +-
 config/ctdb.init             |   88 ++++++++++++++++++++++++++---------------
 include/ctdb_client.h        |    1 -
 include/ctdb_private.h       |    7 +++-
 server/ctdb_daemon.c         |   36 +++++++++++++++++-
 server/ctdbd.c               |    1 +
 7 files changed, 123 insertions(+), 36 deletions(-)


Changeset truncated at 500 lines:

diff --git a/common/ctdb_fork.c b/common/ctdb_fork.c
index 9e3a06d..d372ae0 100644
--- a/common/ctdb_fork.c
+++ b/common/ctdb_fork.c
@@ -23,6 +23,28 @@
 #include "../include/ctdb_private.h"
 #include "../common/rb_tree.h"
 
+static bool is_child = false;
+
+void ctdb_set_child_info(TALLOC_CTX *mem_ctx, const char *child_name_fmt, ...)
+{
+       is_child = true;
+       if (child_name_fmt != NULL) {
+               va_list ap;
+               char *t;
+
+               va_start(ap, child_name_fmt);
+               t = talloc_vasprintf(mem_ctx, child_name_fmt, ap);
+               debug_extra = talloc_asprintf(mem_ctx, "%s:", t);
+               talloc_free(t);
+               va_end(ap);
+       }
+}
+
+bool ctdb_is_child_process(void)
+{
+       return is_child;
+}
+
 /*
  * This function forks a child process and drops the realtime 
  * scheduler for the child process.
@@ -37,6 +59,8 @@ pid_t ctdb_fork_no_free_ringbuffer(struct ctdb_context *ctdb)
                return -1;
        }
        if (pid == 0) {
+               ctdb_set_child_info(ctdb, NULL);
+
                /* Close the Unix Domain socket and the TCP socket.
                 * This ensures that none of the child processes will
                 * look like the main daemon when it is not running.
diff --git a/config/ctdb-crash-cleanup.sh b/config/ctdb-crash-cleanup.sh
index f426056..7796223 100755
--- a/config/ctdb-crash-cleanup.sh
+++ b/config/ctdb-crash-cleanup.sh
@@ -5,7 +5,7 @@
 #
 
 # If ctdb is running, just exit
-if ctdb ping >/dev/null 2>&1 ; then
+if service ctdb status >/dev/null 2>&1 ; then
     exit 0
 fi
 
diff --git a/config/ctdb.init b/config/ctdb.init
index dafe8f7..d92fef0 100755
--- a/config/ctdb.init
+++ b/config/ctdb.init
@@ -6,7 +6,7 @@
 # chkconfig:           - 90 01
 #
 # description:                 Starts and stops the clustered tdb daemon
-# pidfile:             /var/run/ctdbd/ctdbd.pid
+# pidfile:             /var/run/ctdb/ctdbd.pid
 #
 
 ### BEGIN INIT INFO
@@ -32,6 +32,10 @@ fi
     LC_ALL=en_US.UTF-8
 }
 
+if [ -f /lib/lsb/init-functions ] ; then
+    . /lib/lsb/init-functions
+fi
+
 # Avoid using root's TMPDIR
 unset TMPDIR
 
@@ -50,6 +54,7 @@ detect_init_style
 export CTDB_INIT_STYLE
 
 ctdbd=${CTDBD:-/usr/sbin/ctdbd}
+pidfile="/var/run/ctdb/ctdbd.pid"
 
 if [ "$CTDB_VALGRIND" = "yes" ]; then
     init_style="valgrind"
@@ -84,6 +89,9 @@ build_ctdb_options () {
     }
     maybe_set "--reclock"                "$CTDB_RECOVERY_LOCK"
 
+    mkdir -p $(dirname "$pidfile")
+    maybe_set "--pidfile"                "$pidfile"
+
     # build up CTDB_OPTIONS variable from optional parameters
     maybe_set "--logfile"                "$CTDB_LOGFILE"
     maybe_set "--nlist"                  "$CTDB_NODES"
@@ -221,8 +229,6 @@ wait_until_ready () {
     done
 }
 
-ctdbd=${CTDBD:-/usr/sbin/ctdbd}
-
 start() {
     echo -n $"Starting ctdbd service: "
 
@@ -329,6 +335,8 @@ stop() {
     # make sure all ips are dropped, pfkill -9 might leave them hanging around
     drop_all_public_ips
 
+    rm -f "$pidfile"
+
     case $init_style in
        suse)
            # re-set the return code to the recorded RETVAL in order
@@ -351,33 +359,47 @@ restart() {
     start
 }
 
-status() {
-    echo -n $"Checking for ctdbd service: "
-    _out=$(ctdb ping 2>&1) || {
-       RETVAL=$?
-       echo -n "  ctdbd not running. "
-       case $init_style in
-           suse)
-               set_retval $RETVAL
-               rc_status -v
-               ;;
-           redhat)
-               if [ -f /var/lock/subsys/ctdb ]; then
-                       echo $"ctdb dead but subsys locked"
-                       RETVAL=2
-               else
-                       echo $"ctdb is stopped"
-                       RETVAL=3
-               fi
-               ;;
-       esac
-        echo 'Output from "ctdb ping":'
-        echo "$_out"
+# Given that CTDB_VALGRIND is a debug option we don't support the pid
+# file.  We just do a quick and dirty hack instead.  Otherwise we just
+# end up re-implementing each distro's pidfile support...
+check_status_valgrind ()
+{
+    if pkill -0 -f "valgrind.*${ctdbd}" ; then
+       echo "ctdbd is running under valgrind..."
+       return 0
+    else
+       echo "ctdbd is not running"
+       return 1
+    fi
+}
 
-       return $RETVAL
-    }
-    echo ""
-    ctdb status
+check_status ()
+{
+    # Backward compatibility.  When we arrange to pass --pidfile to
+    # ctdbd we also create the directory that will contain it.  If
+    # that directory is missing then we don't use the pidfile to check
+    # status.
+    if [ -d $(dirname "$pidfile") ] ; then
+       _pf_opt="-p $pidfile"
+    else
+       _pf_opt=""
+    fi
+
+    case "$init_style" in
+       valgrind)
+           check_status_valgrind
+           ;;
+       suse)
+           checkproc $_pf_opt "$ctdbd"
+           rc_status -v
+           ;;
+       redhat)
+           status $_pf_opt -l "ctdb" "$ctdbd"
+           ;;
+       debian)
+           status_of_proc $_pf_opt "$ctdbd" "ctdb"
+           ;;
+    esac
 }
 
 
@@ -394,14 +416,16 @@ case "$1" in
        restart
        ;;
     status)
-       status
+       check_status
        ;;
     condrestart|try-restart)
-       ctdb status > /dev/null && restart || :
+       if check_status >/dev/null ; then
+           restart
+       fi
        ;;
     cron)
        # used from cron to auto-restart ctdb
-       ctdb status > /dev/null || restart
+       check_status >/dev/null || restart
        ;;
     *)
        echo $"Usage: $0 
{start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"
diff --git a/include/ctdb_client.h b/include/ctdb_client.h
index 1b90ffb..564c563 100644
--- a/include/ctdb_client.h
+++ b/include/ctdb_client.h
@@ -100,7 +100,6 @@ int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const char 
*nodeip);
   start the ctdb protocol
 */
 int ctdb_start(struct ctdb_context *ctdb);
-int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool 
use_syslog, const char *public_address_list);
 
 /*
   attach to a ctdb database
diff --git a/include/ctdb_private.h b/include/ctdb_private.h
index d0c4234..09f7dd9 100644
--- a/include/ctdb_private.h
+++ b/include/ctdb_private.h
@@ -760,7 +760,9 @@ struct ctdb_call_state *ctdb_call_local_send(struct 
ctdb_db_context *ctdb_db,
                                             TDB_DATA *data);
 
 
-int ctdbd_start(struct ctdb_context *ctdb);
+int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork,
+                     bool use_syslog,
+                     const char *public_address_list);
 struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, 
struct ctdb_call *call);
 int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
 
@@ -1080,6 +1082,8 @@ void ctdb_restore_scheduler(struct ctdb_context *ctdb);
 struct tevent_signal *ctdb_init_sigchld(struct ctdb_context *ctdb);
 pid_t ctdb_fork(struct ctdb_context *ctdb);
 pid_t ctdb_fork_no_free_ringbuffer(struct ctdb_context *ctdb);
+void ctdb_set_child_info(TALLOC_CTX *mem_ctx, const char *child_name_fmt, ...);
+bool ctdb_is_child_process(void);
 int ctdb_kill(struct ctdb_context *ctdb, pid_t pid, int signum);
 
 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb, 
@@ -1398,6 +1402,7 @@ int32_t ctdb_control_set_recmaster(struct ctdb_context 
*ctdb, uint32_t opcode, T
 
 extern int script_log_level;
 extern bool fast_start;
+extern const char *ctdbd_pidfile;
 
 int32_t ctdb_control_get_event_script_status(struct ctdb_context *ctdb,
                                             uint32_t call_type,
diff --git a/server/ctdb_daemon.c b/server/ctdb_daemon.c
index 983f62d..17902b3 100644
--- a/server/ctdb_daemon.c
+++ b/server/ctdb_daemon.c
@@ -36,6 +36,8 @@ struct ctdb_client_pid_list {
        struct ctdb_client *client;
 };
 
+const char *ctdbd_pidfile = NULL;
+
 static void daemon_incoming_packet(void *, struct ctdb_req_header *);
 
 static void print_exit_message(void)
@@ -1103,6 +1105,38 @@ static void ctdb_tevent_trace(enum tevent_trace_point tp,
        }
 }
 
+static void ctdb_remove_pidfile(void)
+{
+       if (ctdbd_pidfile != NULL && !ctdb_is_child_process()) {
+               if (unlink(ctdbd_pidfile) == 0) {
+                       DEBUG(DEBUG_INFO, ("Removed PID file %s\n",
+                                          ctdbd_pidfile));
+               } else {
+                       DEBUG(DEBUG_WARNING, ("Failed to Remove PID file %s\n",
+                                             ctdbd_pidfile));
+               }
+       }
+}
+
+static void ctdb_create_pidfile(pid_t pid)
+{
+       if (ctdbd_pidfile != NULL) {
+               FILE *fp;
+
+               fp = fopen(ctdbd_pidfile, "w");
+               if (fp == NULL) {
+                       DEBUG(DEBUG_ALERT,
+                             ("Failed to open PID file %s\n", ctdbd_pidfile));
+                       exit(11);
+               }
+
+               fprintf(fp, "%d\n", pid);
+               fclose(fp);
+               DEBUG(DEBUG_INFO, ("Created PID file %s\n", ctdbd_pidfile));
+               atexit(ctdb_remove_pidfile);
+       }
+}
+
 /*
   start the protocol going as a daemon
 */
@@ -1140,7 +1174,7 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool 
do_fork, bool use_syslog,
 
        ctdbd_pid = getpid();
        ctdb->ctdbd_pid = ctdbd_pid;
-
+       ctdb_create_pidfile(ctdb->ctdbd_pid);
        DEBUG(DEBUG_ERR, ("Starting CTDBD as pid : %u\n", ctdbd_pid));
 
        if (ctdb->do_setsched) {
diff --git a/server/ctdbd.c b/server/ctdbd.c
index 512a4b7..b8768f1 100644
--- a/server/ctdbd.c
+++ b/server/ctdbd.c
@@ -130,6 +130,7 @@ int main(int argc, const char *argv[])
                { "dbdir-persistent", 0, POPT_ARG_STRING, 
&options.db_dir_persistent, 0, "directory for persistent tdb files", NULL },
                { "dbdir-state", 0, POPT_ARG_STRING, &options.db_dir_state, 0, 
"directory for internal state tdb files", NULL },
                { "reclock", 0, POPT_ARG_STRING, &options.recovery_lock_file, 
0, "location of recovery lock file", "filename" },
+               { "pidfile", 0, POPT_ARG_STRING, &ctdbd_pidfile, 0, "location 
of PID file", "filename" },
                { "valgrinding", 0, POPT_ARG_NONE, &options.valgrinding, 0, 
"disable setscheduler SCHED_FIFO call, use mmap for tdbs", NULL },
                { "nosetsched", 0, POPT_ARG_NONE, &options.nosetsched, 0, 
"disable setscheduler SCHED_FIFO call, use mmap for tdbs", NULL },
                { "syslog", 0, POPT_ARG_NONE, &options.use_syslog, 0, "log 
messages to syslog", NULL },


-- 
CTDB repository

Reply via email to