Technology news and Jobs arrow Information Technology News arrow Write your own Linux server part two
Write your own Linux server part two E-mail
by David M Williams   
Tuesday, 21 August 2007
99dwsvr

#!/bin/sh
#
# dwsvr  Bring up/down the dwserv process
#
# by David M. Williams

# -----------------------------------------------------------------------------
# Configurable options ...
# Comment out any of the following lines to use dwserv's default values.
# -----------------------------------------------------------------------------

DWSERV_DIR=.

# Edit the following to change the port number that dwserv
# runs at. Any client program must specify this port number to connect.
PORT=4000

# Edit the following to increase or decrease the connection queue. This
# probably need not be touched unless dwserv is expected to
# receive many simultaneous connections.
QLEN=5

# Turn on or off logging - use 'on' or 'off'
LOG=on

# Edit the following to specify where the logfile is to be stored - this
# will only take effect if logging is switched on (above).
LOGFILE=/tmp/dwsvr.log

# Edit the following to specify if verbose logging should be performed.
# This will create a larger log file but will give much more information
# about what is happening - use 'yes' or 'no'
VERBOSE=yes

# -----------------------------------------------------------------------------
# Nothing below here needs modification
# -----------------------------------------------------------------------------

getPID_Linux ()
{
 PID=`ps -e | grep dwserv | grep -v grep | cut -c1-5`
}

getPID_SunOS ()
{
 PID=`ps -ejf | grep dwserv | grep -v grep | cut -c10-14`
}

getPID=getPID_`uname`
$getPID

case "$1" in
 stop)
  if [ "a$PID" = "a" ];
  then
   echo "dwserv is not running"
   exit 1
  fi

  kill -9 $PID > /dev/null 2>&1
  sleep 1

  $getPID
  if [ "a$PID" = "a" ];
  then
   echo "dwserv stopped"
  else
   echo "dwserv could not be stopped"
  fi
  ;;

 start)
  if [ "a$PID" != "a" ];
  then
   echo "dwserv is already running"
   exit 1
  fi

  COMMANDLINE=

  if [ "a$PORT" != "a" ];
  then
   COMMANDLINE="$COMMANDLINE -p$PORT"
  fi

  if [ "a$QLEN" != "a" ];
  then
   COMMANDLINE="$COMMANDLINE -q$QLEN"
  fi

  if [ "$LOG" = "on" ];
  then
   COMMANDLINE="$COMMANDLINE -l"

   if [ "$VERBOSE" = "yes" ];
   then
    COMMANDLINE="$COMMANDLINE -v"
   fi

   if [ "a$LOGFILE" != "a" ];
   then
    COMMANDLINE="$COMMANDLINE -f$LOGFILE"
   fi
  fi

  $DWSERV_DIR/dwserv $COMMANDLINE > /dev/null 2>&1

  $getPID
  if [ "a$PID" = "a" ];
  then
   echo "dwserv could not be started"
  else
   echo "dwserv running"
  fi
  ;;

 *)
  echo "Usage: dwserv {start|stop}"
  if [ "a$PID" != "a" ];
  then
   echo "dwserv is running"
  else
   echo "dwserv is not running"
  fi
  exit 1
esac

Powered By Joomla Tags

Please enable JavaScript in your browser to post your comment!



 
< Next story in category   Previous story in the category >
iTWire user statistics Visitors last 30 days
694,279
Subscribers 15,210
#1 independent technology news advertise here
  •   *  
  • Search
  • AdvSeach
  • Login
  • Events
  • FreeStuff

- Advertisement -

Featured Whitepapers

Follow iTWire on Twitter

About iTWire

iTWire is all about technology news, information, jobs and community for the IT and telecommunications industry professional. Subscribe to our free ICT daily newsletter