Improved initscript

This commit is contained in:
Karel Klíč 2010-01-21 21:22:12 +00:00
parent acd718da7e
commit 4ca34e74e6
2 changed files with 163 additions and 132 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/sh
# #
# ypbind: Starts the ypbind Daemon # ypbind: Starts the ypbind daemon
# #
# Version: @(#) /etc/init.d/ypbind.init 1.3 # Version: @(#) /etc/init.d/ypbind.init 1.3
# #
@ -11,13 +11,18 @@
# which are not using NIS. # which are not using NIS.
# processname: ypbind # processname: ypbind
# config: /etc/yp.conf # config: /etc/yp.conf
#
# See https://fedoraproject.org/wiki/Packaging:SysVInitScript for
# the guidelines document.
OTHER_YPBIND_OPTS="" OTHER_YPBIND_OPTS=""
# Source function library. # Source function library.
. /etc/init.d/functions [ -f /etc/rc.d/init.d/functions ] || exit 0
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network # getting the YP domain name
[ -e /etc/sysconfig/network ] && . /etc/sysconfig/network
# Check for and source configuration file otherwise set defaults # Check for and source configuration file otherwise set defaults
[ -f /etc/sysconfig/ypbind ] && . /etc/sysconfig/ypbind [ -f /etc/sysconfig/ypbind ] && . /etc/sysconfig/ypbind
@ -29,6 +34,10 @@ OTHER_YPBIND_OPTS=""
# Check that networking is configured. # Check that networking is configured.
[ "${NETWORKING}" = "no" ] && exit 0 [ "${NETWORKING}" = "no" ] && exit 0
exec="/sbin/ypbind"
prog="ypbind"
lockfile=/var/lock/subsys/$prog
selinux_on() { selinux_on() {
[ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || return [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled || return
#echo $"Turning on allow_ypbind SELinux boolean" #echo $"Turning on allow_ypbind SELinux boolean"
@ -49,6 +58,8 @@ selinux_off() {
} }
start() { start() {
[ $UID -eq 0 ] || exit 4
[ -x $exec ] || exit 5
DOMAINNAME=`domainname` DOMAINNAME=`domainname`
if [ "$DOMAINNAME" = "(none)" -o "$DOMAINNAME" = "" ]; then if [ "$DOMAINNAME" = "(none)" -o "$DOMAINNAME" = "" ]; then
echo -n $"Setting NIS domain: " echo -n $"Setting NIS domain: "
@ -69,13 +80,13 @@ start() {
fi fi
echo -n $"Starting NIS service: " echo -n $"Starting NIS service: "
selinux_on selinux_on
daemon ypbind $OTHER_YPBIND_OPTS daemon $exec $OTHER_YPBIND_OPTS
RETVAL=$? retval=$?
echo echo
if [ $RETVAL -ne 0 ]; then if [ $retval -ne 0 ]; then
#selinux_off #selinux_off
logger -t ypbind "failed to start!" logger -t ypbind "failed to start!"
return $RETVAL return $retval
fi fi
echo -n $"Binding NIS service: " echo -n $"Binding NIS service: "
# the following fixes problems with the init scripts continuing # the following fixes problems with the init scripts continuing
@ -93,44 +104,46 @@ start() {
firsttime=0 firsttime=0
fi fi
/usr/bin/ypwhich > /dev/null 2>&1 /usr/bin/ypwhich > /dev/null 2>&1
RETVAL=$? retval=$?
if [ $RETVAL -eq 0 ]; then if [ $retval -eq 0 ]; then
break; break;
fi fi
fi fi
sleep 2 sleep 2
echo -n "." echo -n "."
done done
if [ $RETVAL -eq 0 ]; then if [ $retval -eq 0 ]; then
logger -t ypbind \ logger -t ypbind \
"NIS domain: `domainname`, NIS server: `ypwhich 2> /dev/null`" "NIS domain: `domainname`, NIS server: `ypwhich 2> /dev/null`"
touch /var/lock/subsys/ypbind touch $lockfile
success success
else else
logger -t ypbind \ logger -t ypbind \
"NIS server for domain `domainname` is not responding." "NIS server for domain `domainname` is not responding."
failure failure
#selinux_off #selinux_off
RETVAL=100 retval=100
fi fi
echo echo
return $RETVAL return $retval
} }
stop() { stop() {
[ $UID -eq 0 ] || exit 4
[ -x $exec ] || exit 5
echo -n $"Shutting down NIS service: " echo -n $"Shutting down NIS service: "
killproc ypbind killproc $prog
RETVAL=$? retval=$?
if [ $RETVAL -eq 0 ]; then echo
rm -f /var/lock/subsys/ypbind if [ $retval -eq 0 ]; then
rm -f $lockfile
# if we used brute force (like kill -9) we don't want those around # if we used brute force (like kill -9) we don't want those around
if [ x$(domainname) != x ]; then if [ x$(domainname) != x ]; then
rm -f /var/yp/binding/$(domainname)* rm -f /var/yp/binding/$(domainname)*
fi fi
fi fi
echo
#selinux_off #selinux_off
return $RETVAL return $retval
} }
restart() { restart() {
@ -140,50 +153,64 @@ restart() {
reload() { reload() {
echo -n $"Reloading NIS service: " echo -n $"Reloading NIS service: "
p=`/sbin/pidof -o %PPID 'ypbind'` killproc $prog -HUP
RETVAL=$? retval=$?
if [ "$RETVAL" -eq 0 ]; then
/bin/kill -HUP $p
RETVAL=$?
fi
[ "$RETVAL" -eq 0 ] && success || failure
echo echo
return $RETVAL return $retval
} }
RETVAL=0 force_reload() {
restart
}
rh_status() {
# run checks to determine if the service is running or use generic status
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
usage() {
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
}
# See how we were called. # See how we were called.
case "$1" in case "$1" in
start) start)
start rh_status_q && exit 0
RETVAL=$? $1
if [ $RETVAL -eq 100 ]; then stop; RETVAL=1; fi retval=$?
if [ $retval -eq 100 ]; then stop; exit 1; fi
exit $retval
;; ;;
stop) stop)
stop rh_status_q || exit 0
RETVAL=$? $1
;;
status)
status ypbind
RETVAL=$?
;; ;;
restart) restart)
restart $1
RETVAL=$?
;;
condrestart|try-restart)
if [ -e /var/lock/subsys/ypbind ]; then restart; fi
;; ;;
reload) reload)
reload rh_status_q || exit 7
$1
;; ;;
force-reload) force-reload)
if ! reload; then restart; fi force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
usage)
$1
;; ;;
*) *)
echo $"Usage: $0 {start|stop|restart|condrestart|try-restart|reload|force-reload|status}" usage
RETVAL=3 exit 2
esac esac
exit $?
exit $RETVAL

View File

@ -1,7 +1,7 @@
Summary: The NIS daemon which binds NIS clients to an NIS domain Summary: The NIS daemon which binds NIS clients to an NIS domain
Name: ypbind Name: ypbind
Version: 1.31 Version: 1.31
Release: 1%{?dist} Release: 2%{?dist}
License: GPLv2 License: GPLv2
Group: System Environment/Daemons Group: System Environment/Daemons
Source0: ftp://ftp.us.kernel.org/pub/linux/utils/net/NIS/ypbind-mt-%{version}.tar.bz2 Source0: ftp://ftp.us.kernel.org/pub/linux/utils/net/NIS/ypbind-mt-%{version}.tar.bz2
@ -85,6 +85,10 @@ fi
%doc README NEWS %doc README NEWS
%changelog %changelog
* Thu Jan 21 2010 Karel Klic <kklic@redhat.com> - 3:1.31-2
- Rewrote initscript to become closer to Packaging:SysVInitScript
Fedora guildeline. Also fixes rhbz#523913
* Mon Jan 4 2010 Karel Klic <kklic@redhat.com> - 3:1.31-1 * Mon Jan 4 2010 Karel Klic <kklic@redhat.com> - 3:1.31-1
- Updated to version 1.31 from upstream - Updated to version 1.31 from upstream
- Removed signalstate patch because it was merged by upstream - Removed signalstate patch because it was merged by upstream