[Server-devel] [PATCH] ejabberd.init: Refuse to init unless domain is configured, create the Online group (OLPCXS)

martin.langhoff at gmail.com martin.langhoff at gmail.com
Fri Apr 24 10:03:04 EDT 2009


From: Martin Langhoff <martin at laptop.org>

With this patch, ejabberd.init

 - won't start until the domain is set correctly
 - will create the Online SRG
---
 ejabberd.init |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/ejabberd.init b/ejabberd.init
index 9aab1b5..dc147d3 100644
--- a/ejabberd.init
+++ b/ejabberd.init
@@ -27,11 +27,63 @@ fi
 
 node=`hostname -s`
 
+check_domain_configured() {
+    if [ ! -e /etc/sysconfig/xs_domain_name ]; then
+	echo "Domain not configured yet" > /dev/stderr
+	exit 1;
+    fi
+
+    domain=`cat /etc/sysconfig/xs_domain_name`
+    if [ "$domain" == "random.xs.laptop.org" ]; then
+	echo "Domain not configured yet" > /dev/stderr
+	exit 1;
+    fi
+}
+
+setup_online_srg() {
+
+    if [ -e /var/lib/ejabberd/online_src_created ]; then
+	return 0
+    fi;
+
+    # give ejabberd a bit of time to startup :-)
+    sleep 5;
+
+    domain=`cat /etc/sysconfig/xs_domain_name`
+
+    # Note: grep -q exits as soon as the match is found, which ejabberdctl
+    # doesn't like. So we send the output to /dev/null instead - more
+    # portable too.
+    #
+    # ejabberdctl should handle SIGPIPE without messing up, but that's
+    # a minor problem anyway.
+    #
+    if ! ejabberdctl srg-list-groups "schoolserver.$domain" | grep '^Online$' > /dev/null ; then
+	# ejabberdctl doesn't like spaces in the description field.
+	# backslashes work - but escaping is better left alone for now :-)
+	ejabberdctl srg-create Online "schoolserver.$domain" \
+	    Online "Created_by_ejabberd_init" Online
+	[ $? -eq 0 ] || return 1
+    fi
+
+    if ! ejabberdctl srg-get-info Online "schoolserver.$domain" | grep '^online_users: true$' > /dev/null ; then
+	ejabberdctl srg-user-add '@online@' "schoolserver.$domain" \
+	    Online "schoolserver.$domain"
+	[ $? -eq 0 ] || return 1
+    fi
+
+    # mark success
+    touch /var/lib/ejabberd/online_src_created
+}
+
 start() {
         echo -n $"Starting ejabberd: "
         if [ "$ULIMIT_MAX_FILES" ]; then
             ulimit -n $ULIMIT_MAX_FILES
         fi
+
+	check_domain_configured
+
         daemon --user=ejabberd --check=ejabberd \
 	    "erl" "-pa @libdir@/ejabberd/ebin \
                    -sname ejabberd \
@@ -45,6 +97,11 @@ start() {
         RETVAL=$?
         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ejabberd
         echo
+
+	# Ignore the return val of setup_online_srg
+	# ==> startup even if the SRG setup had errors.
+	setup_online_srg
+
         return $RETVAL
 }
 
-- 
1.6.0.6



More information about the Server-devel mailing list