>> On Wed, 8 Apr 2009 13:21:17 -0500, 
>> "Gary Gatten" <ggat...@waddell.com> said:

G> I've been playing with various flavors of *nix off and on for almost twenty
G> years, but not doing much development the make process often causes me
G> issues - as is the case with samba.

   This is why I only use the ports system for small, simple builds like
   rsync.  For anything major (Perl, OpenSSH, OpenSSL, Apache ...) I either
   use a pre-built package or build directly from source.  I used these
   commands for my most recent Samba build:

   me% CC=gcc ./configure --with-acl-support \
      --with-configdir=/usr/local/etc \
      --prefix=/usr/local
   me% make
   root# make install

   I use a (fairly generic) script to handle starting and stopping Samba
   cleanly.  It also handles log rotation.  It's attached below, if you're
   interested.  The "killpg" program used is derived from kill, but sends its
   signals to a process group instead of a process.

-- 
Karl Vogel                      I don't speak for the USAF or my company

You know you're a redneck if you've ever been involved in a custody
fight over a hunting dog.

---------------------------------------------------------------------------
#!/bin/sh
#
# $Id: samba.server,v 1.1 2004/05/13 23:32:35 vogelke Exp $
# $Source: /doc/sitelog/fs001/services/RCS/samba.server,v $
#
# NAME:
#    samba.server
#
# SYNOPSIS:
#    samba.server [start|stop|stat|restart|dologs|help]
#    samba.server -v
#
# DESCRIPTION:
#    Script file to start and stop Samba services.
#    "-v" means print the version and exit.
#
#    Non-option argument is one of the following:
#      start -- starts Samba service
#       stop -- stops Samba service
#       stat -- displays status of Samba service
#    restart -- stops and restarts Samba
#     dologs -- stops Samba, moves log directory, restarts Samba
#       help -- this message
#
# INSTALLATION:
#    Put this in at least two places: where the system looks for
#    startup/shutdown files, and someplace where root can run it.
#
# AUTHOR:
#    Karl Vogel <vogelke+u...@pobox.com>
#    Oasis Systems, Inc.
#    Based on "Life with qmail" script.

PATH=/usr/local/sbin:/usr/local/bin:/bin:/usr/bin
export PATH
umask 022
tag=`basename $0`

test -d /usr/bin || exit 0      # /usr not mounted

logdir="/var/log/samba3"
smprog=/usr/local/sbin/smbd
nmprog=/usr/local/sbin/nmbd
smsg="smbd daemon"
nmsg="nmbd daemon"

# echo without newline
necho () {
    echo "$*" | tr -d '\012'
}

# exit with message
die () {
    echo "fatal: $@" >& 2
    exit 1
}

# when this is run
logmsg () {
    logfile=/var/log/$tag
    echo `date` $USER $* >>$logfile
}

killproc() {      # kill the named process(es)
    pname=`basename $1`
    pfile="/usr/local/var/locks/$pname.pid"
    pid=
    test -f $pfile && pid=`cat $pfile`

    case "$pid" in
        "") echo "$pname not running" ;;
        *)  for x in 15 1 9; do
                killpg -$x $pid
                sleep 1
            done
            rm $pfile
            ;;
    esac
}

showproc() {      # show the named process(es)
    pname=`basename $1`
    pfile="/usr/local/var/locks/$pname.pid"
    pid=
    test -f $pfile && pid=`cat $pfile`

    hdr="USER       PID  PPID  PGID STARTED      TIME COMMAND"
    popt='-axw -o user,pid,ppid,pgid,start,time,command'

    case "$pid" in
        "") return 1 ;;

        *)  echo; echo "$hdr"
            ps $popt | grep $pname
            return 0 ;;
    esac
}

# print version
version () {
    lsedscr='s/RCSfile: //
    s/.Date: //
    s/,v . .Revision: /  v/
    s/\$//g'

    lrevno='$RCSfile: samba.server,v $ $Revision: 1.1 $'
    lrevdate='$Date: 2004/05/13 23:32:35 $'
    echo "$lrevno $lrevdate" | sed -e "$lsedscr"
}

# ----------------------------------------------------------------------
case "$1" in
  start)
    if showproc $smprog
    then
       echo "$smsg already running"
    else
       necho "starting the $smsg"
       env - PATH="$PATH" $smprog -D
       echo "."
    fi

    if showproc $nmprog
    then
       echo "$nmsg already running"
    else
       necho "starting the $nmsg"
       env - PATH="$PATH" $nmprog -D
       echo "."
    fi
    ;;

  stop)
    # we can use smbstatus -p for this...
    killproc smbd
    killproc nmbd
    ;;

  stat)
    showproc $smprog && echo "$smsg running"
    showproc $nmprog && echo "$nmsg running"
    ;;

  restart)
    $0 stop
    sleep 3
    $0 start
    ;;

  dologs)
    $0 stop
    symlink='/var/log/samba3'
    newlog=`date "+/space/logs/%Y/%m%d"`
    
    mkdir -p $newlog
    if test -d "$newlog"; then
        test -L $symlink && rm $symlink
        ln -s $newlog $symlink || echo "ln -s failed" >& 2
        test -L $symlink || echo "$symlink not a link" >& 2
    else
        echo "cannot mkdir $newlog" >& 2
    fi

    (
      cd /usr/local/var &&
        mv log.nmbd log.nmbd.old &&
        mv log.smbd log.smbd.old &&
        touch log.nmbd log.smbd &&
        chmod 640 log.nmbd &&
        chmod 640 log.smbd &&
    )

    sleep 3
    $0 start
    ;;

  help)
    cat <<HELP
  start -- starts Samba service
   stop -- stops Samba service
   stat -- displays status of Samba service
restart -- stops and restarts Samba
 dologs -- stops Samba, moves logs, and restarts Samba
   help -- this message
HELP
    ;;

  -v)
    version
    ;;

  *)
    echo "usage: $tag [-v] {start|stop|stat|restart|dologs|help}"
    exit 1
    ;;
esac
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to