[RFC] [Samba] Patch to enable CTDB and replace rc.samba
by Abrixas2 from LinuxQuestions.org on (#509F0)
Hi,
I would like to propose enabling support for CTDB in the Samba package shipped with Slackware, for running a clustered file server.
I created a patch to accomplish this, appended to this post.
The patch performs the following tasks:
The default settings in etc/default/samba are chosen to be backward compatible, that is, it would start the SMB and the NetBIOS daemons.
Code:diff -ruN a/ctdb.functions._service.diff b/ctdb.functions._service.diff
--- a/ctdb.functions._service.diff 1970-01-01 01:00:00.000000000 +0100
+++ b/ctdb.functions._service.diff 2020-03-05 13:46:10.216987859 +0100
@@ -0,0 +1,24 @@
+diff -ru --no-dereference a/ctdb/config/functions b/ctdb/config/functions
+--- a/ctdb/config/functions 2020-01-31 11:25:36.000000000 +0100
++++ b/ctdb/config/functions 2020-03-05 13:45:19.292875835 +0100
+@@ -188,6 +188,20 @@
+ $_nice "${CTDB_SYS_ETCDIR}/init.d/${_service_name}" "$_op"
+ elif [ -x "${CTDB_SYS_ETCDIR}/rc.d/init.d/${_service_name}" ]; then
+ $_nice "${CTDB_SYS_ETCDIR}/rc.d/init.d/${_service_name}" "$_op"
++ else
++ if [ -z "$(which ${_service_name})" ]; then
++ die "Service ${_service_name} not found"
++ fi
++ case "${_op}" in
++ 'start')
++ ${_nice} ${_service_name} -D
++ ;;
++ 'stop')
++ killall ${_service_name}
++ ;;
++ *)
++ ;;
++ esac
+ fi
+ }
+
diff -ruN a/default.ctdb b/default.ctdb
--- a/default.ctdb 1970-01-01 01:00:00.000000000 +0100
+++ b/default.ctdb 2020-03-05 13:38:14.058071873 +0100
@@ -0,0 +1,8 @@
+#CTDB_NODES=/etc/ctdb/nodes
+#CTDB_PUBLIC_ADDRESSES=/etc/ctdb/public_addresses
+#CTDB_RECOVERY_LOCK=</path/to/cluster/share>/ctdb.lock
+#CTDB_MANAGES_SAMBA=no
+#CTDB_MANAGES_WINBIND=no
+CTDB_SERVICE_SMB=/usr/sbin/smbd
+CTDB_SERVICE_NMB=/usr/sbin/nmbd
+CTDB_SERVICE_WINBIND=/usr/sbin/winbindd
diff -ruN a/default.samba b/default.samba
--- a/default.samba 1970-01-01 01:00:00.000000000 +0100
+++ b/default.samba 2020-03-05 13:38:14.058071873 +0100
@@ -0,0 +1,5 @@
+#SAMBA_RC_START_DC=no
+#SAMBA_RC_START_CLUSTER=no
+SAMBA_RC_START_SMBD=yes
+SAMBA_RC_START_NMBD=yes
+#SAMBA_RC_START_WINBINDD=no
diff -ruN a/doinst.sh b/doinst.sh
--- a/doinst.sh 1970-01-01 01:00:00.000000000 +0100
+++ b/doinst.sh 2020-03-05 13:38:20.660083694 +0100
@@ -0,0 +1,44 @@
+#!/bin/sh
+config() {
+ NEW="$1"
+ OLD="`dirname $NEW`/`basename $NEW .new`"
+ # If there's no config file by that name, mv it over:
+ if [ ! -r $OLD ]; then
+ mv $NEW $OLD
+ elif [ "`cat $OLD | md5sum`" = "`cat $NEW | md5sum`" ]; then # toss the redundant copy
+ rm $NEW
+ fi
+ # Otherwise, we leave the .new copy for the admin to consider...
+}
+preserve_perms() {
+ NEW="$1"
+ OLD="$(dirname ${NEW})/$(basename ${NEW} .new)"
+ if [ -e ${OLD} ]; then
+ cp -a ${OLD} ${NEW}.incoming
+ cat ${NEW} > ${NEW}.incoming
+ mv ${NEW}.incoming ${NEW}
+ fi
+ config ${NEW}
+}
+
+config etc/samba/lmhosts.new
+preserve_perms etc/rc.d/rc.samba.new
+config etc/default/samba.new
+config etc/default/ctdb.new
+
+# Commented out 2014-09-15 just in case we do need to change this.
+## This won't be needed. The point here is to preserve the permissions of the existing
+## file, if there is one. I don't see major new development happening in rc.samba... ;-)
+#rm -f etc/rc.d/rc.samba.new
+
+# Since /etc/samba/private/ has moved to /var/lib/samba/private, migrate any
+# important files if possible:
+if [ -d etc/samba/private -a -d var/lib/samba/private ]; then
+ for file in etc/samba/private/* ; do
+ if [ -r "$file" -a ! -r "var/lib/samba/private/$(basename $file)" ]; then
+ mv "$file" var/lib/samba/private
+ fi
+ done
+ # Might as well try to eliminate this directory, since it should be empty:
+ rmdir etc/samba/private 1> /dev/null 2> /dev/null
+fi
diff -ruN a/rc.samba b/rc.samba
--- a/rc.samba 2020-03-05 13:37:59.082045081 +0100
+++ b/rc.samba 2020-03-05 13:38:26.554094251 +0100
@@ -8,20 +8,74 @@
# file executable: chmod 755 /etc/rc.d/rc.samba
#
+. /etc/default/samba
+
samba_start() {
- if [ -x /usr/sbin/smbd -a -x /usr/sbin/nmbd -a -r /etc/samba/smb.conf ]; then
- mkdir -p /var/run/samba
- echo "Starting Samba: /usr/sbin/smbd -D"
- /usr/sbin/smbd -D
- echo " /usr/sbin/nmbd -D"
- /usr/sbin/nmbd -D
- elif [ ! -r /etc/samba/smb.conf ]; then
+ if [ ! -r /etc/samba/smb.conf ]; then
echo "ERROR: cannot start Samba since /etc/samba/smb.conf does not exist"
+ else
+ if [ "$SAMBA_RC_START_DC" = "yes" -a "$SAMBA_RC_START_CLUSTER" = "yes" ]; then
+ echo "ERROR: The Domain Controller and the cluster functionalities are mutually exclusive"
+ else
+ if [ "$SAMBA_RC_START_DC" = "yes" -o "$SAMBA_RC_START_CLUSTER" = "yes" ]; then
+ if [ "$SAMBA_RC_START_SMBD" = "yes" -o "$SAMBA_RC_START_NMBD" = "yes" -o "$SAMBA_RC_START_WINBINDD" = "yes" ]; then
+ echo "WARNING: Ignoring request to start smbd, nmbd or winbindd"
+ fi
+ if [ "$SAMBA_RC_START_DC" = "yes" ]; then
+ echo "Starting Samba as Domain Controller: /usr/sbin/samba -D"
+ /usr/sbin/samba -D
+ else
+ echo "Starting Samba as cluster member: /usr/sbin/ctdbd_wrapper /var/run/ctdbd.pid start"
+ # This may fail spuriously, eg. when used with cgroups.
+ # If this fails, try to use a cpu cgroup with
+ # cpu.rt_runtime_us="10000"
+ i=0
+ while [ $i -lt 3 ]; do
+ /usr/sbin/ctdbd_wrapper /var/run/ctdbd.pid start &>/dev/null
+ if [ $? -eq 0 ]; then
+ break
+ fi
+ i=$[i+1]
+ sleep 1
+ done
+ if [ $i -eq 3 ]; then
+ echo "Failed to start CTDB daemon."
+ fi
+ fi
+ else
+ if [ "$SAMBA_RC_START_SMBD" = "yes" ]; then
+ echo "Starting Samba SMB service: /usr/sbin/smbd -D"
+ /usr/sbin/smbd -D
+ fi
+ if [ "$SAMBA_RC_START_NMBD" = "yes" ]; then
+ echo "Starting Samba NetBIOS service: /usr/sbin/nmbd -D"
+ /usr/sbin/nmbd -D
+ fi
+ if [ "$SAMBA_RC_START_WINBINDD" = "yes" ]; then
+ echo "Starting Samba winbind service: /usr/sbin/winbindd -D"
+ /usr/sbin/winbindd -D
+ fi
+ fi
+ fi
fi
}
samba_stop() {
- killall smbd nmbd
+ if [ "$SAMBA_RC_START_DC" = "yes" ]; then
+ killall -15 samba
+ fi
+ if [ "$SAMBA_RC_START_CLUSTER" = "yes" ]; then
+ /usr/sbin/ctdbd_wrapper /var/run/ctdbd.pid stop
+ fi
+ if [ "$SAMBA_RC_START_SMBD" = "yes" ]; then
+ killall -15 smbd
+ fi
+ if [ "$SAMBA_RC_START_NMBD" = "yes" ]; then
+ killall -15 nmbd
+ fi
+ if [ "$SAMBA_RC_START_WINBINDD" = "yes" ]; then
+ killall -15 winbindd
+ fi
}
samba_restart() {
diff -ruN a/samba.SlackBuild b/samba.SlackBuild
--- a/samba.SlackBuild 2020-03-05 13:37:59.092045098 +0100
+++ b/samba.SlackBuild 2020-03-05 13:42:09.296497067 +0100
@@ -109,6 +109,9 @@
SHADOW_OPTIONS="--without-pam"
fi
+# Patch for _service() to work with Slackware:
+cat $CWD/ctdb.functions._service.diff | patch -p1 --verbose || exit 1
+
# Some of these options could be auto-detected, but declaring them
# here doesn't hurt and helps document what features we're trying to
# build in.
@@ -142,6 +145,8 @@
--with-winbind \
--with-ldap \
--with-ads \
+ --with-cluster-support \
+ --with-shared-modules=idmap_rid,idmap_tdb2,idmap_ad \
$PAM_OPTIONS \
$SHADOW_OPTIONS \
--build=$TARGET || exit 1
@@ -187,6 +192,13 @@
# Setup a default lmhosts file:
echo "127.0.0.1 localhost" > $PKG/etc/samba/lmhosts.new
+# Add default files
+mkdir -p $PKG/etc/default
+cat $CWD/default.samba >$PKG/etc/default/samba.new
+chmod 644 $PKG/etc/default/samba.new
+cat $CWD/default.ctdb >$PKG/etc/default/ctdb.new
+chmod 644 $PKG/etc/default/ctdb.new
+
if [ ! -r $PKG/usr/bin/smbget ]; then
rm -f $PKG/usr/share/man/man1/smbget.1
fi
@@ -224,7 +236,7 @@
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
-zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
+cat $CWD/doinst.sh > $PKG/install/doinst.sh
cat << EOF


I would like to propose enabling support for CTDB in the Samba package shipped with Slackware, for running a clustered file server.
I created a patch to accomplish this, appended to this post.
The patch performs the following tasks:
- it patches the function _service in the file ctdb/config/functions within the Samba source tree to make the function compatible to Slackware,
- adds the required configure options in the SlackBuild script and
- adds a file etc/default/ctdb used by usr/sbin/ctdbd_wrapper for controlling the CTDB daemon.
The default settings in etc/default/samba are chosen to be backward compatible, that is, it would start the SMB and the NetBIOS daemons.
Code:diff -ruN a/ctdb.functions._service.diff b/ctdb.functions._service.diff
--- a/ctdb.functions._service.diff 1970-01-01 01:00:00.000000000 +0100
+++ b/ctdb.functions._service.diff 2020-03-05 13:46:10.216987859 +0100
@@ -0,0 +1,24 @@
+diff -ru --no-dereference a/ctdb/config/functions b/ctdb/config/functions
+--- a/ctdb/config/functions 2020-01-31 11:25:36.000000000 +0100
++++ b/ctdb/config/functions 2020-03-05 13:45:19.292875835 +0100
+@@ -188,6 +188,20 @@
+ $_nice "${CTDB_SYS_ETCDIR}/init.d/${_service_name}" "$_op"
+ elif [ -x "${CTDB_SYS_ETCDIR}/rc.d/init.d/${_service_name}" ]; then
+ $_nice "${CTDB_SYS_ETCDIR}/rc.d/init.d/${_service_name}" "$_op"
++ else
++ if [ -z "$(which ${_service_name})" ]; then
++ die "Service ${_service_name} not found"
++ fi
++ case "${_op}" in
++ 'start')
++ ${_nice} ${_service_name} -D
++ ;;
++ 'stop')
++ killall ${_service_name}
++ ;;
++ *)
++ ;;
++ esac
+ fi
+ }
+
diff -ruN a/default.ctdb b/default.ctdb
--- a/default.ctdb 1970-01-01 01:00:00.000000000 +0100
+++ b/default.ctdb 2020-03-05 13:38:14.058071873 +0100
@@ -0,0 +1,8 @@
+#CTDB_NODES=/etc/ctdb/nodes
+#CTDB_PUBLIC_ADDRESSES=/etc/ctdb/public_addresses
+#CTDB_RECOVERY_LOCK=</path/to/cluster/share>/ctdb.lock
+#CTDB_MANAGES_SAMBA=no
+#CTDB_MANAGES_WINBIND=no
+CTDB_SERVICE_SMB=/usr/sbin/smbd
+CTDB_SERVICE_NMB=/usr/sbin/nmbd
+CTDB_SERVICE_WINBIND=/usr/sbin/winbindd
diff -ruN a/default.samba b/default.samba
--- a/default.samba 1970-01-01 01:00:00.000000000 +0100
+++ b/default.samba 2020-03-05 13:38:14.058071873 +0100
@@ -0,0 +1,5 @@
+#SAMBA_RC_START_DC=no
+#SAMBA_RC_START_CLUSTER=no
+SAMBA_RC_START_SMBD=yes
+SAMBA_RC_START_NMBD=yes
+#SAMBA_RC_START_WINBINDD=no
diff -ruN a/doinst.sh b/doinst.sh
--- a/doinst.sh 1970-01-01 01:00:00.000000000 +0100
+++ b/doinst.sh 2020-03-05 13:38:20.660083694 +0100
@@ -0,0 +1,44 @@
+#!/bin/sh
+config() {
+ NEW="$1"
+ OLD="`dirname $NEW`/`basename $NEW .new`"
+ # If there's no config file by that name, mv it over:
+ if [ ! -r $OLD ]; then
+ mv $NEW $OLD
+ elif [ "`cat $OLD | md5sum`" = "`cat $NEW | md5sum`" ]; then # toss the redundant copy
+ rm $NEW
+ fi
+ # Otherwise, we leave the .new copy for the admin to consider...
+}
+preserve_perms() {
+ NEW="$1"
+ OLD="$(dirname ${NEW})/$(basename ${NEW} .new)"
+ if [ -e ${OLD} ]; then
+ cp -a ${OLD} ${NEW}.incoming
+ cat ${NEW} > ${NEW}.incoming
+ mv ${NEW}.incoming ${NEW}
+ fi
+ config ${NEW}
+}
+
+config etc/samba/lmhosts.new
+preserve_perms etc/rc.d/rc.samba.new
+config etc/default/samba.new
+config etc/default/ctdb.new
+
+# Commented out 2014-09-15 just in case we do need to change this.
+## This won't be needed. The point here is to preserve the permissions of the existing
+## file, if there is one. I don't see major new development happening in rc.samba... ;-)
+#rm -f etc/rc.d/rc.samba.new
+
+# Since /etc/samba/private/ has moved to /var/lib/samba/private, migrate any
+# important files if possible:
+if [ -d etc/samba/private -a -d var/lib/samba/private ]; then
+ for file in etc/samba/private/* ; do
+ if [ -r "$file" -a ! -r "var/lib/samba/private/$(basename $file)" ]; then
+ mv "$file" var/lib/samba/private
+ fi
+ done
+ # Might as well try to eliminate this directory, since it should be empty:
+ rmdir etc/samba/private 1> /dev/null 2> /dev/null
+fi
diff -ruN a/rc.samba b/rc.samba
--- a/rc.samba 2020-03-05 13:37:59.082045081 +0100
+++ b/rc.samba 2020-03-05 13:38:26.554094251 +0100
@@ -8,20 +8,74 @@
# file executable: chmod 755 /etc/rc.d/rc.samba
#
+. /etc/default/samba
+
samba_start() {
- if [ -x /usr/sbin/smbd -a -x /usr/sbin/nmbd -a -r /etc/samba/smb.conf ]; then
- mkdir -p /var/run/samba
- echo "Starting Samba: /usr/sbin/smbd -D"
- /usr/sbin/smbd -D
- echo " /usr/sbin/nmbd -D"
- /usr/sbin/nmbd -D
- elif [ ! -r /etc/samba/smb.conf ]; then
+ if [ ! -r /etc/samba/smb.conf ]; then
echo "ERROR: cannot start Samba since /etc/samba/smb.conf does not exist"
+ else
+ if [ "$SAMBA_RC_START_DC" = "yes" -a "$SAMBA_RC_START_CLUSTER" = "yes" ]; then
+ echo "ERROR: The Domain Controller and the cluster functionalities are mutually exclusive"
+ else
+ if [ "$SAMBA_RC_START_DC" = "yes" -o "$SAMBA_RC_START_CLUSTER" = "yes" ]; then
+ if [ "$SAMBA_RC_START_SMBD" = "yes" -o "$SAMBA_RC_START_NMBD" = "yes" -o "$SAMBA_RC_START_WINBINDD" = "yes" ]; then
+ echo "WARNING: Ignoring request to start smbd, nmbd or winbindd"
+ fi
+ if [ "$SAMBA_RC_START_DC" = "yes" ]; then
+ echo "Starting Samba as Domain Controller: /usr/sbin/samba -D"
+ /usr/sbin/samba -D
+ else
+ echo "Starting Samba as cluster member: /usr/sbin/ctdbd_wrapper /var/run/ctdbd.pid start"
+ # This may fail spuriously, eg. when used with cgroups.
+ # If this fails, try to use a cpu cgroup with
+ # cpu.rt_runtime_us="10000"
+ i=0
+ while [ $i -lt 3 ]; do
+ /usr/sbin/ctdbd_wrapper /var/run/ctdbd.pid start &>/dev/null
+ if [ $? -eq 0 ]; then
+ break
+ fi
+ i=$[i+1]
+ sleep 1
+ done
+ if [ $i -eq 3 ]; then
+ echo "Failed to start CTDB daemon."
+ fi
+ fi
+ else
+ if [ "$SAMBA_RC_START_SMBD" = "yes" ]; then
+ echo "Starting Samba SMB service: /usr/sbin/smbd -D"
+ /usr/sbin/smbd -D
+ fi
+ if [ "$SAMBA_RC_START_NMBD" = "yes" ]; then
+ echo "Starting Samba NetBIOS service: /usr/sbin/nmbd -D"
+ /usr/sbin/nmbd -D
+ fi
+ if [ "$SAMBA_RC_START_WINBINDD" = "yes" ]; then
+ echo "Starting Samba winbind service: /usr/sbin/winbindd -D"
+ /usr/sbin/winbindd -D
+ fi
+ fi
+ fi
fi
}
samba_stop() {
- killall smbd nmbd
+ if [ "$SAMBA_RC_START_DC" = "yes" ]; then
+ killall -15 samba
+ fi
+ if [ "$SAMBA_RC_START_CLUSTER" = "yes" ]; then
+ /usr/sbin/ctdbd_wrapper /var/run/ctdbd.pid stop
+ fi
+ if [ "$SAMBA_RC_START_SMBD" = "yes" ]; then
+ killall -15 smbd
+ fi
+ if [ "$SAMBA_RC_START_NMBD" = "yes" ]; then
+ killall -15 nmbd
+ fi
+ if [ "$SAMBA_RC_START_WINBINDD" = "yes" ]; then
+ killall -15 winbindd
+ fi
}
samba_restart() {
diff -ruN a/samba.SlackBuild b/samba.SlackBuild
--- a/samba.SlackBuild 2020-03-05 13:37:59.092045098 +0100
+++ b/samba.SlackBuild 2020-03-05 13:42:09.296497067 +0100
@@ -109,6 +109,9 @@
SHADOW_OPTIONS="--without-pam"
fi
+# Patch for _service() to work with Slackware:
+cat $CWD/ctdb.functions._service.diff | patch -p1 --verbose || exit 1
+
# Some of these options could be auto-detected, but declaring them
# here doesn't hurt and helps document what features we're trying to
# build in.
@@ -142,6 +145,8 @@
--with-winbind \
--with-ldap \
--with-ads \
+ --with-cluster-support \
+ --with-shared-modules=idmap_rid,idmap_tdb2,idmap_ad \
$PAM_OPTIONS \
$SHADOW_OPTIONS \
--build=$TARGET || exit 1
@@ -187,6 +192,13 @@
# Setup a default lmhosts file:
echo "127.0.0.1 localhost" > $PKG/etc/samba/lmhosts.new
+# Add default files
+mkdir -p $PKG/etc/default
+cat $CWD/default.samba >$PKG/etc/default/samba.new
+chmod 644 $PKG/etc/default/samba.new
+cat $CWD/default.ctdb >$PKG/etc/default/ctdb.new
+chmod 644 $PKG/etc/default/ctdb.new
+
if [ ! -r $PKG/usr/bin/smbget ]; then
rm -f $PKG/usr/share/man/man1/smbget.1
fi
@@ -224,7 +236,7 @@
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
-zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh
+cat $CWD/doinst.sh > $PKG/install/doinst.sh
cat << EOF