Monday, September 3, 2012

Easy ejabberd clustering procedure

I was fed up with lack of easy ways to connect multiple ejabberd together. The documentation contains what you need but because of not so friendly command lines, I was never satisfied by the procedure.

So I've added a simple command "attach" to "ejabberdctl" that speed up the procedure, basically it uses already defined vars from the script:


    $EXEC_CMD "$ERL \
      $NAME $ERLANG_NODE \
      -mnesia dir \"\\\"$SPOOLDIR\\\"\" \
        -mnesia extra_db_nodes \"[$MASTER]\" \
      -s mnesia"

}
Apply this patch, and enjoy the "attach" command:
=== modified file 'src/ejabberdctl.template'
--- src/ejabberdctl.template    2012-08-02 14:39:16 +0000
+++ src/ejabberdctl.template    2012-08-31 09:06:56 +0000
@@ -364,13 +364,63 @@
         status=0
     }
     return $status
+}
+
+attach ()
+{
+
+RUNAS=${INSTALLUSER-root}
+
+cat <<END
+- Attaching Procedure - (running as '$RUNAS')
+
+You're about to initialise this local mnesia with another running instance.
+Data will be written to '$SPOOLDIR'
+
+First, determine which node do you want to use as master, and answer the question.
+
+Now, once you're in the erlang shell, type:
+mnesia:info().
+
+Look at the line that starts with: "running db nodes", and observe that your node
+is listed.
+
+Then type the following:
+mnesia:change_table_copy_type(schema, node(), disc_copies).
+
+You'll normally get: "{atomic,ok}"
+
+You can now close the shell using:
+q().
+
+You can start ejabberd now, and observe this new node in the webadmin...
+END
+
+echo -n "Specify which master do you want to use (ex: ejabberd@node02): "
+read MASTER
+
+        if [[ -n $MASTER ]]
+        then
+
+    $EXEC_CMD "$ERL \
+      $NAME $ERLANG_NODE \
+      -mnesia dir \"\\\"$SPOOLDIR\\\"\" \
+        -mnesia extra_db_nodes \"[$MASTER]\" \
+      -s mnesia"
+
+        else
+                echo
+
+        fi
 }

+
 case $ARGS in
     ' start') start;;
     ' debug') debug;;
     ' live') live;;
     ' started') wait_for_status 0 30 2;; # wait 30x2s before timeout
     ' stopped') wait_for_status 3 15 2; stop_epmd;; # wait 15x2s before timeout
+    ' attach') attach;;
     *) ctl $ARGS;;
 esac



No comments:

Sticky