blob: 81dc2f76888d5d86a10cce9cc06a6e5d9bc3bc98 (
plain)
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
|
#! /bin/bash
### BEGIN INIT INFO
# Provides: telnetd
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start:
# Default-Stop:
# Short-Description: Busybox telnet daemon
### END INIT INFO
declare progname=${0##*/}
declare action=$1; shift
port=$1; shift
: ${port:=23}
: ${bb:=/bin/busybox}
test -x $bb || exit 0
running_pid ()
{
pidof $bb | while read pid ; do
f=$(tr '\000' '\t' < /proc/$pid/cmdline 2>/dev/null | cut -f2)
if [ "$f" == telnetd ] ; then
echo $pid
return
fi
done
false
}
start ()
{
local -i pid=$( running_pid )
[ $pid -ne 0 ] && return
$bb telnetd -p $port
}
stop ()
{
local -i pid=$( running_pid )
[ $pid -ne 0 ] && kill $pid
}
status ()
{
pidof $bb | while read pid ; do
f=$(tr '\000' '\t' < /proc/$pid/cmdline | cut -f2)
if [ $f == telnetd ] ; then
echo running
return
fi
done
echo not running
false
}
case "$action" in
start) start;;
stop) stop;;
restart) stop; sleep 1; start;;
status) status;;
*) echo "Usage: $progname {start|stop|restart|status}"
exit 1
esac
|