summaryrefslogtreecommitdiffstats
path: root/testing/freeradius/freeradius.initd
blob: 86909adef96bef3a1f82720bf23416c2daca384f (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
#!/sbin/runscript

opts="${opts} reload"

depend() {
	need net
	after firewall
	use dns
}

checkconfig() {
	#set the location of log files, including startup.log created by check-radiusd-config
	if ! cd /var/log/radius ; then
		eerror "Failed to change current directory to /var/log/radius"
		return 1
	fi

	if [ ! -d /var/run/radiusd ] && ! mkdir /var/run/radiusd ; then
		eerror "Failed to create /var/run/radiusd"
		return 1
	fi
	
	if [ ! -f /etc/raddb/radiusd.conf ] ; then
		eerror "No /etc/raddb/radiusd.conf file exists!"
		return 1
	fi

	if [ "`/usr/sbin/check-radiusd-config >/dev/null 2>&1; echo $?`" != "0" ] ; then
		eerror "Config not ok! (try /usr/sbin/check-radiusd-config )"
		return 1
	fi

	RADIUSD_USER=`grep '^ *user *=' /etc/raddb/radiusd.conf | cut -d ' ' -f 3`
	RADIUSD_GROUP=`grep '^ *group *=' /etc/raddb/radiusd.conf | cut -d ' ' -f 3`
	if [ -n "${RADIUSD_USER}" ] && ! getent passwd ${RADIUSD_USER} > /dev/null ; then
		eerror "${RADIUSD_USER} user missing!"
		return 1
	fi
	if [ -n "${RADIUSD_GROUP}" ] && ! getent group ${RADIUSD_GROUP} > /dev/null ; then
		eerror "${RADIUSD_GROUP} group missing!"
		return 1
	fi

	#radius.log is created before privileges drop; we need to set proper permissions on it
	[ -f radius.log ] || touch radius.log || return 1

	chown -R "${RADIUSD_USER:-root}:${RADIUSD_GROUP:-root}" . /var/run/radiusd && \
		chmod -R u+rwX,g+rX . /var/run/radiusd || return 1
}

start() {
	checkconfig || return 1

	ebegin "Starting radiusd"
	start-stop-daemon --start --quiet --exec /usr/sbin/radiusd -- ${RADIUSD_OPTS} >/dev/null
	eend $?
}

stop () {
	ebegin "Stopping radiusd"
	start-stop-daemon --stop --quiet --pidfile=/var/run/radiusd/radiusd.pid
	eend $?
}

reload () {
	ebegin "Reloading radiusd"
	kill -HUP `</var/run/radiusd/radiusd.pid`
	eend $?
}