blob: 0d90c9af03c1453f1e571bfc29a1789cb1b10500 [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001#!/bin/sh
2#
Brad Bishopc8f47122019-06-24 09:36:18 -04003# Snort Startup Script modified for OpenEmbedded
Patrick Williamsb48b7b42016-08-17 15:04:38 -05004#
5
6# Script variables
7
8LAN_INTERFACE="$2"
9RETURN_VAL=0
10BINARY=/usr/bin/snort
11PATH=/bin:/usr/bin
12PID=/var/run/snort_${LAN_INTERFACE}_ids.pid
13DEL_PID=$PID
14LOGDIR="/var/log/snort"
15DATE=`/bin/date +%Y%m%d`
16CONFIG_FILE=/etc/snort/snort.conf
17PROG=snort
18USER=root
19GROUP=root
20
21if [ ! -x "$BINARY" ]; then
22 echo "ERROR: $BINARY not found."
23 exit 1
24fi
25
26if [ ! -r "$CONFIG_FILE" ]; then
27 echo "ERROR: $CONFIG_FILE not found."
28 exit 1
29fi
30
31start()
32{
Patrick Williamsb48b7b42016-08-17 15:04:38 -050033 [ -n "$LAN_INTERFACE" ] || return 0
34 # Check if log diratory is present. Otherwise, create it.
35 if [ ! -d $LOGDIR/$DATE ]; then
Brad Bishopc8f47122019-06-24 09:36:18 -040036 mkdir -p $LOGDIR/$DATE
Patrick Williamsb48b7b42016-08-17 15:04:38 -050037 /bin/chown -R $USER:$USER $LOGDIR/$DATE
Brad Bishopc8f47122019-06-24 09:36:18 -040038 /bin/chmod -R 700 $LOGDIR/$DATE
Patrick Williamsb48b7b42016-08-17 15:04:38 -050039 fi
40
41 /bin/echo "Starting $PROG: "
Brad Bishopc8f47122019-06-24 09:36:18 -040042
Patrick Williamsb48b7b42016-08-17 15:04:38 -050043 # Snort parameters
44 # -D Run Snort in background (daemon) mode
45 # -i <if> Listen on interface <if>
46 # -u <uname> Run snort uid as <uname> user (or uid)
47 # -g <gname> Run snort uid as <gname> group (or gid)
48 # -c Load configuration file
49 # -N Turn off logging (alerts still work) (removed to enable logging) :)
50 # -l Log to directory
51 # -t Chroots process to directory after initialization
52 # -R <id> Include 'id' in snort_intf<id>.pid file name
53
54 $BINARY -D -i $LAN_INTERFACE -u $USER -g $GROUP -c $CONFIG_FILE -l $LOGDIR/$DATE -t $LOGDIR/$DATE -R _ids
55 /bin/echo "$PROG startup complete."
56 return $RETURN_VAL
57}
58
59stop()
60{
61 if [ -s $PID ]; then
62 /bin/echo "Stopping $PROG with PID `cat $PID`: "
63 kill -TERM `cat $PID` 2>/dev/null
64 RETURN_VAL=$?
65 /bin/echo "$PROG shutdown complete."
66 [ -e $DEL_PID ] && rm -f $DEL_PID
Brad Bishopc8f47122019-06-24 09:36:18 -040067 [ -e $DEL_PID.lck ] && rm -f $DEL_PID.lck
Patrick Williamsb48b7b42016-08-17 15:04:38 -050068 else
69 /bin/echo "ERROR: PID in $PID file not found."
70 RETURN_VAL=1
71 fi
72 return $RETURN_VAL
73}
74
Brad Bishopc8f47122019-06-24 09:36:18 -040075status()
76{
77 if [ -s $PID ]; then
78 echo "$PROG is running as pid `cat $PID`:"
79 else
80 echo "$PROG is not running."
81 fi
Patrick Williamsb48b7b42016-08-17 15:04:38 -050082}
83
84restart()
85{
86 stop
87 start
88 RETURN_VAL=$?
89 return $RETURN_VAL
90}
91
92case "$1" in
Brad Bishopc8f47122019-06-24 09:36:18 -040093 start)
94 start
95 ;;
96 stop)
97 stop
98 ;;
99 status)
100 status
101 ;;
102 restart|reload)
103 restart
104 ;;
105 *)
106 /bin/echo "Usage: $0 {start|stop|status|restart|reload}"
107 RETURN_VAL=1
Patrick Williamsb48b7b42016-08-17 15:04:38 -0500108esac
109
110exit $RETURN_VAL