Skip to main content

samplicator system-v startup scripts

Samplicator looks like a great UDP fan-out tool for Linux/Unix.
Unfortunately, it doesn't have proper startup/shutdown scripts.

Here are, for your convenience such startup scripts adapted from apmd (currently tested only on Linux). Dependencies are: GNU grep and perl (to emulate a PID mechanism).


#!/bin/sh
#
# chkconfig: 2345 26 74
# description: samplicator is a daemon to fanout UPD packets
# processname: samplicator-syslog

# Source function library.
. /etc/init.d/functions

RETVAL=0
SERVICE="syslog"
UDPLISTENPORT=514
SOURCEIP="10.0.250.131"
DESTINATIONS="10.0.250.132/514 10.0.250.61/514";
PIDFILE="samplicator-$SERVICE.pid"

start() {
  echo -n $"Starting up samplicator-$SERVICE daemon: "
  daemon --check samplicator-$SERVICE /usr/bin/samplicate -f -p $UDPLISTENPORT -s $SOURCEIP -b 8388608 -S $DESTINATIONS; netstat -upan | grep -P "$SOURCEIP:$UDPLISTENPORT.*samplicate" | perl -e 'my $line=; $line=~/([0-9]+)\//; print "$1\n";' >/var/run/$PIDFILE
  RETVAL=$?
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/samplicator-$SERVICE
  echo
  return $RETVAL
}

stop() {
  echo -n $"Shutting down samplicator-$SERVICE daemon: "
  killproc samplicator-$SERVICE
  RETVAL=$?
  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/samplicator-$SERVICE
  echo
  return $RETVAL
}

dostatus() {
  #determine if the program is running based on the UDP port
  STATUS=`netstat -upan | grep -P "$SOURCEIP:$UDPLISTENPORT.*samplicate"|wc -l`;
  if [ $STATUS -eq 1 ]; then
    echo "samplicator-$SERVICE is running, bound on UDP port $UDPLISTENPORT";
  else
  #           echo "samplicator-$SERVICE is not running.";
    status samplicator-$SERVICE
  fi
}

restart() {
  stop
  start
}

condrestart() {
  [ -e /var/lock/subsys/samplicator-$SERVICE ] && restart || :
}

# See how we were called.
  case "$1" in
  start)
    start
  ;;
  stop)
    stop
  ;;
  status)
    dostatus
  ;;
  restart|reload)
    restart
  ;;
  condrestart)
    condrestart
  ;;
  *)
    echo $"Usage: samplicator-$SERVICE {start|stop|status|restart|reload|condrestart}"
    exit 1
  esac

exit $RETVAL 
 
The above example is for a syslog fan-out daemon. It can be easily changed to a snmp-trap or netflow fanout startup script by changing the variables at the top. Multiple concurrent daemons can run on different ports.

Good luck

Comments

Unknown said…
I get a perl error running the service

Starting up samplicator-syslog daemon: /etc/init.d/samplicate-syslog: line 19: daemon: command not found
syntax error at -e line 1, near "=;"
Execution of -e aborted due to compilation errors.
Adrian Popa said…
Sorry to take such a long time to reply, but what distro are you running the script under? I've tested it under RHEL and Debian and it used to work.

There are some other proposed startup scripts available at their project page: http://code.google.com/p/samplicator/issues/detail?id=13

Popular posts from this blog

Home Assistant + Android TV = fun

Here's a quick setup guide for controlling your Android TV from within Home Assistant. I've used it to control a genuine Android TV (Philips 7304) and an Odroid N2 running Android TV. For this to work you need ADB access. It can usually be enabled from within Developer Settings. The great part is - you don't need root access! The most important things are described in the androidtv component for Home Assistant: https://www.home-assistant.io/integrations/androidtv/ Make sure you go through the adb setup. My configuration is simple (inside configuration.yaml): media_player:   - platform: androidtv     name: TV Bedroom ATV     host: 192.168.1.61     device_class: androidtv Once Home Assistant restarts, your TV might require you to accept the connection (adb authentication). This happens only once (or until you reset your ATV to factory settings). Once running the integration will show you the current ATV state (on or off) and al...

SmokePing + InfluxDB export + docker + slaves + Grafana = fun

I've been working for a while on this project - with the purpose of getting SmokePing measurements from different hosts (slaves) into InfluxDB so that we can better graph them with Grafana. The slaves run multiple Smokeping instances inside Docker so that they have separate networking (measure through different uplinks, independently). This will not be a comprehensive configuration guide, but a quick "how to" to handle setup and basic troubleshooting. It assumes you already know how to set up and operate a regular Smokeping install with or without slaves and that you are fluent in Smokeping configuration syntax, know your way around Docker and aren't a stranger from InfluxDB and Grafana (sorry, there's a lot of information to take in). 1. Getting Smokeping with InfluxDB support - you can get it either from the official page (most changes have been merged) - https://github.com/oetiker/SmokePing (PR discussion here: https://github.com/oetiker/SmokePing/issues/...

Android: Adding scp/sftp support to dropbear and mounting with sshfs

I have recently received an android smartphone, and one of the first things I did with it was to root it :). This allows power-usres to get the most out of their hardware. The next thing on my list was to set up a SSH server and to be able to transfer files between my Linux system and my phone (by the way, I'm running Android 4.1 and it seems USB mass storage support has been removed. MTP/PTP modes have either horrible transfer speed or are poorly supported in Ubuntu). With the above in mind, the plan was to: Enable tethering on the phone Run a SSH server to support issuing remote commands and file transfer (FTP might have been an alternative, but I'm a SSH adept). Browsing the market I found  SSHDroid which does all that it advertised. Problem is - the free version conflicts with my add-blocking apps and requests that they are disabled to run. For me, this is a big nuisance, so I kept looking. I found Dropbear SSH Server 2 , which is completely free, but doesn'...