#! /bin/bash
#
# samba4       Bring up/down samba4 service 
#
# chkconfig: - 90 10
# description: Activates/Deactivates all samba4 interfaces configured to \
#              start at boot time.
#
### BEGIN INIT INFO
# Provides: 
# Should-Start: 
# Short-Description: Bring up/down samba4
# Description: Bring up/down samba4
### END INIT INFO
# Source function library.
. /etc/init.d/functions

if [ -f /etc/sysconfig/samba4 ]; then
 . /etc/sysconfig/samba4
fi

return_val=0
prog_name="samba"
prog_cmd=/usr/sbin/samba   #i.e. "/usr/sbin/samba"
pid_file=/var/run/samba/samba.pid  #i.e. "/var/run/samba.pid"

start() {
  message=$(status -p $pid_file $prog_name)
  return_val=$?
  [ $return_val = 3 ] || { echo $message 1>&2; return $return_val; }
  echo -n $"Starting $prog_name: "
  $prog_cmd
  sleep 2
  if [ $(ps ax | grep -v "grep" | grep -q $prog_cmd; echo $?) = 0 -a -f $pid_file ]; then
    success $"samba4 startup"
    echo
    return 0
  else
    failure $"samba4 startup"
    echo
    rm $pid_file
    return 2
  fi
}

stop() {
  # Stop service.
  message=$(status -p $pid_file $prog_name)
  return_val=$?
  [ $return_val = 0 ] || { echo $message 1>&2; return $return_val; }
  echo -n $"Shutting down $prog_name: "
  killproc /usr/sbin/samba
  sleep 2
  if [ $(ps ax | grep -v "grep" | grep -q $prog_cmd; echo $?) = 0 ]; then
    failure $"samba4 shutdown"
    echo
    return 2
  else
    rm -f $pid_file 2>/dev/null
    success $"samba4 shutdown"
    echo
    return 0
  fi
}

# See how we were called.
case "$1" in
start)
  start
  return_val=$?
  ;;
stop)
  stop
  return_val=$?
  ;;
status)
  status -p $pid_file $prog_name
  return_val=$?
  ;;
restart|reload)
  stop
  start
  return_val=$?
  ;;
*)
  echo $"Usage: $0 {start|stop|restart|status}"
  return_val=3
esac

exit $return_val
