summaryrefslogtreecommitdiff
blob: bc9e6e1bb3a70bd053e1c46ad1585ca25a466c0f (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
#!/sbin/openrc-run
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

DIRSRV_EXEC="/usr/sbin/ns-slapd"
PID_DIRECTORY="/var/run/dirsrv"
LOCK_DIRECTORY="/var/lock/dirsrv"
DIRSRV_CONF_DIR="/etc/dirsrv"
DS_INSTANCES=${DIRSRV_CONF_DIR}/slapd-*
F389DS_INSTANCES=""

depend() {
	need net logger
	use dns
	provide dirsvr ldap
}

checkconfig() {
	if [ -z "${DS_INSTANCES}" ]; then
		eerror "389 Directory Server has not been configured."
		eend 1
		return 1
	fi
}

start() {
	checkconfig || return 1

	for instance in ${DS_INSTANCES}; do
		instance=$(basename ${instance})
		# skip .removed instances, bug #338133
		if [ "${instance%%.removed}" != "${instance}" ]; then
			continue
		fi
		# Create the required directories in case they got nuked
		mkdir -p ${PID_DIRECTORY}
		mkdir -p ${LOCK_DIRECTORY}/${instance}
		# This will probably break one day, we should be pulling out the suitespotuser from dse.ldif
		chown dirsrv: ${PID_DIRECTORY}
		chown dirsrv: ${LOCK_DIRECTORY}/${instance}
		ebegin "Starting 389 Directory Server: instance ${instance}"
		start-stop-daemon --start --quiet -m \
			--pidfile ${PID_DIRECTORY}/${instance}.startpid \
			--exec ${DIRSRV_EXEC} -- -D ${DIRSRV_CONF_DIR}/${instance} \
			-i ${PID_DIRECTORY}/${instance}.pid \
			-w ${PID_DIRECTORY}/${instance}.startpid
		sts=${?}
		eend ${sts}
		if [ "${sts}" != "0" ]; then
			return 1
		fi
	done
}



stop() {
	checkconfig || return 1

	for instance in ${DS_INSTANCES}; do
		instance=$(basename ${instance})
		if [ "${instance%%.removed}" != "${instance}" ]; then
			continue
		fi
		ebegin "Stopping 389 Directory Server: instance ${instance}"
		start-stop-daemon --stop --quiet \
			--pidfile ${PID_DIRECTORY}/${instance}.pid \
			--exec ${DIRSRV_EXEC}
		eend ${?}
	done
}

status() {
	for instance in ${DS_INSTANCES}; do
		instance=$(basename ${instance})
		if [ "${instance%%.removed}" != "${instance}" ]; then
			continue
		fi
		if [ -e ${PID_DIRECTORY}/${instance}.pid ]; then
			pid=$(cat ${PID_DIRECTORY}/${instance}.pid)
			if [ $(echo "$pid" | grep -c $pid) -ge 1 ]; then
				einfo "389 Directory Server: instance ${instance} (pid $pid) running."
			else
				ewarn "389 Directory Server: instance ${instance} (pid $pid) NOT running."
			fi
		else
			eerror "389 Directory Server: instance ${instance} is NOT running."
		fi
	done
}