summaryrefslogtreecommitdiff
blob: 35117b4bd4b0aad73052243f2d092b5c8eea815f (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
80
81
82
83
84
85
86
87
88
89
90
91
#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-im/jabberd/files/jabber.init.gentoo,v 1.1 2005/01/31 23:05:41 humpback Exp $

depend() {
	need net
	use mysql postgresql slapd
	provide jabber-server
}

components="router resolver sm c2s s2s"

my_start() {
	ebegin "-> Starting ${i}"
	component=${i}
#	pidfile=/var/jabberd/pid/${component}.pid
#	## remove components pidfile
#	rm -f "${pidfile}" >/dev/null 2>&1
	## start component
	start-stop-daemon --start -c jabber:jabber -b \
		-q -x /usr/bin/${component} >/dev/null 2>&1
#	## check if pidfile exists
#	if [ ! -f "${pidfile}" ]; then
#		false
#	## check if pidfile contains the pid of a running process
#	elif ! ps -p "$(< ${pidfile})" -o pid= >/dev/null 2>&1; then
#		false
#	fi
	eend $?
}

my_stop() {
	ebegin "-> Stopping ${i}"
	component=${i}
	pidfile=/var/jabberd/pid/${component}.pid
	start-stop-daemon --stop -q --pidfile ${pidfile} >/dev/null 2>&1
#	if [ -f "${pidfile}" ] && ps -p "$(< ${pidfile})" -o pid= >/dev/null 2>&1; then
#		false
#	fi
#	## remove components pidfile
#	rm -f "${pidfile}" >/dev/null 2>&1
	eend $?
}

start() {
	ebegin "Starting Jabber Server"
	local started=''
	local failed=''
	for i in ${components}; do
		if ! my_start ${i}; then
			failed="${failed:+${failed} }${i}"
		else
			started="${started:+${started} }${i}"
		fi
	done
	if [ -n "${failed}" ]; then
		eerror
		eerror "The following components failed to start:"
		eerror "-> ${failed}"
		eerror
		eerror "Trying to stop started components"
		for i in ${started}; do
			my_stop ${i}
		done
		false
	fi
	eend $?
}

stop() {
	ebegin "Stopping Jabber Server"
	local failed=''
	for i in ${components}; do
		if ! my_stop ${i}; then
			failed="${failed:+${failed} }${i}"
		fi
	done
	if [ -n "${failed}" ]; then
		eerror
		eerror "The following components failed to stop:"
		eerror "-> ${failed}"
		eerror
		eerror "Please kill the processes manually and reset"
		eerror "this service to a stopped state using"
		eerror "-> ${0} zap"
		eerror
		false
	fi
	eend $?
}