#!/bin/bash ### BEGIN INIT INFO # Provides: noip2 # Required-Start: # Required-Stop: # Should-Start: $network $syslog # Should-Stop: $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start and stop noip2 # Description: noip2 manages dyn dns ### END INIT INFO . /lib/lsb/init-functions set -euf -o pipefail NOIP_BIN='/usr/local/bin/noip2' NOIP_NAME='noip2' NOIP_OPTIONS="${NOIP_OPTIONS:-}" function do_start() { local rc=0 log_daemon_msg 'Starting dynamic DNS client...' "${NOIP_BIN}" ${NOIP_OPTIONS} || rc=$? log_end_msg "${rc}" return ${rc} } function do_stop() { local rc=0 local pid="$(get_pid)" if [ -z "${pid}" ]; then log_warning_msg "${NOIP_NAME} not running" return fi log_daemon_msg 'Stopping dynamic DNS client...' "${NOIP_BIN}" -K "${pid}" \ && waiting_for_stop "${pid}" \ || rc=$? log_end_msg "${rc}" return ${rc} } function get_pid() { "${NOIP_BIN}" -S 2>&1 \ | grep '^Process' \ | sed -E 's>^Process ([0-9]+),.+$>\1>' \ || true } function waiting_for_stop() { local pid="$1" local waiting_cycles=10 while kill -0 ${pid} 2>/dev/null; do waiting_cycles="$[${waiting_cycles} - 1]" if [ "${waiting_cycles}" -lt 1 ]; then log_failure_msg "failed to stop ${NOIP_NAME} daemon" return 1 fi sleep 0.5 done } case "$1" in start) do_start ;; stop) do_stop ;; restart) do_stop do_start ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 esac exit 0