[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#457661: nscd: Please use lsb output functions in init.d/nscd



On Mon, Dec 24, 2007 at 11:43:36AM +0100, Petter Reinholdtsen wrote:
> Package: nscd
> Version: 2.7-5
> 
> When using nscd with the progress bar and console in usplash, no
> message show up when nscd is started.
> 
> The reason is that the init.d script do not use the output functions
> in /lib/lsb/init-functions, but uses echo directly.  usplash override
> the functions in /lib/lsb/init-functions to feed the text into the
> graphical boot screen, and thus depend on the use of the lsb output
> functions.
> 
> Please change the init.d script to use the lsb output functions.

Please try the attached file and see if that does what you want.
#!/bin/sh
### BEGIN INIT INFO
# Provides:          nscd
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts the Name Service Cache Daemon
### END INIT INFO

#
# nscd:		Starts the Name Service Cache Daemon
#
# description:  This is a daemon which handles passwd and group lookups
#		for running programs and caches the results for the next
#		query.  You should start this daemon only if you use
#		slow Services like NIS or NIS+

# Sanity checks.

NAME="nscd"
DESC="Name Service Cache Daemon"
DAEMON="/usr/sbin/nscd"
PIDFILE="/var/run/nscd/nscd.pid"

# Sanity checks.
umask 022
[ -f /etc/nscd.conf ] || exit 0
[ -x "$DAEMON" ] || exit 0
[ -d /var/run/nscd ] || mkdir -p /var/run/nscd
. /lib/lsb/init-functions

start_nscd()
{
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started
	start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" --test > /dev/null || return 1
	start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" || return 2
}

stop_nscd()
{
	# Return
	#   0 if daemon has been stopped
	#   1 if daemon was already stopped
	#   2 if daemon could not be stopped

	# we try to stop using nscd --shutdown, that fails also if nscd is not present.
	# in that case, fallback to "good old methods"
	RETVAL=0
	if ! $DAEMON --shutdown; then
		start-stop-daemon --stop --quiet --pidfile "$PIDFILE" --name "$NAME" --test > /dev/null
		RETVAL="$?"
		[ "$?" -ne 0  -a  "$?" -ne 1 ] && return 2
	fi

	# Wait for children to finish too
	start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec "$DAEMON" > /dev/null
	[ "$?" -ne 0  -a  "$?" -ne 1 ] && return 2
	rm -f "$PIDFILE"
	return "$RETVAL"
}

status()
{
	# Return
	#   0 if daemon is stopped
	#   1 if daemon is running
	start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" --test > /dev/null || return 1
	return 0
}

case "$1" in
start)
	log_daemon_msg "Starting $DESC" "$NAME"
	start_nscd
	case "$?" in
		0) log_end_msg 0 ; exit 0 ;;
		1) log_warning_msg " (already running)." ; exit 0 ;;
		*) log_end_msg 1 ; exit 1 ;;
	esac
	;;
stop)
	log_daemon_msg "Stopping $DESC" "$NAME"
	stop_nscd
	case "$?" in
		0) log_end_msg 0 ; exit 0 ;;
		1) log_warning_msg " (not running)." ; exit 0 ;;
		*) log_end_msg 1 ; exit 1 ;;
	esac
	;;
restart|force-reload|reload)
	log_daemon_msg "Restarting $DESC" "$NAME"
	stop_nscd
	$DAEMON --invalidate passwd --invalidate group --invalidate hosts
	case "$?" in
	0|1)
		start_nscd
		case "$?" in
			0) log_end_msg 0 ; exit 0 ;;
			1) log_failure_msg " (failed -- old process is still running)." ; exit 1 ;;
			*) log_failure_msg " (failed to start)." ; exit 1 ;;
		esac
		;;
	*)
		log_failure_msg " (failed to stop)."
		exit 1
		;;
	esac
	;;
status)
	log_daemon_msg "Status of $DESC service: "
	status
	case "$?" in
		0) log_failure_msg "not running." ; exit 1 ;;
		1) log_success_msg "running." ; exit 0 ;;
	esac
	;;
*)
	echo "Usage: /etc/init.d/$NAME {start|stop|reload|force-reload|restart|status}" >&2
	exit 1
	;;
esac


Reply to: