From 73e21be50a278a7630bfe9bf5ace708caa320a90 Mon Sep 17 00:00:00 2001 From: john30 Date: Sat, 28 May 2016 10:33:06 +0200 Subject: [PATCH] added support for running multiple ebusd instances by adjusting /etc/default/ebusd --- contrib/debian/default/ebusd | 11 +++++ contrib/debian/init.d/ebusd | 81 ++++++++++++++++++++++++++++++------ 2 files changed, 79 insertions(+), 13 deletions(-) mode change 100755 => 100644 contrib/debian/init.d/ebusd diff --git a/contrib/debian/default/ebusd b/contrib/debian/default/ebusd index 03083742..d926c2c9 100644 --- a/contrib/debian/default/ebusd +++ b/contrib/debian/default/ebusd @@ -3,3 +3,14 @@ # Options to pass to ebusd (run "ebusd -?" for more info): EBUSD_OPTS="--scanconfig" + +# In order to run multiple ebusd instances, simply define several EBUSD_OPTS +# with a unique suffix for each. +# Recommended is using a number as suffix for all EBUSD_OPTS settings. +# That number can then be used as additional "instance" parameter to the init.d +# script in order to start/stop an individual ebusd instance instead of all +# instances. +# Example (uncomment the EBUSD_OPTS above): +#EBUSD_OPTS1="--scanconfig -d /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50285BI-if00-port0 -p 8888" +#EBUSD_OPTS2="--scanconfig -d /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A900acTF-if00-port0 -p 8889" +#EBUSD_OPTS3="--scanconfig -d /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A900beCG-if00-port0 -p 8890" \ No newline at end of file diff --git a/contrib/debian/init.d/ebusd b/contrib/debian/init.d/ebusd old mode 100755 new mode 100644 index b4122d6d..356fd1f0 --- a/contrib/debian/init.d/ebusd +++ b/contrib/debian/init.d/ebusd @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # ### BEGIN INIT INFO # Provides: ebusd @@ -10,7 +10,8 @@ ### END INIT INFO DAEMON=/usr/bin/ebusd -PIDFILE=/var/run/ebusd.pid +PIDFILE_PREFIX=/var/run/ebusd +PIDFILE_SUFFIX=.pid . /lib/lsb/init-functions [ -r /etc/default/ebusd ] && . /etc/default/ebusd @@ -20,27 +21,81 @@ if [ ! -x $DAEMON ]; then exit 5 fi +ALL_OPTS=${!EBUSD_OPTS*} +if [ ${#ALL_OPTS[@]} -lt 1 ]; then + ALL_OPTS[0]=EBUSD_OPTS +fi +instance="EBUSD_OPTS$2" +instance=${!instance} + +start_instance () { + local opts suffix + opts=$1 + shift + suffix="${opts#EBUSD_OPTS}" + log_daemon_msg "Starting ebusd${suffix}" ebusd + pidfile=$PIDFILE_PREFIX${suffix}$PIDFILE_SUFFIX + start-stop-daemon --start --quiet --oknodo --pidfile $pidfile --exec $DAEMON -- --pidfile $pidfile ${!opts} + log_end_msg $? +} + +stop_instance () { + local opts suffix + opts=$1 + shift + suffix="${opts#EBUSD_OPTS}" + log_daemon_msg "Stopping ebusd${suffix}" ebusd + pidfile=$PIDFILE_PREFIX${suffix}$PIDFILE_SUFFIX + start-stop-daemon --stop --quiet --oknodo --pidfile $pidfile + log_end_msg $? + rm -f $PIDFILE_PREFIX${suffix}$PIDFILE_SUFFIX +} + case $1 in start) - log_daemon_msg "Starting ebusd" "ebusd" - start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON -- $EBUSD_OPTS - status=$? - log_end_msg $status + if [ -z "$2" ]; then + for opts in $ALL_OPTS; do + start_instance $opts + done + elif [ -z "$instance" ]; then + log_failure_msg "ebusd$2 is not configured" + else + start_instance EBUSD_OPTS$2 + fi ;; stop) - log_daemon_msg "Stopping ebusd" "ebusd" - start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE - log_end_msg $? - rm -f $PIDFILE + if [ -z "$2" ]; then + for opts in $ALL_OPTS; do + stop_instance $opts + done + else + if [ -z "$instance" ]; then + log_warning_msg "ebusd$2 is not configured" + fi + stop_instance EBUSD_OPTS$2 + fi ;; restart|force-reload) - $0 stop && sleep 2 && $0 start + ARGS=($@) + $0 stop ${ARGS[@]:1} && sleep 2 && $0 start ${ARGS[@]:1} ;; status) - status_of_proc $DAEMON "ebusd" + if [ -z "$2" ]; then + for opts in $ALL_OPTS; do + suffix=${opts#EBUSD_OPTS} + pidfile=$PIDFILE_PREFIX$suffix$PIDFILE_SUFFIX + status_of_proc -p $pidfile $DAEMON ebusd$suffix + done + else + if [ -z "$instance" ]; then + log_warning_msg "ebusd$2 is not configured" + fi + pidfile=$PIDFILE_PREFIX$2$PIDFILE_SUFFIX + status_of_proc -p $pidfile $DAEMON ebusd$2 + fi ;; *) - echo "Usage: $0 {start|stop|restart|force-reload|status}" + echo "Usage: $0 {start|stop|restart|force-reload|status} [instance]" exit 2 ;; esac