diff --git a/contrib/eddn-gateway b/contrib/eddn-gateway new file mode 100644 index 0000000..4706942 --- /dev/null +++ b/contrib/eddn-gateway @@ -0,0 +1,77 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: eddn-gateway +# Required-Start: $network +# Required-Stop: +# Default-Start: 2 3 4 5 +# 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. + +#    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. + +#    You should have received a copy of the GNU General Public License +#    along with this program.  If not, see . +# ------------------------------------------------------------------------- + + +MESSAGEDIR=/var/log/eddn-gateway +MESSAGELOG=/var/log/eddn-gateway/gateway.log +PID=/var/run/eddn-gateway.pid +EXECUTABLE=/path/to/eddn-gateway +CMDLINE="" + + +# 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 + start) + # create the log directory if not exist + [ ! -d "$MESSAGEDIR" ] && mkdir -p "$MESSAGEDIR" + + echo "Starting EDDN gateway" + # test if not already running + if [ ! -f "/proc/$(cat $PID)/exe" ]; then + $EXECUTABLE "$CMDLINE" > "$MESSAGELOG" 2>&1 & + echo $!>"$PID" + else + echo "EDDN gateway already running" + fi + ;; + stop) + echo "Stopping EDDN gateway" + # test if running + if [ -f "/proc/$(cat $PID)/exe" ]; then + kill -9 "$(cat $PID)" + rm -rf "$PID" + else + echo "EDDN gateway already stopped" + fi + ;; + restart) + $0 stop + $0 start + ;; + *) + echo "usage: $0 {start|stop|restart}" +esac +exit 0