112 lines
2.3 KiB
Bash
Executable File
112 lines
2.3 KiB
Bash
Executable File
#!/bin/sh
|
|
### BEGIN INIT INFO
|
|
# Provides: osmocom-tcpdump
|
|
# Required-Start: $remote_fs $network
|
|
# Should-Start: udev
|
|
# Required-Stop: $remote_fs $network
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Stop: 0 1 6
|
|
### END INIT INFO
|
|
|
|
# Do NOT "set -e"
|
|
|
|
# PATH should only include /usr/* if it runs after the mountnfs.sh script
|
|
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
|
DESC="Osmocom traffic capture"
|
|
NAME="tcpdump"
|
|
DAEMON=/usr/sbin/$NAME
|
|
PIDFILE=/var/run/osmocom-tcpdump-$NAME.pid
|
|
SCRIPTNAME=/etc/init.d/osmocom-tcpdump
|
|
|
|
|
|
CAPTURE_ENABLED="0"
|
|
CAPTURE_LIMIT="8"
|
|
CAPTURE_SIZE="1"
|
|
CAPTURE_BASENAME="/tmp/tcpdump-capture-"
|
|
CAPTURE_COMPRESS="-z /usr/sbin/tcpdump-compress"
|
|
|
|
if [ -e /etc/default/osmocom-tcpdump ]; then
|
|
. /etc/default/osmocom-tcpdump
|
|
fi
|
|
|
|
|
|
CAPTURE_OPTIONS="-pi $CAPTURE_DEVICE -s0 -w $CAPTURE_BASENAME -C $CAPTURE_SIZE -W $CAPTURE_LIMIT $CAPTURE_COMPRESS"
|
|
|
|
#
|
|
# Function that starts the daemon/service
|
|
#
|
|
do_start()
|
|
{
|
|
# Return
|
|
# 0 if daemon has been started
|
|
# 1 if daemon was already running
|
|
# 2 if daemon could not be started
|
|
if [ -z "$CAPTURE_DEVICE" -o -z "$CAPTURE_FILTER" ]; then
|
|
echo "Unable to start $DESC" "$NAME" "(unconfigured)"
|
|
exit 2
|
|
fi
|
|
if [ "$CAPTURE_ENABLED" != "1" ]; then
|
|
echo "Not starting $DESC" "$NAME" "(disabled)"
|
|
exit 0
|
|
fi
|
|
#start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|
|
# || return 1
|
|
echo "Starting $DESC" "$NAME"
|
|
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
|
|
--background --make-pidfile -- $CAPTURE_OPTIONS $CAPTURE_FILTER \
|
|
|| return 2
|
|
}
|
|
|
|
#
|
|
# Function that stops the daemon/service
|
|
#
|
|
do_stop()
|
|
{
|
|
# Return
|
|
# 0 if daemon has been stopped
|
|
# 1 if daemon was already stopped
|
|
# 2 if daemon could not be stopped
|
|
# other if a failure occurred
|
|
echo "Stopping $DESC" "$NAME"
|
|
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
|
|
RETVAL="$?"
|
|
[ "$RETVAL" = 2 ] && return 2
|
|
# Many daemons don't delete their pidfiles when they exit.
|
|
rm -f $PIDFILE
|
|
return "$RETVAL"
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
do_start
|
|
exit $?
|
|
;;
|
|
stop)
|
|
do_stop
|
|
exit $?
|
|
;;
|
|
restart)
|
|
#
|
|
# If the "reload" option is implemented then remove the
|
|
# 'force-reload' alias
|
|
#
|
|
do_stop
|
|
case "$?" in
|
|
0|1)
|
|
do_start
|
|
exit $?
|
|
;;
|
|
*)
|
|
# Failed to stop
|
|
exit 1
|
|
;;
|
|
esac
|
|
;;
|
|
*)
|
|
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
|
|
exit 3
|
|
;;
|
|
esac
|
|
|
|
:
|