]> git.donarmstrong.com Git - unscd.git/commitdiff
* update unscd.init
authordon <don@8f7917da-ec0b-0410-a553-b9b0e350d17e>
Mon, 21 Sep 2009 00:08:58 +0000 (00:08 +0000)
committerdon <don@8f7917da-ec0b-0410-a553-b9b0e350d17e>
Mon, 21 Sep 2009 00:08:58 +0000 (00:08 +0000)
debian/unscd.init [new file with mode: 0755]

diff --git a/debian/unscd.init b/debian/unscd.init
new file mode 100755 (executable)
index 0000000..dd03529
--- /dev/null
@@ -0,0 +1,126 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides:          unscd nscd
+# Required-Start:    $remote_fs
+# Required-Stop:     $remote_fs
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Starts the Micro Name Service Cache Daemon
+### END INIT INFO
+
+#
+# unscd:       Starts the Micro 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="unscd"
+DESC="Micro 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_unscd()
+{
+       # 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_unscd()
+{
+       # 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 unscd --shutdown, that fails also if unscd 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_unscd
+       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_unscd
+       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_unscd
+       $DAEMON --invalidate passwd --invalidate group --invalidate hosts
+       case "$?" in
+       0|1)
+               start_unscd
+               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
+