~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/nscd

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
### BEGIN INIT INFO
3
 
# Provides:          nscd
4
 
# Required-Start:    $remote_fs $syslog
5
 
# Required-Stop:     $remote_fs $syslog
6
 
# Default-Start:     2 3 4 5
7
 
# Default-Stop:      0 1 6
8
 
# Short-Description: Starts the Name Service Cache Daemon
9
 
### END INIT INFO
10
 
 
11
 
#
12
 
# nscd:         Starts the 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
 
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
20
 
NAME="nscd"
21
 
DESC="Name Service Cache Daemon"
22
 
DAEMON="/usr/sbin/nscd"
23
 
PIDFILE="/var/run/nscd/nscd.pid"
24
 
 
25
 
# Sanity checks.
26
 
umask 022
27
 
[ -f /etc/nscd.conf ] || exit 0
28
 
[ -x "$DAEMON" ] || exit 0
29
 
[ -d /var/run/nscd ] || mkdir -p /var/run/nscd
30
 
. /lib/lsb/init-functions
31
 
 
32
 
start_nscd()
33
 
{
34
 
        # Return
35
 
        #   0 if daemon has been started or was already running
36
 
        #   2 if daemon could not be started
37
 
        start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" --test > /dev/null || return 0
38
 
        start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" || return 2
39
 
}
40
 
 
41
 
stop_nscd()
42
 
{
43
 
        # Return
44
 
        #   0 if daemon has been stopped
45
 
        #   1 if daemon was already stopped
46
 
        #   2 if daemon could not be stopped
47
 
 
48
 
        # we try to stop using nscd --shutdown, that fails also if nscd is not present.
49
 
        # in that case, fallback to "good old methods"
50
 
        RETVAL=0
51
 
        if ! $DAEMON --shutdown; then
52
 
                start-stop-daemon --stop --quiet --pidfile "$PIDFILE" --name "$NAME" --test > /dev/null
53
 
                RETVAL="$?"
54
 
                [ "$?" -ne 0  -a  "$?" -ne 1 ] && return 2
55
 
        fi
56
 
 
57
 
        # Wait for children to finish too
58
 
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec "$DAEMON" > /dev/null
59
 
        [ "$?" -ne 0  -a  "$?" -ne 1 ] && return 2
60
 
        rm -f "$PIDFILE"
61
 
        return "$RETVAL"
62
 
}
63
 
 
64
 
status()
65
 
{
66
 
        # Return
67
 
        #   0 if daemon is stopped
68
 
        #   1 if daemon is running
69
 
        start-stop-daemon --start --quiet --pidfile "$PIDFILE" --exec "$DAEMON" --test > /dev/null || return 1
70
 
        return 0
71
 
}
72
 
 
73
 
invalidate_cache()
74
 
{
75
 
        for table in passwd group hosts ; do
76
 
                $DAEMON --invalidate $table
77
 
        done
78
 
}
79
 
 
80
 
case "$1" in
81
 
start)
82
 
        log_daemon_msg "Starting $DESC" "$NAME"
83
 
        start_nscd
84
 
        case "$?" in
85
 
                0) invalidate_cache ; 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_nscd
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)
100
 
        log_daemon_msg "Restarting $DESC" "$NAME"
101
 
        invalidate_cache
102
 
        stop_nscd
103
 
        case "$?" in
104
 
        0|1)
105
 
                start_nscd
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 3 ;;
123
 
                1) log_success_msg "running." ; exit 0 ;;
124
 
        esac
125
 
        ;;
126
 
*)
127
 
        echo "Usage: /etc/init.d/$NAME {start|stop|force-reload|restart|status}" >&2
128
 
        exit 1
129
 
        ;;
130
 
esac
131