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