mirror of
https://git.FreeBSD.org/ports.git
synced 2024-12-06 01:57:40 +00:00
b3ab9ed23a
services using the same script. As a result it resets rcvar several times in order to process the options for each service. The changes I made on 2012/01/14 to facilitate the removal of set_rc_var() from HEAD were effective in the case where the WINBIND option was off (the case that I tested) because that causes the related portions of the rc.d script to be removed completely on install. However, if installed from a package, or installed using the the default OPTIONS, WINBIND is on, which caused the last known rcvar to be winbind_enable. Since the common case seems to be for users to use samba_enable (which only enables smb_and nmb_ by default) the fact that rcvar=winbind_enable, but that knob is off, caused the startup script to trip on a totally unrelated portion of rc.subr. So the fix is to move processing of the winbind_ stuff first, which leaves the last known rcvar as smb_enable. Since running nmb without smb is a very unlikely scenario, this should be safe for the common case, as well as safe if the user enables winbind_. Apologies all around for not catching this sooner, and thanks to the users who reported the problem and stuck with me while I debugged it. Bump PORTREVISION since this fix is needed for the common case, as configured for the package.
169 lines
4.8 KiB
Bash
169 lines
4.8 KiB
Bash
#!/bin/sh
|
|
#
|
|
# $FreeBSD$
|
|
#
|
|
|
|
# PROVIDE: nmbd smbd
|
|
%%WINBIND%%# PROVIDE: winbindd
|
|
# REQUIRE: NETWORKING SERVERS DAEMON ldconfig resolv
|
|
%%CUPS%%# 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"
|
|
%%WINBIND%%# You need to enable winbindd separately, by adding:
|
|
%%WINBIND%%#winbindd_enable="YES"
|
|
#
|
|
# Configuration file can be set with:
|
|
#samba_config="%%SAMBA_CONFDIR%%/%%SAMBA_CONFIG%%"
|
|
#
|
|
|
|
. /etc/rc.subr
|
|
|
|
name="samba"
|
|
rcvar=samba_enable
|
|
|
|
# Defaults
|
|
samba_enable=${samba_enable:=NO}
|
|
samba_config_default="%%SAMBA_CONFDIR%%/%%SAMBA_CONFIG%%"
|
|
samba_config=${samba_config="${samba_config_default}"}
|
|
command_args=${samba_config:+-s "${samba_config}"}
|
|
# Fetch parameters from configuration file
|
|
testparm_command="%%PREFIX%%/bin/testparm"
|
|
smbcontrol_command="%%PREFIX%%/bin/smbcontrol"
|
|
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)
|
|
# Load configuration
|
|
load_rc_config "${name}"
|
|
# Setup dependent variables
|
|
if [ -n "${rcvar}" ] && checkyesno "${rcvar}"; then
|
|
nmbd_enable=${nmbd_enable=YES}
|
|
smbd_enable=${smbd_enable=YES}
|
|
%%WINBIND%% # Check that winbindd is actually configured
|
|
%%WINBIND%% if [ -n "${samba_idmap}" ]; then
|
|
%%WINBIND%% winbindd_enable=${winbindd_enable=YES}
|
|
%%WINBIND%% fi
|
|
fi
|
|
# XXX: Hack to enable check of the dependent variables
|
|
eval real_${rcvar}="\${${rcvar}:=NO}" ${rcvar}=YES
|
|
%%WINBIND%%# winbindd
|
|
%%WINBIND%%rcvar=winbindd_enable
|
|
%%WINBIND%%winbindd_enable=${winbindd_enable:=NO}
|
|
%%WINBIND%%winbindd_flags=${winbindd_flags=''}
|
|
# nmbd
|
|
rcvar=nmbd_enable
|
|
nmbd_enable=${nmbd_enable:=NO}
|
|
nmbd_flags=${nmbd_flags="-D"}
|
|
# smbd
|
|
rcvar=smbd_enable
|
|
smbd_enable=${smbd_enable:=NO}
|
|
smbd_flags=${smbd_flags="-D"}
|
|
# 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"
|
|
#
|
|
samba_daemons="nmbd smbd"
|
|
%%WINBIND%%samba_daemons="${samba_daemons} winbindd"
|
|
# 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
|
|
return 0
|
|
}
|
|
|
|
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() {
|
|
local rcvar
|
|
rcvar=${name}_enable
|
|
eval ${rcvar}=\${real_${rcvar}}
|
|
# Prevent recursive calling
|
|
unset "${rc_arg}_cmd" "${rc_arg}_precmd" "${rc_arg}_postcmd"
|
|
# Check master variable
|
|
run_rc_command "${_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=${name}_enable
|
|
command="%%PREFIX%%/sbin/${name}"
|
|
pidfile="%%SAMBA_RUNDIR%%/${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
|
|
}
|
|
|
|
samba_cmd() {
|
|
local name rcvar rcvars v command pidfile samba_daemons result
|
|
# Prevent recursive calling
|
|
unset "${rc_arg}_cmd" "${rc_arg}_precmd" "${rc_arg}_postcmd"
|
|
# Stop processes in the reverse order
|
|
if [ "${rc_arg}" = "stop" ] ; then
|
|
samba_daemons=$(reverse_list ${samba_daemons})
|
|
fi
|
|
# Assume success
|
|
result=0
|
|
# Apply to all daemons
|
|
for name in ${samba_daemons}; do
|
|
rcvar=${name}_enable
|
|
# XXX
|
|
rcvars=''; v=''
|
|
command="%%PREFIX%%/sbin/${name}"
|
|
pidfile="%%SAMBA_RUNDIR%%/${name}${pid_extra}.pid"
|
|
# Daemon should be enabled and running
|
|
if [ -n "${rcvar}" ] && checkyesno "${rcvar}"; then
|
|
run_rc_command "${_rc_prefix}${rc_arg}" ${rc_extra_args}
|
|
# If any of the of the commands failed, take it as a total result
|
|
result=$((${result} || $?))
|
|
fi
|
|
done
|
|
return ${result}
|
|
}
|
|
|
|
run_rc_command "$1"
|