Subversion Repositories configs

Rev

Go to most recent revision | Details | 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
81
    echo -n $"Starting NIS service: "
82
    selinux_on
83
    daemon $exec $OTHER_YPBIND_OPTS
84
    retval=$?
85
    echo
86
    if [ $retval -ne 0 ]; then
87
        #selinux_off
88
	logger -t ypbind "failed to start!"
89
	return $retval
90
    fi
91
    echo -n $"Binding NIS service: "
92
    # the following fixes problems with the init scripts continuing
93
    # even when we are really not bound yet to a server, and then things
94
    # that need NIS fail.
95
    timeout=10
96
    firsttime=1
97
    SECONDS=0
98
    while [ $SECONDS -lt $timeout ]; do
99
	if /usr/sbin/rpcinfo -p | LC_ALL=C fgrep -q ypbind
100
	then
101
	    if [ $firsttime -eq 1 ]; then
102
		# reset timeout
103
		timeout=$NISTIMEOUT
104
		firsttime=0
105
	    fi
106
	    /usr/bin/ypwhich > /dev/null 2>&1
107
	    retval=$?
108
	    if [ $retval -eq 0 ]; then
109
		break;
110
	    fi
111
	fi
112
	sleep 2
113
	echo -n "."
114
    done
115
    if [ $retval -eq 0 ]; then
116
	logger -t ypbind \
117
	    "NIS domain: `domainname`, NIS server: `ypwhich 2> /dev/null`"
118
	touch $lockfile
119
	success
120
    else
121
	logger -t ypbind \
122
	    "NIS server for domain `domainname` is not responding."
123
	failure
124
	#selinux_off
125
	retval=100
126
    fi
127
    echo
128
    return $retval
129
}
130
 
131
stop() {
132
    [ $UID -eq 0 ] || exit 4
133
    [ -x $exec ] || exit 5
134
    echo -n $"Shutting down NIS service: "
135
    killproc $prog
136
    retval=$?
137
    echo
138
    if [ $retval -eq 0 ]; then
139
	rm -f $lockfile
140
	# if  we used brute force (like kill -9) we don't want those around
141
	if [ x$(domainname) != x ]; then
142
	    rm -f /var/yp/binding/$(domainname)*
143
	fi
144
    fi
145
    #selinux_off
146
    return $retval
147
}
148
 
149
restart() {
150
    stop
151
    start
152
}
153
 
154
reload() {
155
    echo -n $"Reloading NIS service: "
156
    killproc $prog -HUP
157
    retval=$?
158
    echo
159
    return $retval
160
}
161
 
162
force_reload() {
163
    restart
164
}
165
 
166
rh_status() {
167
    # run checks to determine if the service is running or use generic status
168
    status $prog
169
}
170
 
171
rh_status_q() {
172
    rh_status >/dev/null 2>&1
173
}
174
 
175
usage() {
176
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
177
}
178
 
179
# See how we were called.
180
case "$1" in
181
    start)
182
	rh_status_q && exit 0
183
	$1
184
	retval=$?
185
	if [ $retval -eq 100 ]; then stop; exit 1; fi
186
	exit $retval
187
	;;
188
    stop)
189
        rh_status_q || exit 0
190
	$1
191
	;;
192
    restart)
193
	$1
194
	;;
195
    reload)
196
	rh_status_q || exit 7
197
	$1
198
	;;
199
    force-reload)
200
	force_reload
201
	;;
202
    status)
203
	rh_status
204
	;;
205
    condrestart|try-restart)
206
	rh_status_q || exit 0
207
	restart
208
	;;
209
    usage)
210
	$1
211
	;;
212
    *)
213
	usage
214
	exit 2
215
esac
216
exit $?