~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

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

  • 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 -e
2
 
#
3
 
### BEGIN INIT INFO
4
 
# Provides:          suricata
5
 
# Required-Start:    $time $network $local_fs $remote_fs
6
 
# Required-Stop:     $remote_fs
7
 
# Default-Start:     2 3 4 5
8
 
# Default-Stop:      0 1 6
9
 
# Short-Description: Next Generation IDS/IPS
10
 
# Description:       Intrusion detection system that will
11
 
#                    capture traffic from the network cards and will
12
 
#                    match against a set of known attacks.
13
 
### END INIT INFO
14
 
 
15
 
. /lib/lsb/init-functions
16
 
 
17
 
# Source function library.
18
 
if test -f /etc/default/suricata; then
19
 
    . /etc/default/suricata
20
 
else
21
 
    echo "/etc/default/suricata is missing... bailing out!"
22
 
fi
23
 
 
24
 
# We'll add up all the options above and use them
25
 
NAME=suricata
26
 
DAEMON=/usr/bin/$NAME
27
 
 
28
 
 
29
 
# Use this if you want the user to explicitly set 'RUN' in
30
 
# /etc/default/
31
 
if [ "x$RUN" != "xyes" ] ; then
32
 
    log_failure_msg "$NAME disabled, please adjust the configuration to your needs "
33
 
    log_failure_msg "and then set RUN to 'yes' in /etc/default/$NAME to enable it."
34
 
    exit 0
35
 
fi
36
 
 
37
 
check_root()  {
38
 
    if [ "$(id -u)" != "0" ]; then
39
 
        log_failure_msg "You must be root to start, stop or restart $NAME."
40
 
        exit 4
41
 
    fi
42
 
}
43
 
 
44
 
check_nfqueue() {
45
 
if [ ! -e /proc/net/netfilter/nf_queue ]; then
46
 
    log_failure_msg "NFQUEUE support not found !"
47
 
    log_failure_msg "Please ensure the nfnetlink_queue module is loaded or built in kernel"
48
 
    exit 5
49
 
fi
50
 
}
51
 
 
52
 
check_run_dir() {
53
 
    if [ ! -d /var/run/suricata ]; then
54
 
        mkdir /var/run/suricata
55
 
        chmod 0755 /var/run/suricata
56
 
    fi
57
 
}
58
 
 
59
 
 
60
 
 
61
 
check_root
62
 
 
63
 
case "$LISTENMODE" in
64
 
  nfqueue)
65
 
    IDMODE="IPS (nfqueue)"
66
 
    LISTEN_OPTIONS=" -q $NFQUEUE"
67
 
    check_nfqueue
68
 
    ;;
69
 
  pcap)
70
 
    IDMODE="IDS (pcap)"
71
 
    LISTEN_OPTIONS=" -i $IFACE"
72
 
    ;;
73
 
  af-packet)
74
 
    IDMODE="IDS (af-packet)"
75
 
    LISTEN_OPTIONS=" --af-packet"
76
 
    ;;
77
 
  *)
78
 
    echo "Unsupported listen mode $LISTENMODE, aborting"
79
 
    exit 1
80
 
    ;;
81
 
esac
82
 
 
83
 
SURICATA_OPTIONS=" -c $SURCONF --pidfile $PIDFILE $LISTEN_OPTIONS -D"
84
 
 
85
 
# See how we were called.
86
 
case "$1" in
87
 
  start)
88
 
       if [ -f $PIDFILE ]; then
89
 
           PID1=`cat $PIDFILE`
90
 
           if kill -0 "$PID1" 2>/dev/null; then
91
 
               echo "$NAME is already running with PID $PID1"
92
 
               exit 0
93
 
           fi
94
 
       fi
95
 
       check_run_dir
96
 
       echo -n "Starting suricata in $IDMODE mode..."
97
 
       if [ -f /usr/lib/libtcmalloc_minimal.so.0 ] && [ "x$TCMALLOC" = "xYES" ]; then
98
 
           export LD_PRELOAD="/usr/lib/libtcmalloc_minimal.so.0"
99
 
           #echo "Using googles tcmalloc for minor performance boost!?!"
100
 
       fi
101
 
       $DAEMON $SURICATA_OPTIONS > /var/log/suricata/suricata-start.log  2>&1 &
102
 
       echo " done."
103
 
       ;;
104
 
  stop)
105
 
       echo -n "Stopping suricata: "
106
 
       if [ -f $PIDFILE ]; then
107
 
           PID2=`cat $PIDFILE`
108
 
       else
109
 
           echo " No PID file found; not running?"
110
 
           exit 0;
111
 
       fi
112
 
       start-stop-daemon --oknodo --stop --quiet --pidfile=$PIDFILE --exec $DAEMON
113
 
       if [ -n "$PID2" ]; then
114
 
           kill "$PID2"
115
 
           ret=$?
116
 
           sleep 2
117
 
           if kill -0 "$PID2" 2>/dev/null; then
118
 
               ret=$?
119
 
               echo -n "Waiting . "
120
 
               cnt=0
121
 
               while kill -0 "$PID2" 2>/dev/null; do
122
 
                   ret=$?
123
 
                   cnt=`expr "$cnt" + 1`
124
 
                   if [ "$cnt" -gt 10 ]; then
125
 
                      kill -9 "$PID2"
126
 
                      break
127
 
                   fi
128
 
                   sleep 2
129
 
                   echo -n ". "
130
 
               done
131
 
           fi
132
 
       fi
133
 
       if [ -e $PIDFILE ]; then
134
 
           rm $PIDFILE > /dev/null 2>&1
135
 
       fi
136
 
       echo " done."
137
 
    ;;
138
 
  status)
139
 
       # Check if running...
140
 
       if [ -s $PIDFILE ]; then
141
 
           PID3=`cat $PIDFILE`
142
 
           if kill -0 "$PID3" 2>/dev/null; then
143
 
               echo "$NAME is running with PID $PID3"
144
 
               exit 0
145
 
           else
146
 
               echo "PID file $PIDFILE exists, but process not running!"
147
 
           fi
148
 
       else
149
 
          echo "$NAME not running!"
150
 
       fi
151
 
    ;;
152
 
  restart)
153
 
        $0 stop
154
 
        $0 start
155
 
    ;;
156
 
  force-reload)
157
 
        $0 stop
158
 
        $0 start
159
 
    ;;
160
 
  *)
161
 
        echo "Usage: $0 {start|stop|restart|status}"
162
 
        exit 1
163
 
esac
164
 
 
165
 
exit 0