ifdef out the whole function...
[freeradius.git] / redhat / freeradius-radiusd-init
1 #!/bin/sh
2 #
3 # radiusd Start/Stop the FreeRADIUS daemon
4 #
5 # chkconfig: - 88 10
6 # description: Extensible, configurable, high performance RADIUS server.
7
8 ### BEGIN INIT INFO
9 # Provides: radiusd
10 # Required-Start: $network
11 # Required-Stop:
12 # Default-Start:
13 # Default-Stop:
14 # Should-Start: $time $syslog mysql ldap postgresql samba krb5-kdc
15 # Should-Stop:
16 # Short-Description: FreeRADIUS server
17 # Description: Extensible, configurable, high performance RADIUS server.
18 ### END INIT INFO
19
20 # Source function library.
21
22 # Get the wrappers for the standard lsb init functions
23 . /lib/lsb/init-functions
24
25 # and the distro specific ones
26 . /etc/init.d/functions
27
28 prog=radiusd
29
30 [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
31
32 exec=${exec:=/usr/sbin/$prog}
33 config_dir=${config_dir:=/etc/raddb}
34 config=${config:=$config_dir/radiusd.conf}
35 pidfile=${pidfile:=/var/run/$prog/$prog.pid}
36 lockfile=${lockfile:=/var/lock/subsys/radiusd}
37
38 configtest() {
39     echo -n $"Checking $prog configuration: "
40     out=`$exec -Cxl stdout -d $config_dir`; retval=$?
41     out=`echo "${out}" | tail -n 1 | sed 's/^\s*ERROR:\s*\(.*\)\s*$/\1/'`
42
43     # Seems some LSB function implementations *really* need
44     # a log message < 60 chars long, else output gets mangled.
45     if [ $retval -eq 0 ]; then
46         log_success_msg
47     else
48         if [ $(expr length "$out") -gt 60 ]; then
49             log_failure_msg
50             echo "$out" 1>&2
51         else
52             log_failure_msg "$out"
53         fi
54     fi
55     return $retval
56 }
57
58 start() {
59     echo -n $"Starting $prog: "
60
61     if [ ! -x $exec ]; then
62         log_failure_msg "$exec not found or not executable"
63         exit 5
64     fi
65
66     if [ ! -f $config ]; then
67         log_failure_msg "Can't find radiusd.conf"
68         exit 6
69     fi
70
71     start_daemon -p $pidfile $exec -d $config_dir
72     retval=$?
73     if [ $retval -eq 0 ]; then
74         log_success_msg
75     else
76         log_failure_msg
77     fi
78     return $retval
79 }
80
81 stop() {
82     echo -n $"Stopping $prog: "
83     killproc -p $pidfile $prog
84     retval=$?
85     if [ $retval -eq 0 ]; then
86         log_success_msg
87         rm -f $lockfile
88     else
89         log_failure_msg
90     fi
91     return $retval
92 }
93
94 restart() {
95     stop
96     start
97 }
98
99 reload() {
100     # radiusd may not be capable of a 100% configuration reload depending
101     # on which loadable modules are in use, if sending the server a
102     # HUP is not sufficient then use restart here instead. However, we
103     # prefer by default to use HUP since it's what is usually desired.
104     #
105     # restart
106
107     kill -HUP `pidofproc -p $pidfile $prog`
108 }
109
110 force_reload() {
111     restart
112 }
113
114 rh_status() {
115     # run checks to determine if the service is running or use generic status
116     status -p $pidfile $prog
117 }
118
119 rh_status_q() {
120     rh_status >/dev/null 2>&1
121 }
122
123 case "$1" in
124     start)
125         rh_status_q && exit 0
126         configtest || exit 150
127         $1
128         ;;
129
130     stop)
131         rh_status_q || exit 0
132         $1
133         ;;
134
135     restart)
136         configtest || exit 150
137         $1
138         ;;
139
140     reload)
141         rh_status_q || exit 7
142         configtest || exit 150
143         $1
144         ;;
145
146     force-reload)
147         configtest || exit 150
148         force_reload
149         ;;
150
151     condrestart|try-restart)
152         configtest || exit 150
153         rh_status_q || exit 0
154         restart
155         ;;
156
157     configtest|testconfig)
158         configtest || exit 150
159         ;;
160
161     debug)
162         echo -n $"Debugging $prog: "
163         if rh_status_q; then
164             log_failure_msg "$prog already running; for live debugging see raddebug(8)"
165             exit 151
166         else
167             log_success_msg
168         fi
169         $exec -X -d $config_dir || exit $?
170         ;;
171
172     debug-threaded)
173         echo -n $"Debugging $prog: "
174         if rh_status_q; then
175             log_failure_msg "$prog already running; for live debugging see raddebug(8)"
176             exit 151
177         else
178             log_success_msg
179         fi
180         $exec -f -xx -l stdout -d $config_dir || exit $?
181         ;;
182
183     status)
184         rh_status
185         ;;
186
187     *)
188         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest|debug|debug-threaded}"
189         exit 2
190 esac
191 exit $?