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