summaryrefslogtreecommitdiff
blob: cbbca9e2983087e2ffc68b3839741f2387c4debe (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
#!/sbin/runscript
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-misc/dhcp/files/dhcp.init,v 1.6 2006/02/23 16:21:24 uberlord Exp $

depend() {
	need net
	use logger dns
}

get_var() {
	sed -n 's/^[[:blank:]]\?'"$1"' "*\([^#";]\+\).*/\1/p' \
		"${CHROOT}/etc/dhcp/dhcpd.conf"
}

start() {
	if [[ ! -f "${CHROOT}/etc/dhcp/dhcpd.conf" ]] ; then
		eerror "${CHROOT}/etc/dhcp/dhcpd.conf does not exist"
		return 1
	fi

	local leasefile="$(get_var lease-file-name)"
	leasefile="${CHROOT}/${leasefile:-/var/lib/dhcp/dhcpd.leases}"
	if [[ ! -f ${leasefile} ]] ; then
		ebegin "Creating ${leasefile}"
		touch "${leasefile}"
		chown dhcp:dhcp "${leasefile}"
		eend $? || return 1
	fi

	# Ensure that LD_PRELOAD is really exported
	[[ -n ${LD_PRELOAD} ]] && export LD_PRELOAD="${LD_PRELOAD}"

	local pidfile="$(get_var pid-file-name)"
	pidfile="${pidfile:-/var/run/dhcp/dhcpd.pid}"

	ebegin "Starting ${CHROOT:+chrooted }dhcpd"
	start-stop-daemon --start --exec /usr/sbin/dhcpd \
		--pidfile "${CHROOT}/${pidfile}" \
		-- -q -pf "${pidfile}" \
		-user dhcp -group dhcp ${DHCPD_OPTS} \
		${CHROOT:+-chroot} ${CHROOT} ${IFACE}
	eend $? && save_options pidfile "${CHROOT}/${pidfile}"
}

stop() {
	local pidfile="$(get_options pidfile)" chrooted=""
	[[ ${pidfile} != //var/run/dhcp/dhcpd.pid ]] && chrooted="chrooted "
	ebegin "Stopping ${chrooted}dhcpd"
	start-stop-daemon --stop --exec /usr/sbin/dhcpd \
	    --pidfile "${pidfile}"
	eend $?
}