summaryrefslogtreecommitdiffstats
path: root/redhat/freeradius-radiusd-init
blob: d19b2d449d3439581bdf4f148b27537c880141bc (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/sh
#
# radiusd Start/Stop the FreeRADIUS daemon
#
# chkconfig: - 88 10
# description: Extensible, configurable, high performance RADIUS server.

### BEGIN INIT INFO
# Provides: radiusd
# Required-Start: $network
# Required-Stop:
# Default-Start:
# Default-Stop:
# Should-Start: $time $syslog mysql ldap postgresql samba krb5-kdc
# Should-Stop:
# Short-Description: FreeRADIUS server
# Description: Extensible, configurable, high performance RADIUS server.
### END INIT INFO

# Source function library.

# Get the wrappers for the standard lsb init functions
. /lib/lsb/init-functions

# and the distro specific ones
. /etc/init.d/functions

prog=radiusd

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

exec=${exec:=/usr/sbin/$prog}
config_dir=${config_dir:=/etc/raddb}
config=${config:=$config_dir/radiusd.conf}
pidfile=${pidfile:=/var/run/$prog/$prog.pid}
lockfile=${lockfile:=/var/lock/subsys/radiusd}

configtest() {
    echo -n $"Checking $prog configuration: "
    out=`$exec -Cxl stdout -d $config_dir`; retval=$?
    out=`echo "${out}" | tail -n 1 | sed 's/^\s*ERROR:\s*\(.*\)\s*$/\1/'`

    # Seems some LSB function implementations *really* need
    # a log message < 60 chars long, else output gets mangled.
    if [ $retval -eq 0 ]; then
        log_success_msg
    else
        if [ $(expr length "$out") -gt 60 ]; then
            log_failure_msg
            echo "$out" 1>&2
        else
            log_failure_msg "$out"
        fi
    fi
    return $retval
}

start() {
    echo -n $"Starting $prog: "

    if [ ! -x $exec ]; then
        log_failure_msg "$exec not found or not executable"
        exit 5
    fi

    if [ ! -f $config ]; then
        log_failure_msg "Can't find radiusd.conf"
        exit 6
    fi

    start_daemon -p $pidfile $exec -d $config_dir
    retval=$?
    if [ $retval -eq 0 ]; then
        log_success_msg
    else
        log_failure_msg
    fi
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc -p $pidfile $prog
    retval=$?
    if [ $retval -eq 0 ]; then
        log_success_msg
        rm -f $lockfile
    else
        log_failure_msg
    fi
    return $retval
}

restart() {
    stop
    start
}

reload() {
    # radiusd may not be capable of a 100% configuration reload depending
    # on which loadable modules are in use, if sending the server a
    # HUP is not sufficient then use restart here instead. However, we
    # prefer by default to use HUP since it's what is usually desired.
    #
    # restart

    kill -HUP `pidofproc -p $pidfile $prog`
}

force_reload() {
    restart
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status -p $pidfile $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        configtest || exit 150
        $1
        ;;

    stop)
        rh_status_q || exit 0
        $1
        ;;

    restart)
        configtest || exit 150
        $1
        ;;

    reload)
        rh_status_q || exit 7
        configtest || exit 150
        $1
        ;;

    force-reload)
        configtest || exit 150
        force_reload
        ;;

    condrestart|try-restart)
        configtest || exit 150
        rh_status_q || exit 0
        restart
        ;;

    configtest|testconfig)
        configtest || exit 150
        ;;

    debug)
        echo -n $"Debugging $prog: "
        if rh_status_q; then
            log_failure_msg "$prog already running; for live debugging see raddebug(8)"
            exit 151
        else
            log_success_msg
        fi
        $exec -X -d $config_dir || exit $?
        ;;

    debug-threaded)
        echo -n $"Debugging $prog: "
        if rh_status_q; then
            log_failure_msg "$prog already running; for live debugging see raddebug(8)"
            exit 151
        else
            log_success_msg
        fi
        $exec -f -xx -l stdout -d $config_dir || exit $?
        ;;

    status)
        rh_status
        ;;

    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest|debug|debug-threaded}"
        exit 2
esac
exit $?