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 allows you to turn it on or off.

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/

Installing Home Assistant Supervised on an old 32bit HP laptop

 I've received a challenge from my former boss: an old HP laptop that was born in 2005:  an HP-Compaq NC6220 ( https://www.pocket-lint.com/laptops/reviews/hp/68181-hp-compaq-nc6220-notebook-laptop/ ). The specs are abysmal: So, i386, 1.7GHz single-core CPU (remember those?), 1G of DDR2 RAM (2x512M) and a 40GB ATA (not SATA!) drive. But hey, at least it has a serial port!  The challenge is to install HomeAssistant ( https://www.home-assistant.io/ ) on it so that he can monitor some Zigbee temperature sensors and relays (via a gateway). The first hurdle was to remove the BIOS password - following this nice guide: https://www.youtube.com/watch?v=ZaGKyb0ntSg Next-up - install HASSOS. Unfortunately, it doesn't support i386, but only x86_64... So, I went the Home Assistant Supervised route, and installed Debian 11 i386 edition from a netinstall USB ( https://cdimage.debian.org/debian-cd/current/i386/iso-cd/debian-11.6.0-i386-netinst.iso ).   Once Debian was up and running (didn't