]> git.donarmstrong.com Git - unscd.git/blob - debian/unscd.init
dd03529c9064f658ff52099b27af50690c7b3e25
[unscd.git] / debian / unscd.init
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          unscd nscd
4 # Required-Start:    $remote_fs
5 # Required-Stop:     $remote_fs
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: Starts the Micro Name Service Cache Daemon
9 ### END INIT INFO
10
11 #
12 # unscd:        Starts the Micro Name Service Cache Daemon
13 #
14 # description:  This is a daemon which handles passwd and group lookups
15 #               for running programs and caches the results for the next
16 #               query.  You should start this daemon only if you use
17 #               slow Services like NIS or NIS+
18
19 # Sanity checks.
20
21 NAME="unscd"
22 DESC="Micro Name Service Cache Daemon"
23 DAEMON="/usr/sbin/nscd"
24 PIDFILE="/var/run/nscd/nscd.pid"
25
26 # Sanity checks.
27 umask 022
28 [ -f /etc/nscd.conf ] || exit 0
29 [ -x "$DAEMON" ] || exit 0
30 [ -d /var/run/nscd ] || mkdir -p /var/run/nscd
31 . /lib/lsb/init-functions
32
33 start_unscd()
34 {
35         # Return
36         #   0 if daemon has been started
37         #   1 if daemon was already running
38         #   2 if daemon could not be started
39         start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" --test > /dev/null || return 1
40         start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" || return 2
41 }
42
43 stop_unscd()
44 {
45         # Return
46         #   0 if daemon has been stopped
47         #   1 if daemon was already stopped
48         #   2 if daemon could not be stopped
49
50         # we try to stop using unscd --shutdown, that fails also if unscd is not present.
51         # in that case, fallback to "good old methods"
52         RETVAL=0
53         if ! $DAEMON --shutdown; then
54                 start-stop-daemon --stop --quiet --pidfile "$PIDFILE" --name "$NAME" --test > /dev/null
55                 RETVAL="$?"
56                 [ "$?" -ne 0  -a  "$?" -ne 1 ] && return 2
57         fi
58
59         # Wait for children to finish too
60         start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec "$DAEMON" > /dev/null
61         [ "$?" -ne 0  -a  "$?" -ne 1 ] && return 2
62         rm -f "$PIDFILE"
63         return "$RETVAL"
64 }
65
66 status()
67 {
68         # Return
69         #   0 if daemon is stopped
70         #   1 if daemon is running
71         start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" --test > /dev/null || return 1
72         return 0
73 }
74
75 case "$1" in
76 start)
77         log_daemon_msg "Starting $DESC" "$NAME"
78         start_unscd
79         case "$?" in
80                 0) log_end_msg 0 ; exit 0 ;;
81                 1) log_warning_msg " (already running)." ; exit 0 ;;
82                 *) log_end_msg 1 ; exit 1 ;;
83         esac
84         ;;
85 stop)
86         log_daemon_msg "Stopping $DESC" "$NAME"
87         stop_unscd
88         case "$?" in
89                 0) log_end_msg 0 ; exit 0 ;;
90                 1) log_warning_msg " (not running)." ; exit 0 ;;
91                 *) log_end_msg 1 ; exit 1 ;;
92         esac
93         ;;
94 restart|force-reload|reload)
95         log_daemon_msg "Restarting $DESC" "$NAME"
96         stop_unscd
97         $DAEMON --invalidate passwd --invalidate group --invalidate hosts
98         case "$?" in
99         0|1)
100                 start_unscd
101                 case "$?" in
102                         0) log_end_msg 0 ; exit 0 ;;
103                         1) log_failure_msg " (failed -- old process is still running)." ; exit 1 ;;
104                         *) log_failure_msg " (failed to start)." ; exit 1 ;;
105                 esac
106                 ;;
107         *)
108                 log_failure_msg " (failed to stop)."
109                 exit 1
110                 ;;
111         esac
112         ;;
113 status)
114         log_daemon_msg "Status of $DESC service: "
115         status
116         case "$?" in
117                 0) log_failure_msg "not running." ; exit 1 ;;
118                 1) log_success_msg "running." ; exit 0 ;;
119         esac
120         ;;
121 *)
122         echo "Usage: /etc/init.d/$NAME {start|stop|reload|force-reload|restart|status}" >&2
123         exit 1
124         ;;
125 esac
126