Subversion Repositories configs

Rev

Rev 4 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 - 1
#!/bin/sh
2
#
3
# ypbind:       Starts the ypbind daemon
4
#
5
# Version:      @(#) /etc/init.d/ypbind.init 1.3
6
#
7
# chkconfig: - 24 76
8
# description: This is a daemon which runs on NIS/YP clients and binds them \
9
#              to a NIS domain. It must be running for systems based on glibc \
10
#              to work as NIS clients, but it should not be enabled on systems \
11
#              which are not using NIS.
12
# processname: ypbind
13
# config: /etc/yp.conf
14
#
15
# See https://fedoraproject.org/wiki/Packaging:SysVInitScript for
16
# the guidelines document.
17
 
18
OTHER_YPBIND_OPTS=""
19
 
20
# Source function library.
21
[ -f /etc/rc.d/init.d/functions ] || exit 0
22
. /etc/rc.d/init.d/functions
23
 
24
# getting the YP domain name
25
[ -e /etc/sysconfig/network ] && . /etc/sysconfig/network
26
 
27
# Check for and source configuration file otherwise set defaults
28
[ -f /etc/sysconfig/ypbind ] && . /etc/sysconfig/ypbind
29
 
30
# NISTIMEOUT should be a multiple of 15 since
31
# ypwhich has a hardcoded 15sec timeout
32
[ -z "$NISTIMEOUT" ] && NISTIMEOUT=45
33
 
34
# Check that networking is configured.
35
[ "${NETWORKING}" = "no" ] && exit 0
36
 
37
exec="/usr/sbin/ypbind"
38
prog="ypbind"
39
lockfile=/var/lock/subsys/$prog
40
 
41
selinux_on() {
42
    [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || return
43
    #echo $"Turning on allow_ypbind SELinux boolean"
44
    setsebool allow_ypbind=1
45
}
46
 
47
selinux_off() {
48
    [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || return
49
    allow_ypbind=0
50
    .  /etc/selinux/config
51
    if [ -e /etc/selinux/${SELINUXTYPE}/modules/active/booleans.local ]; then
52
	. /etc/selinux/${SELINUXTYPE}/modules/active/booleans.local
53
    fi
54
    if [ $allow_ypbind == 0 ]; then
55
	#echo $"Turning off allow_ypbind SELinux boolean"
56
	setsebool allow_ypbind=$allow_ypbind
57
    fi
58
}
59
 
60
start() {
61
    [ $UID -eq 0 ] || exit 4
62
    [ -x $exec ] || exit 5
63
    DOMAINNAME=`domainname`
64
    if [ "$DOMAINNAME" = "(none)" -o "$DOMAINNAME" = "" ]; then
65
	echo -n $"Setting NIS domain: "
66
	if [ -n "$NISDOMAIN" ]; then
67
	    action $"domain is '$NISDOMAIN' " domainname $NISDOMAIN
68
	else # See if the domain is set in config file
69
	    NISDOMAIN=`grep "domain" /etc/yp.conf | grep -v ^# | \
70
		awk '{print $2}' | head -1`
71
	    if [ -n "$NISDOMAIN" ]; then
72
		action $"domain is '$NISDOMAIN' " \
73
		    domainname $NISDOMAIN
74
	    else
75
		action $"domain not found" /bin/false
76
		logger -t ypbind $"domain not found"
77
	        return 1
78
	    fi
79
	fi
80
    fi
34 - 81
 
82
    #/etc/rpc check
83
    grep ypbind /etc/rpc > /dev/null 2>&1
84
    if [ $? -ne 0 ]; then
85
	action $"Error: Missing ypbind entry in /etc/rpc." false
86
	exit 1
87
    fi
88
 
4 - 89
    echo -n $"Starting NIS service: "
90
    selinux_on
91
    daemon $exec $OTHER_YPBIND_OPTS
92
    retval=$?
93
    echo
94
    if [ $retval -ne 0 ]; then
95
        #selinux_off
96
	logger -t ypbind "failed to start!"
97
	return $retval
98
    fi
34 - 99
    retval=-1
4 - 100
    echo -n $"Binding NIS service: "
101
    # the following fixes problems with the init scripts continuing
102
    # even when we are really not bound yet to a server, and then things
103
    # that need NIS fail.
104
    firsttime=1
105
    SECONDS=0
34 - 106
    while [ $SECONDS -lt $NISTIMEOUT ] || [ $firsttime -eq 1 ] ; do
107
	firsttime=0
4 - 108
	if /usr/sbin/rpcinfo -p | LC_ALL=C fgrep -q ypbind
109
	then
110
	    /usr/bin/ypwhich > /dev/null 2>&1
111
	    retval=$?
112
	    if [ $retval -eq 0 ]; then
113
		break;
114
	    fi
115
	fi
116
	sleep 2
117
	echo -n "."
118
    done
119
    if [ $retval -eq 0 ]; then
120
	logger -t ypbind \
121
	    "NIS domain: `domainname`, NIS server: `ypwhich 2> /dev/null`"
122
	touch $lockfile
123
	success
34 - 124
    elif [ $retval -eq -1 ]; then
125
	logger -t ypbind \
126
            "NIS service failed to register to rpcbind."
127
        failure
128
        #selinux_off
129
        retval=90
4 - 130
    else
131
	logger -t ypbind \
132
	    "NIS server for domain `domainname` is not responding."
133
	failure
134
	#selinux_off
135
	retval=100
136
    fi
137
    echo
138
    return $retval
139
}
140
 
141
stop() {
142
    [ $UID -eq 0 ] || exit 4
143
    [ -x $exec ] || exit 5
144
    echo -n $"Shutting down NIS service: "
145
    killproc $prog
146
    retval=$?
147
    echo
148
    if [ $retval -eq 0 ]; then
149
	rm -f $lockfile
150
	# if  we used brute force (like kill -9) we don't want those around
151
	if [ x$(domainname) != x ]; then
152
	    rm -f /var/yp/binding/$(domainname)*
153
	fi
154
    fi
155
    #selinux_off
156
    return $retval
157
}
158
 
159
restart() {
160
    stop
161
    start
162
}
163
 
164
reload() {
165
    echo -n $"Reloading NIS service: "
166
    killproc $prog -HUP
167
    retval=$?
168
    echo
169
    return $retval
170
}
171
 
172
force_reload() {
173
    restart
174
}
175
 
176
rh_status() {
177
    # run checks to determine if the service is running or use generic status
178
    status $prog
179
}
180
 
181
rh_status_q() {
182
    rh_status >/dev/null 2>&1
183
}
184
 
185
usage() {
186
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
187
}
188
 
189
# See how we were called.
190
case "$1" in
191
    start)
192
	rh_status_q && exit 0
193
	$1
194
	retval=$?
195
	if [ $retval -eq 100 ]; then stop; exit 1; fi
196
	exit $retval
197
	;;
198
    stop)
199
        rh_status_q || exit 0
200
	$1
201
	;;
202
    restart)
203
	$1
204
	;;
205
    reload)
206
	rh_status_q || exit 7
207
	$1
208
	;;
209
    force-reload)
210
	force_reload
211
	;;
212
    status)
213
	rh_status
214
	;;
215
    condrestart|try-restart)
216
	rh_status_q || exit 0
217
	restart
218
	;;
219
    usage)
220
	$1
221
	;;
222
    *)
223
	usage
224
	exit 2
225
esac
226
exit $?