1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#! /bin/bash
#
# ser2net init script for ser2net
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian GNU/Linux
# by Ian Murdock <imurdock@gnu.ai.mit.edu>.
# Modified for ser2net by Marc Haber <mh+debian-packages@zugschlus.de>
### BEGIN INIT INFO
# Provides: ser2net
# Required-Start: $network $remote_fs
# Required-Stop: $network $remote_fs
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Allows network connections to serial ports
# Description: This daemon allows telnet and tcp sessions to be established with a unit's serial ports.
### END INIT INFO
set -e
if [ -r "/lib/lsb/init-functions" ]; then
. /lib/lsb/init-functions
else
echo "E: /lib/lsb/init-functions not found, lsb-base (>= 3.0-6) needed"
exit 1
fi
if [ -n "$SER2NETDEBUG" ]; then
echo "now debugging $0 $@"
set -x
fi
LANG=C
export LANG
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/ser2net
NAME=ser2net
DESC="Serial port to network proxy"
PIDFILE=/run/$NAME.pid
test -f $DAEMON || exit 0
# Defaults
CONFFILE="/etc/ser2net.yaml"
OPTIONS=""
CONTROLPORT=""
# Read config file (will override defaults above)
[ -r /etc/default/ser2net ] && . /etc/default/ser2net
# this is from madduck on IRC, 2006-07-06
# There should be a better possibility to give daemon error messages
# and/or to log things
log()
{
case "$1" in
[[:digit:]]*) success=$1; shift;;
*) :;;
esac
log_action_begin_msg "$1"; shift
log_action_end_msg ${success:-0} "$*"
}
start () {
if ! pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null; then
start_daemon -p $PIDFILE $DAEMON ${CONTROLPORT:+-p} $CONTROLPORT -c $CONFFILE -P $PIDFILE $OPTIONS
ret=$?
else
log_failure_msg "already running!"
log_end_msg 1
exit 1
fi
return $ret
}
stop () {
# this is a workaround for #451529 as ser2net 2.5 does not delete its pidfile
SIG="${1:--TERM}"
killproc -p "$PIDFILE" "$DAEMON" "$SIG"
# this is a workaround for killproc -TERM not zapping the pidfile
if ! pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null; then
rm -f $PIDFILE
fi
}
status()
{
log_action_begin_msg "checking $DESC"
if pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null; then
log_action_end_msg 0 "$NAME running"
else
if [ -e "$PIDFILE" ]; then
log_action_end_msg 1 "$NAME failed"
exit 1
else
log_action_end_msg 0 "$NAME not running"
exit 3
fi
fi
}
if ! [ -e "$CONFFILE" ]; then
log_failure_msg "Not starting ser2net: Conffile $CONFFILE missing"
log_end_msg 1
exit 1
fi
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
start
log_end_msg 0
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
stop
log_end_msg 0
;;
reload|force-reload)
log_daemon_msg "Reloading $DESC" "$NAME"
stop "-HUP"
log_end_msg 0
;;
restart)
log_daemon_msg "Restarting $DESC" "$NAME"
stop
sleep 1
start
log_end_msg 0
;;
status)
status
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
exit 1
;;
esac
exit 0
|