summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2007-10-31 14:51:16 -0700
committerAn-Cheng Huang <ancheng@vyatta.com>2007-10-31 14:51:16 -0700
commitf0920480f03cd60681061a6bbb19fc70beb235dd (patch)
treef4010edfb01b0ef33ab00d1967edda5a7eb6f039 /scripts
parent290a17f504293f80b54bb8960293e6bc0cfacb19 (diff)
downloadvyatta-cfg-system-f0920480f03cd60681061a6bbb19fc70beb235dd.tar.gz
vyatta-cfg-system-f0920480f03cd60681061a6bbb19fc70beb235dd.zip
import telnetd init from old eureka/rl-system
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/telnetd.init74
1 files changed, 74 insertions, 0 deletions
diff --git a/scripts/telnetd.init b/scripts/telnetd.init
new file mode 100755
index 00000000..7afefb3d
--- /dev/null
+++ b/scripts/telnetd.init
@@ -0,0 +1,74 @@
+#! /bin/bash
+
+declare progname=${0##*/}
+declare action=$1; shift
+
+if [ x$BOOTFILE != x ] && [ -r $BOOTFILE ]; then
+ may_start=false
+ eval $(sed -n '
+/^service {$/,/^}$/ {
+ / *telnet {$/,/ *}$/ {
+ s/ *telnet {/may_start=true/p
+ s/ *port: /port=/p
+}}' $BOOTFILE)
+else
+ may_start=true
+fi
+
+if [ $# -ne 0 ] ; then
+ port=$1; shift
+fi
+
+: ${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
+ $may_start || return 0
+ $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