StartStopStatusScript

From MLDonkey
Jump to: navigation, search

Contents

general

here is a small script that can be used by bsd/linux/*nix boxes to start/stop mlnet.
the stop stdout output is not quite clean, but it functions.

requirements

  1. . the http interface must be enabled for localhost.
  2. . gnu wget
  3. . striphtml.sed script (see below)

mlnet.sh

#!/bin/bash

MLNET_DIR="/srv/mlnet/bin"
# MLNET_LOG="/dev/null"
MLNET_LOG="/var/log/mlnet.log"
MLNET_COMMAND="$MLNET_DIR/mlnet > $MLNET_LOG 2>&1 &"
# STRIP_SCRIPT="$MLNET_DIR/scripts/striphtml.sed"
HTTP_PORT="4080"

echo  -n ' mlnet '

case "$1" in
start)
        echo start
#        cd $MLNET_DIR
        $MLNET_COMMAND
        ;;
stop)
        echo stop
        wget -q --spider --http-user=admin --http-password='!n@\033[m' \
                   "http://localhost:$HTTP_PORT/submit?q=kill"
        RETVAL=$?
        ;;
status)
        wget -q --spider --http-user=admin --http-password='!n@\033[m' \
                   "http://localhost:$HTTP_PORT/submit?q=bw_stats"
        RETVAL=$?
        case "$RETVAL" in
           "0")
              echo "mldonkey is runing"
              ;;
           "1")
              echo "mldonkey is stopped"
        esac
        ;;
*)
        echo "Usage: `basename $0` {start|stop|status}" >&2
        exit 64
        ;;
esac

exit $RETVAL

striphtml.sed

#!/bin/sed -nf
#< strip HTML tags from input and remove blank lines
# from http://www.zazzybob.com/bin.html
# under GNU license

: loop
/<.*>/ {
         #if we have a HTML tag, remove it
         s/<~[[^<>]]*>//g

         #branch if a successful substitution was made
         t loop
}
/</ {
         #if just an opening tag is found, append the
         #next line of input into the pattern space
         N
         b loop
}

# remove blank lines
/^[[     ]]*$/d

# print the rest!
p

alternative way to get status

You either can grab status without the external sed script and without wget:

status)

       echo -e \"auth $password\nbw_stats\nquit\" || nc -w 1 127.0.0.1 4000 ||grep ^D
       ;;
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox