blob: fa412e2aa55160fabb5de294b4ade306dd985927 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001#!/bin/sh
2# Start/stop the FreeRADIUS daemon.
3
4### BEGIN INIT INFO
5# Provides: freeradius
6# Required-Start: $remote_fs $network $syslog
7# Should-Start: $time mysql slapd postgresql samba krb5-kdc
8# Required-Stop: $remote_fs $syslog
9# Default-Start: 2 3 4 5
10# Default-Stop: 0 1 6
11# Short-Description: Radius Daemon
12# Description: Extensible, configurable radius daemon
13### END INIT INFO
14
15set -e
16
17# Source function library.
18. /etc/init.d/functions
19
20if [ -f /lib/lsb/init-functions ]; then
21 . /lib/lsb/init-functions
22fi
23
24PROG="radiusd"
25PROGRAM="/usr/sbin/radiusd"
26PIDFILE="/var/run/radiusd/radiusd.pid"
27DESCR="FreeRADIUS daemon"
28
29if [ -r /etc/default/$PROG ]; then
30 . /etc/default/$PROG
31fi
32
33test -f $PROGRAM || exit 0
34
35check_certs() {
36 if [ ! -f /etc/raddb/certs/server.pem ]; then
37 echo -n "Creating certificates for freeradius..."
38 if sudo -u radiusd /etc/raddb/certs/bootstrap 1> /dev/null 2> /dev/null; then
39 echo "done"
40 else
41 echo "failed!"
42 fi
43 fi
44
45}
46
47# /var/run may be a tmpfs
48if [ ! -d /var/run/radiusd ]; then
49 mkdir -p /var/run/radiusd
50 chown radiusd:radiusd /var/run/radiusd
51fi
52
53if [ ! -d /var/log/radius ]; then
54 mkdir -p /var/log/radius
55 touch /var/log/radius/radius.log
56 chown radiusd:radiusd /var/run/radius
57fi
58
59if [ ! -f ${PIDFILE} ]; then
60 touch ${PIDFILE}
61 chown radiusd:radiusd ${PIDFILE}
62fi
63
64export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
65
66ret=0
67
68case "$1" in
69 start)
70 check_certs
71 echo -n "Starting $DESCR" "$PROG"
72 start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $PROGRAM -- $FREERADIUS_OPTIONS || ret=$?
73 [ "$ret" == 0 ] && echo " Success" || echo " Failed"
74 exit $ret
75 ;;
76 stop)
77 echo -n "Stopping $DESCR" "$PROG"
78 if [ -f "$PIDFILE" ] ; then
79 start-stop-daemon --stop --retry=TERM/30/KILL/5 --quiet --pidfile $PIDFILE || ret=$?
80 else
81 echo -n "$PIDFILE not found"
82 ret=1
83 fi
84 [ "$ret" == 0 ] && echo " Success" || echo " Failed"
85 ;;
86 status)
87 status $PROGRAM;
88 exit $?
89 ;;
90 restart)
91 $0 stop
92 $0 start
93 ;;
94 reload|force-reload)
95 echo -n "Reloading $DESCR" "$PROG"
96 if [ -f "$PIDFILE" ] ; then
97 start-stop-daemon --stop --signal HUP --quiet --pidfile $PIDFILE || ret=$?
98 else
99 echo -n "$PIDFILE not found"
100 ret=1
101 fi
102 [ "$ret" == 0 ] && echo " Success" || echo " Failed"
103 ;;
104 *)
105 echo "Usage: $0 start|stop|status|restart|force-reload|reload"
106 exit 1
107 ;;
108esac
109
110exit 0