ejabberd: start the daemon as ejabberd user
PATCH 1/3 ejabberd: start the daemon as ejabberd user
ejabberd.mk creates an ejabberd user but the init script was starting the xmpp server as root user. This patch fixes it by invoking ejabberctl from a "su ejabberd -c" command.
--- package/ejabberd/S50ejabberd | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
package/ejabberd/S50ejabberd +20 -8
@@ -7,29 +7,41 @@ USER=ejabberd RUNDIR=/var/run/ejabberd mkrundir() { - install -d -o $USER -g $USER $RUNDIR + install -d -o "$USER" -g "$USER" "$RUNDIR" +} + +# Run ejabberdctl as user $USER. +ctl() { + su $USER -c "ejabberdctl $*" } case "$1" in start) - mkrundir - echo "Starting ejabberd..." - ejabberdctl start + mkrundir || exit 1 + echo -n "Starting ejabberd... " + ctl start ;; stop) echo -n "Stopping ejabberd... " - ejabberdctl stop > /dev/null - if [ $? -eq 3 ] || ejabberdctl stopped; then + ctl stop > /dev/null + if [ $? -eq 3 ] || ctl stopped; then echo "OK" else echo "failed" fi ;; - restart|reload) + status) + ctl status + ;; + restart|force-reload) "$0" stop "$0" start ;; + live) + mkrundir || exit 1 + ctl live + ;; *) - echo "Usage: $0 {start|stop|restart}" + echo "Usage: $0 {start|stop|status|restart|force-reload|live}" exit 1 esac
Signature · 1 line
2.1.0
PATCH 2/3 ejabberd: allow one to change SPOOLDIR location
By default, ejabberd saves the mnesia database into /var/lib/ejabberd. Otherwise, one might want to change this location (e.g., if /var/lib is read-only). Add an option in the init script to offer this possibility.
--- package/ejabberd/S50ejabberd | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
package/ejabberd/S50ejabberd +7 -2
@@ -3,11 +3,16 @@ # Start/stop ejabberd # +NAME=ejabberd USER=ejabberd RUNDIR=/var/run/ejabberd +SPOOLDIR=/var/lib/ejabberd + +# Read configuration variable file if it is present. +[ -r /etc/default/$NAME ] && . /etc/default/$NAME mkrundir() { - install -d -o "$USER" -g "$USER" "$RUNDIR" + install -d -o "$USER" -g "$USER" "$RUNDIR" "$SPOOLDIR" } # Run ejabberdctl as user $USER.
@@ -19,7 +24,7 @@ case "$1" in start) mkrundir || exit 1 echo -n "Starting ejabberd... " - ctl start + ctl start --spool "$SPOOLDIR" ;; stop) echo -n "Stopping ejabberd... "
Signature · 1 line
2.1.0
PATCH 3/3 ejabberd: wait until ejabberd is up and running
In reply to Johan Oudinetejabberdctl start returns immediately even if ejabberd is not ready yet. Add a call to ejabberdctl started just after to wait until the status says ejabberd is up and running.
--- package/ejabberd/S50ejabberd | 6 ++++++ 1 file changed, 6 insertions(+)
package/ejabberd/S50ejabberd +6 -0
@@ -25,6 +25,12 @@ case "$1" in mkrundir || exit 1 echo -n "Starting ejabberd... " ctl start --spool "$SPOOLDIR" + # Wait until ejabberd is up and running. + if ctl started; then + echo "done" + else + echo "failed" + fi ;; stop) echo -n "Stopping ejabberd... "
Signature · 1 line
2.1.0
PATCH 1/3 ejabberd: start the daemon as ejabberd user
In reply to Johan OudinetDear Johan Oudinet,
Quoted 8 lines · Johan Oudinet
ejabberd.mk creates an ejabberd user but the init script was starting the xmpp server as root user. This patch fixes it by invoking ejabberctl from a "su ejabberd -c" command.
Signed-off-by Johan Oudinet <[email protected]>--- package/ejabberd/S50ejabberd | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
All three patches applied, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com