#!/bin/sh
#
# sstop - start specified service
#

usage(){
  echo "Usage: sstop [SERVICE]..."
  echo "Stop the service specificed as argument, if the service"
  echo "has a service-file installed in /etc/rc.d/services/."
  echo
  echo "  -h, --help		print this help and exit"
  echo "  -v, --version		output version information and exit"
  echo
  echo "Report bugs to <johne@rootlinux.org>"
  exit 1
}

displayversion(){
  echo "sstop (rltools) #VERSION#"
  exit 0
}

if [ "$1" = "-h" -o "$1" = "--help" ]; then
  usage
fi

if [ "$1" = "-v" -o "$1" = "--version" ]; then
  displayversion
fi

if [ -z $1 ]; then
  echo "sstop: error: missing option"
  echo "Try 'sstop --help' for more information."
  exit 1
fi


if [ -f /etc/rc.d/services/$1.service ]; then
    if [ -f /tmp/$1.startlog ]; then
	rm -f /tmp/$1.startlog
    fi
    /etc/rc.d/services/$1.service stop >/tmp/$1.stoplog
    if [ "`file -b /tmp/$1.stoplog`"="empty" ]; then
        rm -f /tmp/$1.stoplog
    fi
    exit 0
  else
    echo "sstop: $1: no such service."
    exit 1
fi
