Skip to content

Instantly share code, notes, and snippets.

@mbrownnycnyc
Last active December 17, 2015 09:28
Show Gist options
  • Select an option

  • Save mbrownnycnyc/5587142 to your computer and use it in GitHub Desktop.

Select an option

Save mbrownnycnyc/5587142 to your computer and use it in GitHub Desktop.
rastream init script
#! /bin/sh
### BEGIN INIT INFO
# Provides: rastream-client
# Required-Start: $network $argusd
# Required-Stop:
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: argus client to attach to argus tcp socket and write to local files
# Description:
### END INIT INFO
#The check for $argusd is irrelevant if you are running rastream on a remote system from argus, obviously
CONFFILE=/etc/rastream.conf
PROG=rastream
DAEMON=/usr/local/bin/$PROG
NAME=rastreamd
SETTINGS="-S 127.0.0.1:561 -B 15s -M time 1h -w /var/opt/argus/%Y-%m-%d/argus_%T -f /usr/local/bin/rastream.sh -F $CONFFILE"
. /etc/rc.d/init.d/functions
[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
#/etc/rastream.conf contain at least:
# RA_SET_PID="yes"
# RA_PID_PATH="/var/run"
#an example .rarc is contained within the source tree at ../support/Config/rarc
if [ ! -f $CONFFILE ]; then
echo "$CONFFILE doesn't exist or is not a regular file."
exit 1
fi
if [ -f $CONFFILE ]; then
#check to see if the $CONFFILE contains RA_SET_PID="YES"
grep 'RA_SETPID="no"' $CONFFILE &> /dev/null
if [ $? = 1 ]; then
grep '^RA_SETPID="yes"' $CONFFILE &> /dev/null
if [ $? = 0 ]; then
echo -n " RA_SETPID=\"yes\" is not present in $CONFFILE "
echo_failure
exit 1
fi
fi
fi
PIDFILE=/var/run/rastream.pid
testrunning ()
{
if [ -f $PIDFILE ] && [ -n "$(ps -p $(cat $PIDFILE) | grep $PROG)" ]; then
echo_success
echo "$DAEMON is running with PID $(cat $PIDFILE)."
exit 1
else
echo_warning
echo "$DAEMON is not running."
fi
}
testpid ()
{
if [ ! -f $PIDFILE ]; then
echo_warning
echo "$DAEMON is stopped."
exit 1
fi
}
#returns 1 if FILE exists and execute (or search) permission is granted
test -x $DAEMON || exit 1
case "$1" in
start)
echo -n "Starting $NAME: "
testrunning
#$DAEMON -d $SETTINGS #disabled due to bug, http://thread.gmane.org/gmane.network.argus/9354/focus=9363
nohup $DAEMON $SETTINGS &
testrunning
echo ""
;;
stop)
echo -n "Stopping $NAME: "
testpid
kill `cat $PIDFILE`
rm -f "$PIDFILE"
echo_success
echo ""
;;
restart)
echo -n "Restarting $NAME: "
kill `cat $PIDFILE` > /dev/null 2>&1 || true
rm -f "$PIDFILE"
#$DAEMON -d $SETTINGS #disabled due to bug, http://thread.gmane.org/gmane.network.argus/9354/focus=9363
nohup $DAEMON $SETTINGS &
echo_success
echo ""
;;
status)
echo "Checking $NAME status: "
testrunning
echo ""
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment