blob: fdb63040d1abb21881691391514ed34f8af16eeb (
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#! /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
addr=$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_telnetd ()
{
if [ -n "$addr" ]
then $bb telnetd -p $port -b $addr
else $bb telnetd -p $port
fi
}
start ()
{
local -i pid=$( running_pid )
[ $pid -ne 0 ] && return
start_telnetd
}
stop ()
{
local -i pid=$( running_pid )
if [ $pid -ne 0 ]
then kill $pid
else return 0
fi
}
restart()
{
local -i pid=$( running_pid )
if [ $pid -ne 0 ]
then kill $pid
sleep 1
fi
start_telnetd
}
status ()
{
local -i pid=$( running_pid )
if [ $pid -ne 0 ]
then echo running
return
else
echo not running
false
fi
}
case "$action" in
start) start;;
stop) stop;;
restart) restart;;
status) status;;
*) echo "Usage: $progname {start|stop|restart|status}"
exit 1
esac
|