summaryrefslogtreecommitdiff
path: root/chat/ejabberd/files/ejabberd.sh
blob: 21b4d045aec6796a9361b26ece378063ae5fc858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!@RCD_SCRIPTS_SHELL@
#
# $NetBSD: ejabberd.sh,v 1.2 2011/10/07 22:37:03 shattered Exp $
# $FreeBSD: ejabberd.sh.in,v 1.1 2005/08/28 15:51:48 vsevolod Exp $
#
# PROVIDE: ejabberd
# REQUIRE: DAEMON
# BEFORE: LOGIN
# KEYWORD: shutdown

if [ -f /etc/rc.subr ]
then
        . /etc/rc.subr
fi

name="ejabberd"
rcvar=${name}

command=ejabberdctl
ejabberd_user="@JABBERD_USER@"
reload_cmd="ejabberd_reload"
restart_cmd="ejabberd_reload"
start_cmd="ejabberd_start"
status_cmd="ejabberd_status"
stop_cmd="ejabberd_stop"

PATH=/sbin:/bin:/usr/sbin:/usr/bin:@PREFIX@/bin:@PREFIX@/sbin
EJABBERDCTL=@PREFIX@/sbin/ejabberdctl

ejabberd_status()
{
    su -m $ejabberd_user -c "$EJABBERDCTL status >/dev/null"
}

ejabberd_start()
{
    echo -n "Starting $name: "
    if ejabberd_status; then
	echo " already running."
	exit 1
    else
	su -m $ejabberd_user -c "$EJABBERDCTL start"
    fi
    echo "$name."
}

ejabberd_stop()
{
    echo -n "Stopping $name: "
    if su -m $ejabberd_user -c "$EJABBERDCTL stop"; then
	cnt=0
        while ejabberd_status; do
            cnt=`expr $cnt + 1`
            if [ $cnt -gt 60 ]; then
                echo -n " failed "
                break
            fi
            sleep 1
            echo -n "."
        done
    else
        echo -n " failed "
    fi
    echo "$name."
}

ejabberd_reload()
{
    echo -n "Restarting $name: "
    if ejabberd_status; then
        su -m $ejabberd_user -c "$EJABBERDCTL restart"
    else
        ejabberd_start
    fi
    echo "$name."
}

load_rc_config $name
run_rc_command "$1"