How to start or stop daemon in silence

Hi;

I run a custom script at boot by using /usr/local/sbin
In this script I stop a daemon : [CMD="/usr/local/etc/rc.d"]samba stop[/CMD]

When this command is run I read on the screen an error because winbindd is not running.

I've tried things like [CMD="/usr/local/etc/rc.d/"]samba stop &>/dev/null[/CMD] but this is not working.

Is it possible to start/stop a daemon without output ?

Thanks
 
I remember having this same problem with winbindd a few weeks ago. I hacked the rc script to make it shut up, but don't remember the specifics of what I changed. If you want, I'll post it Monday if you haven't figured something out.

If you just want to suppress all output, I believe you have to use bash and use the 1>/dev/null 2>/dev/null to redirect STDOUT and STDERR.
 
Try
command 2>/dev/null (suppresses error output)
command > /dev/null 2>&1 (suppresses all output)
command 1>/dev/null 2>/dev/null (same)
 
Use this:
Code:
nmbd_enable="YES"
smbd_enable="YES"
Instead of
Code:
samba_enable="YES"
 
I believe I tried doing that SirDice, but no dice - same message popped up. (And yes, I intended that as a pun. :) :e ) I also tried setting winbindd_enable, also to no effect.

I just looked at my samba startup script and can't find what I changed. Further, I neglected to keep a backup copy of the original. :( Here's the entire thing - maybe you could run a diff on it against your own and post the changes, both for future people who view this thread and so that I don't drive myself crazy trying to figure out what I changed?

Code:
#!/bin/sh
#
# $FreeBSD: ports/net/samba33/files/samba.in,v 1.1 2009/03/07 05:57:21 timur Exp $
#

# PROVIDE: nmbd smbd
# PROVIDE: winbindd
# REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv
# REQUIRE: cupsd
# BEFORE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
#samba_enable="YES"
# or, for fine grain control:
#nmbd_enable="YES"
#smbd_enable="YES"
# You need to enable winbindd separately, by adding:
#winbindd_enable="YES"
#
# Configuration file can be set with:
#samba_config="/usr/local/etc/smb.conf"
#

. /etc/rc.subr

name="samba"
rcvar=$(set_rcvar)

load_rc_config "${name}"
# Custom commands
extra_commands="reload status"
start_precmd="samba_start_precmd"
start_cmd="samba_cmd"
stop_cmd="samba_cmd"
status_cmd="samba_cmd"
restart_precmd="samba_checkconfig"
reload_precmd="samba_checkconfig"
reload_cmd="samba_reload_cmd"
rcvar_cmd="samba_rcvar_cmd"
# Defaults
samba_enable=${samba_enable:=NO}
samba_config_default="/usr/local/etc/smb.conf"
samba_config=${samba_config="${samba_config_default}"}
command_args=${samba_config:+-s "${samba_config}"}
samba_daemons="nmbd smbd"
#samba_daemons="${samba_daemons} winbindd"
testparm_command="/usr/local/bin/testparm"
smbcontrol_command="/usr/local/bin/smbcontrol"
# Fetch parameters from configuration file
samba_parm="${testparm_command} -s -v --parameter-name"
samba_idmap=$(${samba_parm} 'idmap uid' "${samba_config}" 2>/dev/null)
samba_lockdir=$(${samba_parm} 'lock directory' "${samba_config}" 2>/dev/null)
# Setup dependent variables
if [ -n "${rcvar}" ] && checkyesno "${rcvar}"; then
    nmbd_enable=${nmbd_enable=YES}
    smbd_enable=${smbd_enable=YES}
    # Check that winbindd is actually configured
    if [ -n "${samba_idmap}" ]; then
  winbindd_enable=${winbindd_enable=YES}
    fi
fi
# Hack to work around name change of pid file with non-default config
pid_extra=
if [ -n "${samba_config}" -a "${samba_config}" != "${samba_config_default}" ]; then
    pid_extra="-$(basename "${samba_config}")"
fi
# Hack to enable check of dependent variables
eval real_${rcvar}="\${${rcvar}:=NO}" ${rcvar}=YES
# Defaults for dependent variables
nmbd_enable=${nmbd_enable:=NO}
nmbd_flags=${nmbd_flags="-D"}
smbd_enable=${smbd_enable:=NO}
smbd_flags=${smbd_flags="-D"}
winbindd_enable=${winbindd_enable:=NO}
winbindd_flags=${winbindd_flags=''}
# Requirements
required_files="${samba_config}"
required_dirs="${samba_lockdir}"
samba_checkconfig() {
    echo -n "Performing sanity check on Samba configuration: "
    if ${testparm_command} -s ${samba_config:+"${samba_config}"} >/dev/null 2>&1; then
  echo "OK"
    else
  echo "FAILED"
  return 1
    fi
}

samba_start_precmd() {
    # XXX: Never delete winbindd_idmap, winbindd_cache and group_mapping
    if [ -n "${samba_lockdir}" -a -d "${samba_lockdir}" ]; then
  echo -n "Removing stale Samba tdb files: "
  for file in brlock.tdb browse.dat connections.tdb gencache.tdb \
        locking.tdb messages.tdb namelist.debug sessionid.tdb \
        unexpected.tdb
  do
      rm "${samba_lockdir}/${file}" </dev/null 2>/dev/null && echo -n '.'
  done
  echo " done"
    fi
}

samba_rcvar_cmd() {
    # Prevent recursive calling
    unset "${rc_arg}_cmd" "${rc_arg}_precmd" "${rc_arg}_postcmd"
    # Check master variable
    echo "# ${name}"
    if [ -n "${rcvar}" ]; then
  # Use original configured value
  if checkyesno "real_${rcvar}"; then
      echo "\$${rcvar}=YES"
  else
      echo "\$${rcvar}=NO"
  fi
    fi
    # Check dependent variables
    samba_cmd "${_rc_prefix}${rc_arg}" ${rc_extra_args}
}

samba_reload_cmd() {
    local name rcvar command pidfile
    # Prevent recursive calling
    unset "${rc_arg}_cmd" "${rc_arg}_precmd" "${rc_arg}_postcmd"
    # Apply to all daemons
    for name in ${samba_daemons}; do
      rcvar=$(set_rcvar)
  command="/usr/local/sbin/${name}"
  pidfile="/var/run/${name}${pid_extra}.pid"
  # Daemon should be enabled and running
  if [ -n "${rcvar}" ] && checkyesno "${rcvar}"; then
      if [ -n "$(check_pidfile "${pidfile}" "${command}")" ]; then
    debug "reloading ${name} configuration"
    echo "Reloading ${name}."
    # XXX: Hack with pid_extra
    ${smbcontrol_command} "${name}${pid_extra}" 'reload-config' ${command_args}
>/dev/null 2>&1
      fi
  fi
    done
}

    local name rcvar command pidfile samba_daemons
    # Prevent recursive calling
    unset "${rc_arg}_cmd" "${rc_arg}_precmd" "${rc_arg}_postcmd"
    # Stop processes in the reverse to order
    if [ "${rc_arg}" = "stop" ] ; then
  samba_daemons=$(reverse_list ${samba_daemons})
    fi
    # Apply to all daemons
    for name in ${samba_daemons}; do
  rcvar=$(set_rcvar)
  command="/usr/local/sbin/${name}"
  pidfile="/var/run/${name}${pid_extra}.pid"

  run_rc_command "${_rc_prefix}${rc_arg}" ${rc_extra_args}
    done
}

run_rc_command "$1"
 
Here is your change in the script:

You have added ->
Code:
# Hack to work around name change of pid file with non-default config
pid_extra=
if [ -n "${samba_config}" -a "${samba_config}" != "${samba_config_default}" ]; then
    pid_extra="-$(basename "${samba_config}")"
fi

In my default start/stop script for samba this does not exist. So there is no variable called pid_extra, and that's why the default script does not work. Shame on port maintainer.
 
Back
Top