aboutsummaryrefslogtreecommitdiff
path: root/rc
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2020-02-17 14:04:32 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2020-02-17 14:04:32 +0200
commit0dfd07ad3ef44ebc5a1b5118ce66f668768d14a6 (patch)
tree513769850833207642a0e77df756736f7c9a7c73 /rc
parent0af947c35520bea53c43b79cbbcd1f4a44b65952 (diff)
downloadping903-0dfd07ad3ef44ebc5a1b5118ce66f668768d14a6.tar.gz
ping903-0dfd07ad3ef44ebc5a1b5118ce66f668768d14a6.tar.bz2
Add distribution-specific startup files.
Diffstat (limited to 'rc')
-rw-r--r--rc/README73
-rw-r--r--rc/debian.rc133
-rw-r--r--rc/genrc.rc7
-rw-r--r--rc/ping903.service13
-rw-r--r--rc/slackware.rc80
5 files changed, 306 insertions, 0 deletions
diff --git a/rc/README b/rc/README
new file mode 100644
index 0000000..40e716e
--- /dev/null
+++ b/rc/README
@@ -0,0 +1,73 @@
+* Overview
+This directory contains distribution-specific startup scripts for
+Ping903. All scripts assume the daemon binary is installed at
+/usr/sbin/ping903. If it's not the case, change the value of the
+COMMAND variable, located at the start of the script.
+
+* debian.rc
+The start script for Debian-based systems without systemd. Use it on
+Debian 7, Ubuntu up to 16.04, etc.
+
+1. Copy the script and make it executable:
+
+ cp debian.rc /etc/init.d/ping903
+ chmod +x /etc/init.d/ping903
+
+2. Register it in the startup and shutdown sequences:
+
+ update-rc.d ping903 defaults
+
+Optionally, you may create the file /etc/default/903, which can
+define two shell variables:
+
+ START
+ Whether or not to start the service. Set it to "no", to
+ disable the service. Set it to "yes" (or simply remove it)
+ to enable the service.
+ DAEMON_OPTS
+ Additional options to be passed to the server.
+
+* ping903.service
+Service definition for systems with systemd. Usage:
+
+1. Copy
+ cp ping903.service /etc/systemd/system/
+
+2. Enable it
+ systemctl enable ping903
+
+3. Reload the daemon
+ systemctl daemon-reload
+
+4. Start the service
+ systemctl start ping903
+
+* slackware.rc
+Slackware rc script. In fact, it is the most general of all and it
+will work an all systems with no (or at a pinch, little) changes.
+Usage:
+
+1. Copy it to where startup scripts live and make it executable.
+ cp slackware.rc /etc/rc.d/rc.pound903
+ chmod +x /etc/rc.d/rc.pound903
+
+2. Add the following line to your /etc/rc.d/rc.local:
+ /etc/rc.d/rc.pound903 start
+
+* genrc.rc
+Startup script for installations using genrc
+(https://puszcza.gnu.org.ua/projects/genrc). This is mostly for
+Slackware, but can actually be used on any system. The usage on
+Slackware is the same as described for slackware.rc.
+
+
+Local Variables:
+mode: outline
+paragraph-separate: "[ ]*$"
+version-control: never
+End:
+
+
+
+
+
diff --git a/rc/debian.rc b/rc/debian.rc
new file mode 100644
index 0000000..ed5e7a4
--- /dev/null
+++ b/rc/debian.rc
@@ -0,0 +1,133 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides: ping903
+# Required-Start: $local_fs $network $remote_fs $syslog
+# Required-Stop: $local_fs $network $remote_fs $syslog
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: ICMP Monitoring Server
+# Description: High-performance ICMP monitoring server
+### END INIT INFO
+
+# Author: Sergey Poznyakoff <gray@gnu.org>
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="ping903"
+NAME=ping903
+DAEMON=/usr/sbin/ping903
+DAEMON_OPTS=""
+CONFIG=/etc/ping903.conf
+SCRIPTNAME=/etc/init.d/$NAME
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Read configuration variable file if it is present
+# The file is supposed to define at most two variables:
+# START
+# The only recongized value is "no", which disables
+# the service. Any other value (or undefined) means to
+# start the service.
+# DAEMON_OPTS
+# Command line to be passed to the server. Not needed, really.
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+[ "START" = no ] && exit 0
+
+[ ! -f $CONFIG ] && exit 0
+
+PIDFILE=$(sed -r -n 's/^[[:space:]]*pidfile[[:space:]]+//p' $CONFIG)
+if [ -n "$PIDFILE" ]; then
+ PIDFILE_OPT="--pidfile $PIDFILE"
+fi
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
+# and status_of_proc is working.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start() {
+ # Return
+ # 0 if daemon has been started
+ # 1 if daemon was already running
+ # 2 if daemon could not be started
+ start-stop-daemon --start --quiet $PIDFILE_OPT \
+ --exec $DAEMON --test > /dev/null \
+ || return 1
+ start-stop-daemon --start --quiet $PIDFILE_OPT \
+ --exec $DAEMON -- $DAEMON_OPTS \
+ || return 2
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop() {
+ # Return
+ # 0 if daemon has been stopped
+ # 1 if daemon was already stopped
+ # 2 if daemon could not be stopped
+ # other if a failure occurred
+ start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
+ $PIDFILE_OPT --name $NAME
+ RETVAL="$?"
+ [ "$RETVAL" = 2 ] && return 2
+ rm -f $PIDFILE
+ return "$RETVAL"
+}
+
+case "$1" in
+ start)
+ [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+ do_start
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ stop)
+ [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+ esac
+ ;;
+ status)
+ status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
+ ;;
+ restart|force-reload)
+ #
+ # If the "reload" option is implemented then remove the
+ # 'force-reload' alias
+ #
+ log_daemon_msg "Restarting $DESC" "$NAME"
+ do_stop
+ case "$?" in
+ 0|1)
+ do_start
+ case "$?" in
+ 0) log_end_msg 0 ;;
+ 1) log_end_msg 1 ;; # Old process is still running
+ *) log_end_msg 1 ;; # Failed to start
+ esac
+ ;;
+ *)
+ # Failed to stop
+ log_end_msg 1
+ ;;
+ esac
+ ;;
+ *)
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
+ exit 3
+ ;;
+esac
+
+:
diff --git a/rc/genrc.rc b/rc/genrc.rc
new file mode 100644
index 0000000..d382cb7
--- /dev/null
+++ b/rc/genrc.rc
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+export GENRC_COMMAND=/usr/sbin/ping903
+export GENRC_PID_FROM=PROC:ping903
+exec /sbin/genrc "$@"
+
+
diff --git a/rc/ping903.service b/rc/ping903.service
new file mode 100644
index 0000000..0d2cd6a
--- /dev/null
+++ b/rc/ping903.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=Ping903 Monitoring Server
+Documentation=man:ping903(8)
+After=network-online.target
+
+[Service]
+Type=forking
+ExecStart=/usr/sbin/ping903
+PIDFile=/var/run/ping903.pid
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
diff --git a/rc/slackware.rc b/rc/slackware.rc
new file mode 100644
index 0000000..d006b9d
--- /dev/null
+++ b/rc/slackware.rc
@@ -0,0 +1,80 @@
+#!/bin/sh
+
+PROGNAME=ping903
+COMMAND=/usr/sbin/ping903
+OPTIONS=
+CONFIG=/etc/ping903.conf
+
+if [ ! -f $CONFIG ]; then
+ exit
+fi
+
+PIDFILE=$(sed -r -n 's/^[[:space:]]*pidfile[[:space:]]+//p' $CONFIG)
+
+ping903_start() {
+ $COMMAND $OPTIONS
+}
+
+ping903_stop() {
+ if [ -n "$PIDFILE" ]; then
+ if [ -f "$PIDFILE" ]; then
+ pid=$(head -1 $PIDFILE)
+ prog=$(ps -p $pid -ocomm=)
+ if [ $prog = $PROGNAME ]; then
+ kill -TERM $pid
+ return
+ fi
+ else
+ return
+ fi
+ fi
+
+ killall $PROGNAME
+}
+
+ping903_restart() {
+ ping903_stop
+ sleep 1
+ ping903_start
+}
+
+ping903_status() {
+ if [ -n "$PIDFILE" ]; then
+ if [ -f "$PIDFILE" ]; then
+ pid=$(head -1 $PIDFILE)
+ prog=$(ps -p $pid -ocomm=)
+ if [ $prog = $PROGNAME ]; then
+ echo "$PROGNAME is running (PID $pid)"
+ else
+ echo "$PROGNAME is not running (pidfile is stale)"
+ fi
+ else
+ echo "$PROGNAME is not running"
+ fi
+ else
+ pid=$(/sbin/pidof $PROGNAME | cut -d ' ' -f 1)
+ if [ -n "$pid" ]; then
+ echo "$PROGNAME is running (PID $pid)"
+ else
+ echo "$PROGNAME is not running"
+ fi
+ fi
+}
+
+case "$1" in
+ 'start')
+ ping903_start
+ ;;
+ 'stop')
+ ping903_stop
+ ;;
+ 'restart')
+ ping903_restart
+ ;;
+ 'status')
+ ping903_status
+ ;;
+ *)
+ echo "usage $0 start|stop|restart|status"
+esac
+

Return to:

Send suggestions and report system problems to the System administrator.