From 8bffbe91facef3f9296df89d6a949c14ca007dc4 Mon Sep 17 00:00:00 2001 From: AnthorNet Date: Thu, 29 Jun 2017 12:20:39 +0200 Subject: [PATCH] Make init.d scripts working with Debian --- contrib/init.d/eddn-gateway | 90 ++++++++++++++----------------------- contrib/init.d/eddn-monitor | 90 ++++++++++++++----------------------- contrib/init.d/eddn-relay | 90 ++++++++++++++----------------------- 3 files changed, 99 insertions(+), 171 deletions(-) diff --git a/contrib/init.d/eddn-gateway b/contrib/init.d/eddn-gateway index e33c916..3b87b73 100644 --- a/contrib/init.d/eddn-gateway +++ b/contrib/init.d/eddn-gateway @@ -8,70 +8,46 @@ # Default-Stop: 0 1 6 ### END INIT INFO -# ------------------------------------------------------------------------- -#    Based on: -#    Copyright (C) <2011>  - ppacory-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org -# Modified by James Muscat -#    This program is free software: you can redistribute it and/or modify -#    it under the terms of the GNU General Public License as published by -#    the Free Software Foundation, either version 3 of the License, or -#    (at your option) any later version. +NAME=eddn-gateway +DESC="eddn-gateway" +PIDFILE="/var/run/${NAME}.pid" +LOGFILE="/var/log/eddn/${NAME}.log" -#    This program is distributed in the hope that it will be useful, -#    but WITHOUT ANY WARRANTY; without even the implied warranty of -#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -#    GNU General Public License for more details. +DAEMON="/usr/local/bin/${NAME}" -#    You should have received a copy of the GNU General Public License -#    along with this program.  If not, see . -# ------------------------------------------------------------------------- +EXEC_AS_USER="root" +START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --chuid ${EXEC_AS_USER} --exec ${DAEMON}" +STOP_OPTS="--stop --pidfile ${PIDFILE}" -MESSAGEDIR=/var/log/eddn -MESSAGELOG=/var/log/eddn/gateway.log -PID=/var/run/eddn-gateway.pid -EXECUTABLE=/usr/local/bin/eddn-gateway -CMDLINE="" +test -x $DAEMON || exit 0 - -# Check the script is being run by root user -if [ "$(id -u)" != "0" ]; then -  echo 1>&2 "ERROR: The $0 script must be run as root" -  exit 1 -fi - -# Create the PID File -touch $PID +set -e case "$1" in - start) - # create the log directory if not exist - [ ! -d "$MESSAGEDIR" ] && mkdir -p "$MESSAGEDIR" - - echo "Starting $EXECUTABLE" - # test if not already running - if [ ! -f "/proc/$(cat $PID)/exe" ]; then - $EXECUTABLE "$CMDLINE" > "$MESSAGELOG" 2>&1 & - echo $!>"$PID" - else - echo "$EXECUTABLE already running" - fi - ;; - stop) - echo "Stopping $EXECUTABLE" - # test if running - if [ -f "/proc/$(cat $PID)/exe" ]; then - kill -9 "$(cat $PID)" - rm -rf "$PID" - else - echo "$EXECUTABLE already stopped" - fi +start) + echo -n "Starting ${DESC}: " + start-stop-daemon $START_OPTS >> $LOGFILE + echo "$NAME." ;; - restart) - $0 stop - $0 start +stop) + echo -n "Stopping $DESC: " + start-stop-daemon $STOP_OPTS + echo "$NAME." + rm -f $PIDFILE + ;; +restart|force-reload) + echo -n "Restarting $DESC: " + start-stop-daemon $STOP_OPTS + sleep 1 + start-stop-daemon $START_OPTS >> $LOGFILE + echo "$NAME." + ;; +*) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|restart|force-reload}" >&2 + exit 1 ;; - *) - echo "usage: $0 {start|stop|restart}" esac -exit 0 + +exit 0 \ No newline at end of file diff --git a/contrib/init.d/eddn-monitor b/contrib/init.d/eddn-monitor index e567d9c..2d73441 100644 --- a/contrib/init.d/eddn-monitor +++ b/contrib/init.d/eddn-monitor @@ -8,70 +8,46 @@ # Default-Stop: 0 1 6 ### END INIT INFO -# ------------------------------------------------------------------------- -#    Based on: -#    Copyright (C) <2011>  - ppacory-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org -# Modified by James Muscat -#    This program is free software: you can redistribute it and/or modify -#    it under the terms of the GNU General Public License as published by -#    the Free Software Foundation, either version 3 of the License, or -#    (at your option) any later version. +NAME=eddn-monitor +DESC="eddn-monitor" +PIDFILE="/var/run/${NAME}.pid" +LOGFILE="/var/log/eddn/${NAME}.log" -#    This program is distributed in the hope that it will be useful, -#    but WITHOUT ANY WARRANTY; without even the implied warranty of -#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -#    GNU General Public License for more details. +DAEMON="/usr/local/bin/${NAME}" -#    You should have received a copy of the GNU General Public License -#    along with this program.  If not, see . -# ------------------------------------------------------------------------- +EXEC_AS_USER="root" +START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --chuid ${EXEC_AS_USER} --exec ${DAEMON}" +STOP_OPTS="--stop --pidfile ${PIDFILE}" -MESSAGEDIR=/var/log/eddn -MESSAGELOG=/var/log/eddn/monitor.log -PID=/var/run/eddn-monitor.pid -EXECUTABLE=/usr/local/bin/eddn-monitor -CMDLINE="" +test -x $DAEMON || exit 0 - -# Check the script is being run by root user -if [ "$(id -u)" != "0" ]; then -  echo 1>&2 "ERROR: The $0 script must be run as root" -  exit 1 -fi - -# Create the PID File -touch $PID +set -e case "$1" in - start) - # create the log directory if not exist - [ ! -d "$MESSAGEDIR" ] && mkdir -p "$MESSAGEDIR" - - echo "Starting $EXECUTABLE" - # test if not already running - if [ ! -f "/proc/$(cat $PID)/exe" ]; then - $EXECUTABLE "$CMDLINE" > "$MESSAGELOG" 2>&1 & - echo $!>"$PID" - else - echo "$EXECUTABLE already running" - fi - ;; - stop) - echo "Stopping $EXECUTABLE" - # test if running - if [ -f "/proc/$(cat $PID)/exe" ]; then - kill -9 "$(cat $PID)" - rm -rf "$PID" - else - echo "$EXECUTABLE already stopped" - fi +start) + echo -n "Starting ${DESC}: " + start-stop-daemon $START_OPTS >> $LOGFILE + echo "$NAME." ;; - restart) - $0 stop - $0 start +stop) + echo -n "Stopping $DESC: " + start-stop-daemon $STOP_OPTS + echo "$NAME." + rm -f $PIDFILE + ;; +restart|force-reload) + echo -n "Restarting $DESC: " + start-stop-daemon $STOP_OPTS + sleep 1 + start-stop-daemon $START_OPTS >> $LOGFILE + echo "$NAME." + ;; +*) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|restart|force-reload}" >&2 + exit 1 ;; - *) - echo "usage: $0 {start|stop|restart}" esac -exit 0 + +exit 0 \ No newline at end of file diff --git a/contrib/init.d/eddn-relay b/contrib/init.d/eddn-relay index c573210..24b3d79 100644 --- a/contrib/init.d/eddn-relay +++ b/contrib/init.d/eddn-relay @@ -8,70 +8,46 @@ # Default-Stop: 0 1 6 ### END INIT INFO -# ------------------------------------------------------------------------- -#    Based on: -#    Copyright (C) <2011>  - ppacory-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org -# Modified by James Muscat -#    This program is free software: you can redistribute it and/or modify -#    it under the terms of the GNU General Public License as published by -#    the Free Software Foundation, either version 3 of the License, or -#    (at your option) any later version. +NAME=eddn-relay +DESC="eddn-relay" +PIDFILE="/var/run/${NAME}.pid" +LOGFILE="/var/log/eddn/${NAME}.log" -#    This program is distributed in the hope that it will be useful, -#    but WITHOUT ANY WARRANTY; without even the implied warranty of -#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the -#    GNU General Public License for more details. +DAEMON="/usr/local/bin/${NAME}" -#    You should have received a copy of the GNU General Public License -#    along with this program.  If not, see . -# ------------------------------------------------------------------------- +EXEC_AS_USER="root" +START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --chuid ${EXEC_AS_USER} --exec ${DAEMON}" +STOP_OPTS="--stop --pidfile ${PIDFILE}" -MESSAGEDIR=/var/log/eddn -MESSAGELOG=/var/log/eddn/relay.log -PID=/var/run/eddn-relay.pid -EXECUTABLE=/usr/local/bin/eddn-relay -CMDLINE="" +test -x $DAEMON || exit 0 - -# Check the script is being run by root user -if [ "$(id -u)" != "0" ]; then -  echo 1>&2 "ERROR: The $0 script must be run as root" -  exit 1 -fi - -# Create the PID File -touch $PID +set -e case "$1" in - start) - # create the log directory if not exist - [ ! -d "$MESSAGEDIR" ] && mkdir -p "$MESSAGEDIR" - - echo "Starting $EXECUTABLE" - # test if not already running - if [ ! -f "/proc/$(cat $PID)/exe" ]; then - $EXECUTABLE "$CMDLINE" > "$MESSAGELOG" 2>&1 & - echo $!>"$PID" - else - echo "$EXECUTABLE already running" - fi - ;; - stop) - echo "Stopping $EXECUTABLE" - # test if running - if [ -f "/proc/$(cat $PID)/exe" ]; then - kill -9 "$(cat $PID)" - rm -rf "$PID" - else - echo "$EXECUTABLE already stopped" - fi +start) + echo -n "Starting ${DESC}: " + start-stop-daemon $START_OPTS >> $LOGFILE + echo "$NAME." ;; - restart) - $0 stop - $0 start +stop) + echo -n "Stopping $DESC: " + start-stop-daemon $STOP_OPTS + echo "$NAME." + rm -f $PIDFILE + ;; +restart|force-reload) + echo -n "Restarting $DESC: " + start-stop-daemon $STOP_OPTS + sleep 1 + start-stop-daemon $START_OPTS >> $LOGFILE + echo "$NAME." + ;; +*) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|restart|force-reload}" >&2 + exit 1 ;; - *) - echo "usage: $0 {start|stop|restart}" esac -exit 0 + +exit 0 \ No newline at end of file