[ipvsadm] Backport the init script from RHEL6 (#593276).
Matthias Saou
thias at fedoraproject.org
Mon Jul 11 11:38:58 UTC 2011
commit 0742eb65a78c5c04d6737eebba17a0cf9a46aac6
Author: Matthias Saou <thias at marmotte.net>
Date: Mon Jul 11 13:38:11 2011 +0200
Backport the init script from RHEL6 (#593276).
ipvsadm-config | 23 +++++++
ipvsadm.init | 177 ++++++++++++++++++++++++++++++++++++++++++++++----------
ipvsadm.spec | 12 +++-
3 files changed, 179 insertions(+), 33 deletions(-)
---
diff --git a/ipvsadm-config b/ipvsadm-config
new file mode 100644
index 0000000..34251a3
--- /dev/null
+++ b/ipvsadm-config
@@ -0,0 +1,23 @@
+# Unload modules on restart and stop
+# Value: yes|no, default: yes
+# This option has to be 'yes' to get to a sane state for a ipvs
+# restart or stop. Only set to 'no' if there are problems unloading ipvs
+# modules.
+IPVS_MODULES_UNLOAD="yes"
+
+# Save current ipvs rules on stop.
+# Value: yes|no, default: no
+# Saves all ipvs rules to /etc/sysconfig/ipvsadm if ipvsadm gets stopped
+# (e.g. on system shutdown).
+IPVS_SAVE_ON_STOP="no"
+
+# Save current ipvs rules on restart.
+# Value: yes|no, default: no
+# Saves all ipvs rules to /etc/sysconfig/ipvsadm if ipvsadm gets
+# restarted.
+IPVS_SAVE_ON_RESTART="no"
+
+# Numeric status output
+# Value: yes|no, default: yes
+# Print IP addresses and port numbers in numeric format in the status output.
+IPVS_STATUS_NUMERIC="yes"
diff --git a/ipvsadm.init b/ipvsadm.init
index f9989ab..804b9b7 100644
--- a/ipvsadm.init
+++ b/ipvsadm.init
@@ -1,7 +1,7 @@
-#!/bin/sh
+#!/bin/bash
#
# Startup script handle the initialisation of LVS
-# chkconfig: - 08 92
+# chkconfig: - 28 72
# description: Initialise the Linux Virtual Server
# config: /etc/sysconfig/ipvsadm
#
@@ -15,60 +15,175 @@
# balancer running on Linux.
### END INIT INFO
-# set the configuration file
-IPVSADM_CONFIG="/etc/sysconfig/ipvsadm"
-
# Source function library
. /etc/rc.d/init.d/functions
+IPVSADM=ipvsadm
+IPVSADMRESTORE=${IPVSADM}-restore
+IPVSADMSAVE=${IPVSADM}-save
+# Saved IPVS data
+IPVSADM_DATA=/etc/sysconfig/$IPVSADM
+# Configuration
+IPVSADM_CONFIG=/etc/sysconfig/${IPVSADM}-config
+IPVS=ip_vs
+PROC_IPVS=/proc/net/$IPVS
+VAR_SUBSYS_IPVSADM=/var/lock/subsys/$IPVSADM
+
+if [ ! -x /sbin/$IPVSADM ]; then
+ echo -n $"${IPVSADM}: /sbin/$IPVSADM does not exist."; warning; echo
+ exit 5
+fi
+
+# Old or new modutils
+/sbin/modprobe --version 2>&1 | grep -q module-init-tools \
+ && NEW_MODUTILS=1 \
+ || NEW_MODUTILS=0
+
+# Default IPVSADM configuration:
+IPVS_MODULES_UNLOAD="yes"
+IPVS_SAVE_ON_STOP="no"
+IPVS_SAVE_ON_RESTART="no"
+IPVS_STATUS_NUMERIC="yes"
+
+# Load IPVSADM configuration.
+[ -f "$IPVSADM_CONFIG" ] && . "$IPVSADM_CONFIG"
+
+rmmod_r() {
+ # Unload module with all referring modules.
+ # At first all referring modules will be unloaded, then the module itself.
+ local mod=$1
+ local ret=0
+ local ref=
+
+ # Get referring modules.
+ # New modutils have another output format.
+ [ $NEW_MODUTILS = 1 ] \
+ && ref=$(lsmod | awk "/^${mod}[[:space:]]/ { print \$4; }" | tr ',' ' ') \
+ || ref=$(lsmod | grep ^${mod} | cut -d "[" -s -f 2 | cut -d "]" -s -f 1)
+
+ # recursive call for all referring modules
+ for i in $ref; do
+ rmmod_r $i
+ let ret+=$?;
+ done
+
+ # Unload module.
+ # The extra test is for 2.6: The module might have autocleaned,
+ # after all referring modules are unloaded.
+ if grep -q "^${mod}" /proc/modules ; then
+ modprobe -r $mod > /dev/null 2>&1
+ res=$?
+ [ $res -eq 0 ] || echo -n " $mod"
+ let ret+=$res;
+ fi
+
+ return $ret
+}
+
start() {
+ # Do not start if there is no config file.
+ [ ! -f "$IPVSADM_DATA" ] && return 6
+
# If we don't clear these first, we might be adding to pre-existing rules.
- action "Clearing the current IPVS table:" ipvsadm -C
- echo -n "Applying IPVS configuration: "
- ipvsadm-restore < ${IPVSADM_CONFIG} && \
- success "Applying IPVS configuration" || \
- failure "Applying IPVS configuration"
- echo
- touch /var/lock/subsys/ipvsadm
+ action $"${IPVSADM}: Clearing the current IPVS table:" $IPVSADM -C
+
+ echo -n $"${IPVSADM}: Applying IPVS configuration: "
+ $IPVSADMRESTORE < ${IPVSADM_DATA}
+ if [ $? -eq 0 ];then success; echo; else failure; echo; return 1;fi
+
+ touch $VAR_SUBSYS_IPVSADM
}
stop() {
- action "Clearing the current IPVS table:" ipvsadm -C
- rm -f /var/lock/subsys/ipvsadm
+ # Do not stop if ipvs module is not loaded.
+ [ ! -e "$PROC_IPVS" ] && return 0
+
+ action $"${IPVSADM}: Clearing the current IPVS table:" $IPVSADM -C
+
+ ret=0
+
+ if [ "x$IPVS_MODULES_UNLOAD" = "xyes" ]; then
+ action $"${IPVSADM}: Unloading modules:" rmmod_r $IPVS
+ [ $? -ne 0 ] && ret=1
+ fi
+
+ rm -f $VAR_SUBSYS_IPVSADM
+
+ return $ret
+}
+
+status() {
+ # Do not print status if lockfile is missing and ipvs modules are not
+ # loaded.
+ if [ ! -f "$VAR_SUBSYS_IPVSADM" -a ! -e "$PROC_IPVS" ]; then
+ echo $"${IPVSADM}: IPVS is not running."
+ return 3
+ fi
+
+ # Do show status if ipvs module is not loaded.
+ if [ ! -e "$PROC_IPVS" ];then
+ echo $"${IPVSADM}: IPVS module is not loaded."
+ return 3
+ fi
+
+ NUM=""
+ [ "x$IPVS_STATUS_NUMERIC" = "xyes" ] && NUM="-n"
+
+ $IPVSADM -L $NUM && echo
}
save() {
- echo -n "Saving IPVS table to ${IPVSADM_CONFIG}: "
- ipvsadm-save -n > ${IPVSADM_CONFIG} 2>/dev/null && \
- success "Saving IPVS table to ${IPVSADM_CONFIG}" || \
- failure "Saving IPVS table to ${IPVSADM_CONFIG}"
- echo
+ # Check if module is loaded
+ [ ! -e "$PROC_IPVS" ] && return 0
+
+ echo -n $"${IPVSADM}: Saving IPVS table to ${IPVSADM_DATA}: "
+ $IPVSADMSAVE -n > ${IPVSADM_DATA} 2>/dev/null
+ if [ $? -eq 0 ];then success; echo; else failure; echo; return 1;fi
+
+ return 0
+}
+
+restart() {
+ [ "x$IPVS_SAVE_ON_RESTART" = "xyes" ] && save
+ stop
+ start
}
# See how we were called.
case "$1" in
start)
+ [ -f "$VAR_SUBSYS_IPVSADM" ] && exit 0
+
# If we have no configuration, save the current one
- [ -f ${IPVSADM_CONFIG} ] || save
+ [ -f ${IPVSADM_DATA} ] || save
start
+ RETVAL=$?
;;
stop)
+ [ "x$IPVS_SAVE_ON_STOP" = "xyes" ] && save
stop
+ RETVAL=$?
+ ;;
+ restart|force-reload)
+ restart
+ RETVAL=$?
+ ;;
+ reload)
+ # Start will flush everything, so it counts as a reload
+ start
+ RETVAL=$?
;;
- reload|force-reload|restart)
- # Start will flush everything, so it counts as a restart
- start
- ;;
status)
- ipvsadm -L -n
- ;;
+ status
+ RETVAL=$?
+ ;;
save)
save
- ;;
+ RETVAL=$?
+ ;;
*)
- echo "Usage: $0 {start|stop|restart|force-reload|status|save}"
- exit 3
+ echo "Usage: $0 {start|stop|restart|force-reload|reload|status|save}"
+ RETVAL=2
esac
-exit 0
-
+exit $RETVAL
diff --git a/ipvsadm.spec b/ipvsadm.spec
index ae2cc47..c56f0e5 100644
--- a/ipvsadm.spec
+++ b/ipvsadm.spec
@@ -1,12 +1,13 @@
Summary: Utility to administer the Linux Virtual Server
Name: ipvsadm
Version: 1.26
-Release: 1%{?dist}
+Release: 2%{?dist}
License: GPLv2+
Group: Applications/System
URL: http://www.linuxvirtualserver.org/software/ipvs.html
Source0: http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-%{version}.tar.gz
Source1: ipvsadm.init
+Source2: ipvsadm-config
Patch0: ipvsadm-1.26-popt.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
Buildrequires: libnl-devel
@@ -33,8 +34,10 @@ CFLAGS="%{optflags}" make
rm -rf %{buildroot}
mkdir -p %{buildroot}/etc/rc.d/init.d
make install BUILD_ROOT=%{buildroot} MANDIR=%{_mandir}
-# Overwrite the provided init script with our own (mostly) LSB compliant one
+# Overwrite the provided init script with our flexible and LSB compliant one
install -p -m 0755 %{SOURCE1} %{buildroot}/etc/rc.d/init.d/ipvsadm
+# Install config file which controls the service behavior
+install -D -p -m 0600 %{SOURCE2} %{buildroot}/etc/sysconfig/ipvsadm-config
%clean
@@ -54,6 +57,7 @@ fi
%defattr(-,root,root)
%doc README
/etc/rc.d/init.d/ipvsadm
+%config(noreplace) /etc/sysconfig/ipvsadm-config
/sbin/ipvsadm
/sbin/ipvsadm-restore
/sbin/ipvsadm-save
@@ -63,6 +67,10 @@ fi
%changelog
+* Mon Jul 11 2011 Matthias Saou <http://freshrpms.net/> 1.26-2
+- Backport the init script from RHEL6, which contains lots of changes to make
+ it behave simlarly to the iptables init script (#593276).
+
* Sat Jul 9 2011 Matthias Saou <http://freshrpms.net/> 1.26-1
- Update to 1.26 (#676167).
- Remove upstreamed Makefile and activeconns patchs, rebase popt patch.
More information about the scm-commits
mailing list