~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

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

  • 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:          nfcapd
4
 
# Required-Start:    $remote_fs $network
5
 
# Required-Stop:     $remote_fs
6
 
# Default-Start:     2 3 4 5
7
 
# Default-Stop:      0 1 6
8
 
# Short-Description: netflow capture daemon
9
 
# Description:       nfcapd is the netflow capture daemon of the nfdump tools.
10
 
### END INIT INFO
11
 
 
12
 
# Author: Erik Wenzel <erik@debian.org>
13
 
 
14
 
# Do NOT "set -e"
15
 
 
16
 
# PATH should only include /usr/* if it runs after the mountnfs.sh script
17
 
PATH=/sbin:/usr/sbin:/bin:/usr/bin
18
 
DESC="netflow capture daemon"
19
 
NAME=nfcapd
20
 
DAEMON=/usr/bin/$NAME
21
 
DATA_BASE_DIR="/var/cache/nfdump"
22
 
PIDFILE=/var/run/$NAME.pid
23
 
DAEMON_ARGS="-D -l $DATA_BASE_DIR -P $PIDFILE"
24
 
SCRIPTNAME=/etc/init.d/nfdump
25
 
 
26
 
# Exit if the package is not installed
27
 
[ -x "$DAEMON" ] || exit 0
28
 
 
29
 
# Read configuration variable file if it is present
30
 
[ -r /etc/default/nfdump ] && . /etc/default/nfdump
31
 
 
32
 
# Load the VERBOSE setting and other rcS variables
33
 
. /lib/init/vars.sh
34
 
 
35
 
# Define LSB log_* functions.
36
 
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
37
 
. /lib/lsb/init-functions
38
 
 
39
 
#
40
 
# Function that starts the daemon/service
41
 
#
42
 
do_start()
43
 
{
44
 
        # Don't start daemon in this mode. Defined in /etc/default/nfdump
45
 
        if [ x"$nfcapd_start" = xno ]
46
 
        then
47
 
                [ "$VERBOSE" != no ] && log_warning_msg "nfdump daemon not enabled in /etc/default/nfdump, not starting..."
48
 
                return 0
49
 
        fi
50
 
        # Return
51
 
        #   0 if daemon has been started
52
 
        #   1 if daemon was already running
53
 
        #   2 if daemon could not be started
54
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
55
 
                || return 1
56
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
57
 
                $DAEMON_ARGS \
58
 
                || return 2
59
 
        # Add code here, if necessary, that waits for the process to be ready
60
 
        # to handle requests from services started subsequently which depend
61
 
        # on this one.  As a last resort, sleep for some time.
62
 
}
63
 
 
64
 
#
65
 
# Function that stops the daemon/service
66
 
#
67
 
do_stop()
68
 
{
69
 
        # Return
70
 
        #   0 if daemon has been stopped
71
 
        #   1 if daemon was already stopped
72
 
        #   2 if daemon could not be stopped
73
 
        #   other if a failure occurred
74
 
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
75
 
        RETVAL="$?"
76
 
        [ "$RETVAL" = 2 ] && return 2
77
 
        # Wait for children to finish too if this is a daemon that forks
78
 
        # and if the daemon is only ever run from this initscript.
79
 
        # If the above conditions are not satisfied then add some other code
80
 
        # that waits for the process to drop all resources that could be
81
 
        # needed by services started subsequently.  A last resort is to
82
 
        # sleep for some time. 
83
 
        #
84
 
        # Disabled second call, because is kills nfsen controlled nfcapd
85
 
        #start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
86
 
        #[ "$?" = 2 ] && return 2
87
 
        # Many daemons don't delete their pidfiles when they exit.
88
 
        rm -f $PIDFILE
89
 
        return "$RETVAL"
90
 
}
91
 
 
92
 
#
93
 
# Function that sends a SIGHUP to the daemon/service
94
 
#
95
 
do_reload() {
96
 
        #
97
 
        # If the daemon can reload its configuration without
98
 
        # restarting (for example, when it is sent a SIGHUP),
99
 
        # then implement that here.
100
 
        #
101
 
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
102
 
        return 0
103
 
}
104
 
 
105
 
case "$1" in
106
 
  start)
107
 
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
108
 
        do_start
109
 
        case "$?" in
110
 
                0|1) [ q"$VERBOSE" != qno ] && log_end_msg 0 ;;
111
 
                2)   [ p"$VERBOSE" != pno ] && log_end_msg 1 ;;
112
 
        esac
113
 
        ;;
114
 
  stop)
115
 
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
116
 
        do_stop
117
 
        case "$?" in
118
 
                0|1) [ "r$VERBOSE" != rno ] && log_end_msg 0 ;;
119
 
                2) [ "s$VERBOSE" != sno ] && log_end_msg 1 ;;
120
 
        esac
121
 
        ;;
122
 
  #reload|force-reload)
123
 
        #
124
 
        # If do_reload() is not implemented then leave this commented out
125
 
        # and leave 'force-reload' as an alias for 'restart'.
126
 
        #
127
 
        #log_daemon_msg "Reloading $DESC" "$NAME"
128
 
        #do_reload
129
 
        #log_end_msg $?
130
 
        #;;
131
 
  restart|force-reload)
132
 
        #
133
 
        # If the "reload" option is implemented then remove the
134
 
        # 'force-reload' alias
135
 
        #
136
 
        log_daemon_msg "Restarting $DESC" "$NAME"
137
 
        do_stop
138
 
        case "$?" in
139
 
          0|1)
140
 
                do_start
141
 
                case "$?" in
142
 
                        0|1) log_end_msg 0 ;;
143
 
                        *) log_end_msg 1 ;; # Failed to start
144
 
                esac
145
 
                ;;
146
 
          *)
147
 
                # Failed to stop
148
 
                log_end_msg 1
149
 
                ;;
150
 
        esac
151
 
        ;;
152
 
  *)
153
 
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
154
 
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
155
 
        exit 3
156
 
        ;;
157
 
esac
158
 
exit 0