Make init.d scripts working with Debian

This commit is contained in:
AnthorNet 2017-06-29 12:20:39 +02:00
parent 5e841fb9c8
commit 8bffbe91fa
3 changed files with 99 additions and 171 deletions

View File

@ -8,70 +8,46 @@
# Default-Stop: 0 1 6 # Default-Stop: 0 1 6
### END INIT INFO ### END INIT INFO
# ------------------------------------------------------------------------- NAME=eddn-gateway
#    Based on: <Pyro4 NameServer Script> DESC="eddn-gateway"
#    Copyright (C) <2011>  <Pierre PACORY> - ppacory-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org PIDFILE="/var/run/${NAME}.pid"
# Modified by James Muscat LOGFILE="/var/log/eddn/${NAME}.log"
#    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.
#    This program is distributed in the hope that it will be useful, DAEMON="/usr/local/bin/${NAME}"
#    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.
#    You should have received a copy of the GNU General Public License EXEC_AS_USER="root"
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
# -------------------------------------------------------------------------
START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --chuid ${EXEC_AS_USER} --exec ${DAEMON}"
STOP_OPTS="--stop --pidfile ${PIDFILE}"
MESSAGEDIR=/var/log/eddn test -x $DAEMON || exit 0
MESSAGELOG=/var/log/eddn/gateway.log
PID=/var/run/eddn-gateway.pid
EXECUTABLE=/usr/local/bin/eddn-gateway
CMDLINE=""
set -e
# 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
case "$1" in case "$1" in
start) start)
# create the log directory if not exist echo -n "Starting ${DESC}: "
[ ! -d "$MESSAGEDIR" ] && mkdir -p "$MESSAGEDIR" start-stop-daemon $START_OPTS >> $LOGFILE
echo "$NAME."
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) stop)
echo "Stopping $EXECUTABLE" echo -n "Stopping $DESC: "
# test if running start-stop-daemon $STOP_OPTS
if [ -f "/proc/$(cat $PID)/exe" ]; then echo "$NAME."
kill -9 "$(cat $PID)" rm -f $PIDFILE
rm -rf "$PID"
else
echo "$EXECUTABLE already stopped"
fi
;; ;;
restart) restart|force-reload)
$0 stop echo -n "Restarting $DESC: "
$0 start start-stop-daemon $STOP_OPTS
sleep 1
start-stop-daemon $START_OPTS >> $LOGFILE
echo "$NAME."
;; ;;
*) *)
echo "usage: $0 {start|stop|restart}" N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac esac
exit 0 exit 0

View File

@ -8,70 +8,46 @@
# Default-Stop: 0 1 6 # Default-Stop: 0 1 6
### END INIT INFO ### END INIT INFO
# ------------------------------------------------------------------------- NAME=eddn-monitor
#    Based on: <Pyro4 NameServer Script> DESC="eddn-monitor"
#    Copyright (C) <2011>  <Pierre PACORY> - ppacory-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org PIDFILE="/var/run/${NAME}.pid"
# Modified by James Muscat LOGFILE="/var/log/eddn/${NAME}.log"
#    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.
#    This program is distributed in the hope that it will be useful, DAEMON="/usr/local/bin/${NAME}"
#    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.
#    You should have received a copy of the GNU General Public License EXEC_AS_USER="root"
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
# -------------------------------------------------------------------------
START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --chuid ${EXEC_AS_USER} --exec ${DAEMON}"
STOP_OPTS="--stop --pidfile ${PIDFILE}"
MESSAGEDIR=/var/log/eddn test -x $DAEMON || exit 0
MESSAGELOG=/var/log/eddn/monitor.log
PID=/var/run/eddn-monitor.pid
EXECUTABLE=/usr/local/bin/eddn-monitor
CMDLINE=""
set -e
# 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
case "$1" in case "$1" in
start) start)
# create the log directory if not exist echo -n "Starting ${DESC}: "
[ ! -d "$MESSAGEDIR" ] && mkdir -p "$MESSAGEDIR" start-stop-daemon $START_OPTS >> $LOGFILE
echo "$NAME."
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) stop)
echo "Stopping $EXECUTABLE" echo -n "Stopping $DESC: "
# test if running start-stop-daemon $STOP_OPTS
if [ -f "/proc/$(cat $PID)/exe" ]; then echo "$NAME."
kill -9 "$(cat $PID)" rm -f $PIDFILE
rm -rf "$PID"
else
echo "$EXECUTABLE already stopped"
fi
;; ;;
restart) restart|force-reload)
$0 stop echo -n "Restarting $DESC: "
$0 start start-stop-daemon $STOP_OPTS
sleep 1
start-stop-daemon $START_OPTS >> $LOGFILE
echo "$NAME."
;; ;;
*) *)
echo "usage: $0 {start|stop|restart}" N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac esac
exit 0 exit 0

View File

@ -8,70 +8,46 @@
# Default-Stop: 0 1 6 # Default-Stop: 0 1 6
### END INIT INFO ### END INIT INFO
# ------------------------------------------------------------------------- NAME=eddn-relay
#    Based on: <Pyro4 NameServer Script> DESC="eddn-relay"
#    Copyright (C) <2011>  <Pierre PACORY> - ppacory-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org PIDFILE="/var/run/${NAME}.pid"
# Modified by James Muscat LOGFILE="/var/log/eddn/${NAME}.log"
#    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.
#    This program is distributed in the hope that it will be useful, DAEMON="/usr/local/bin/${NAME}"
#    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.
#    You should have received a copy of the GNU General Public License EXEC_AS_USER="root"
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
# -------------------------------------------------------------------------
START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --chuid ${EXEC_AS_USER} --exec ${DAEMON}"
STOP_OPTS="--stop --pidfile ${PIDFILE}"
MESSAGEDIR=/var/log/eddn test -x $DAEMON || exit 0
MESSAGELOG=/var/log/eddn/relay.log
PID=/var/run/eddn-relay.pid
EXECUTABLE=/usr/local/bin/eddn-relay
CMDLINE=""
set -e
# 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
case "$1" in case "$1" in
start) start)
# create the log directory if not exist echo -n "Starting ${DESC}: "
[ ! -d "$MESSAGEDIR" ] && mkdir -p "$MESSAGEDIR" start-stop-daemon $START_OPTS >> $LOGFILE
echo "$NAME."
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) stop)
echo "Stopping $EXECUTABLE" echo -n "Stopping $DESC: "
# test if running start-stop-daemon $STOP_OPTS
if [ -f "/proc/$(cat $PID)/exe" ]; then echo "$NAME."
kill -9 "$(cat $PID)" rm -f $PIDFILE
rm -rf "$PID"
else
echo "$EXECUTABLE already stopped"
fi
;; ;;
restart) restart|force-reload)
$0 stop echo -n "Restarting $DESC: "
$0 start start-stop-daemon $STOP_OPTS
sleep 1
start-stop-daemon $START_OPTS >> $LOGFILE
echo "$NAME."
;; ;;
*) *)
echo "usage: $0 {start|stop|restart}" N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac esac
exit 0 exit 0