~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

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

  • 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:          sagan
4
 
# Required-Start:    $network $local_fs $remote_fs
5
 
# Required-Stop:     $remote_fs
6
 
# Default-Start:     2 3 4 5
7
 
# Default-Stop:      0 1 6
8
 
# Short-Description: Real-time System & Event Log Monitoring System
9
 
# Description:       Sagan is a multi-threaded, real time system- and event-log monitoring
10
 
#                    system. Sagan uses a “Snort” like rule set for
11
 
#                    detecting malicious events happening on your network and/or computer
12
 
#                    systems.
13
 
### END INIT INFO
14
 
 
15
 
# Author: Pierre Chifflier <pollux@debian.org>
16
 
 
17
 
# PATH should only include /usr/* if it runs after the mountnfs.sh script
18
 
PATH=/sbin:/usr/sbin:/bin:/usr/bin
19
 
DESC=sagan             # Introduce a short description here
20
 
NAME=sagan             # Introduce the short server's name here
21
 
DAEMON=/usr/sbin/sagan # Introduce the server's location here
22
 
DAEMON_ARGS="-D"             # Arguments to run the daemon with
23
 
PIDFILE=/var/run/$NAME.pid
24
 
SCRIPTNAME=/etc/init.d/$NAME
25
 
VARRUN=/var/run/$NAME
26
 
 
27
 
# Exit if the package is not installed
28
 
[ -x $DAEMON ] || exit 0
29
 
 
30
 
# Read configuration variable file if it is present
31
 
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
32
 
 
33
 
# Load the VERBOSE setting and other rcS variables
34
 
. /lib/init/vars.sh
35
 
 
36
 
# Define LSB log_* functions.
37
 
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
38
 
. /lib/lsb/init-functions
39
 
 
40
 
#
41
 
# Function that starts the daemon/service
42
 
#
43
 
do_start()
44
 
{
45
 
        [ -d "$VARRUN" ] || mkdir "$VARRUN"
46
 
        chown sagan:adm "$VARRUN"
47
 
        [ -e "$VARRUN/sagan.fifo" ] || mkfifo -m 0770 "$VARRUN/sagan.fifo"
48
 
        chown sagan:adm "$VARRUN/sagan.fifo"
49
 
        # Return
50
 
        #   0 if daemon has been started
51
 
        #   1 if daemon was already running
52
 
        #   2 if daemon could not be started
53
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
54
 
                || return 1
55
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
56
 
                $DAEMON_ARGS \
57
 
                || return 2
58
 
        # Add code here, if necessary, that waits for the process to be ready
59
 
        # to handle requests from services started subsequently which depend
60
 
        # on this one.  As a last resort, sleep for some time.
61
 
}
62
 
 
63
 
#
64
 
# Function that stops the daemon/service
65
 
#
66
 
do_stop()
67
 
{
68
 
        # Return
69
 
        #   0 if daemon has been stopped
70
 
        #   1 if daemon was already stopped
71
 
        #   2 if daemon could not be stopped
72
 
        #   other if a failure occurred
73
 
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
74
 
        RETVAL="$?"
75
 
        [ "$RETVAL" = 2 ] && return 2
76
 
        # Wait for children to finish too if this is a daemon that forks
77
 
        # and if the daemon is only ever run from this initscript.
78
 
        # If the above conditions are not satisfied then add some other code
79
 
        # that waits for the process to drop all resources that could be
80
 
        # needed by services started subsequently.  A last resort is to
81
 
        # sleep for some time.
82
 
        start-stop-daemon --stop --quiet --oknodo --retry=0/10/KILL/5 --exec $DAEMON
83
 
        [ "$?" = 2 ] && return 2
84
 
        # Many daemons don't delete their pidfiles when they exit.
85
 
        rm -f $PIDFILE
86
 
        return "$RETVAL"
87
 
}
88
 
 
89
 
#
90
 
# Function that sends a SIGHUP to the daemon/service
91
 
#
92
 
do_reload() {
93
 
        #
94
 
        # If the daemon can reload its configuration without
95
 
        # restarting (for example, when it is sent a SIGHUP),
96
 
        # then implement that here.
97
 
        #
98
 
        start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
99
 
        return 0
100
 
}
101
 
 
102
 
case "$1" in
103
 
  start)
104
 
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
105
 
    do_start
106
 
    case "$?" in
107
 
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
108
 
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
109
 
        esac
110
 
  ;;
111
 
  stop)
112
 
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
113
 
        do_stop
114
 
        case "$?" in
115
 
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
116
 
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
117
 
        esac
118
 
        ;;
119
 
  status)
120
 
       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
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) log_end_msg 0 ;;
143
 
                        1) log_end_msg 1 ;; # Old process is still running
144
 
                        *) log_end_msg 1 ;; # Failed to start
145
 
                esac
146
 
                ;;
147
 
          *)
148
 
                # Failed to stop
149
 
                log_end_msg 1
150
 
                ;;
151
 
        esac
152
 
        ;;
153
 
  *)
154
 
        #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
155
 
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
156
 
        exit 3
157
 
        ;;
158
 
esac
159
 
 
160
 
: