[ucarp] Migrate to systemd.
Jon Ciesla
limb at fedoraproject.org
Wed Mar 14 15:50:14 UTC 2012
commit d6dd6869c49acd5d9ef318a28ed05c9f39aabc37
Author: Jon Ciesla <limburgher at gmail.com>
Date: Wed Mar 14 10:50:03 2012 -0500
Migrate to systemd.
ucarp | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ucarp.spec | 50 +++++++++++++++------
2 files changed, 177 insertions(+), 15 deletions(-)
---
diff --git a/ucarp b/ucarp
new file mode 100755
index 0000000..a9e0631
--- /dev/null
+++ b/ucarp
@@ -0,0 +1,142 @@
+#!/bin/bash
+
+# Source function library.
+. /etc/init.d/functions
+
+# Source networking configuration.
+. /etc/sysconfig/network
+
+# Check that networking is up.
+[ ${NETWORKING} = "no" ] && exit 0
+
+get_files() {
+ FILES=`find ${CONFDIR} -maxdepth 1 -type f -name 'vip-*.conf' \
+ -printf "%f\n" | egrep '^vip-[[:digit:]]+\.conf$' | LC_COLLATE="C" sort`
+}
+
+prog=$"common address redundancy protocol daemon"
+LOGGER="/usr/bin/logger -p daemon.notice -t ucarp"
+CONFDIR=/etc/ucarp
+UPSCRIPT=/usr/libexec/ucarp/vip-up
+DOWNSCRIPT=/usr/libexec/ucarp/vip-down
+
+start() {
+ RETVAL=-1
+ VIP_RETVAL=0
+
+ echo -n $"Starting ${prog}: "
+
+ get_files
+
+ if [ -z "${FILES}" ]; then
+ ${LOGGER} "no virtual addresses are configured in ${CONFDIR}"
+ failure
+ RETVAL=1
+ else
+ for FILE in ${FILES}; do
+ # Check that the file name gives us an ID between 1 and 255
+ ID=`echo ${FILE}| sed 's/^vip-\(.*\).conf/\1/'`
+ if [ ${ID} -lt 1 -o ${ID} -gt 255 ]; then
+ ${LOGGER} "ID out of range (1-255) for ${FILE}, skipped VIP ID ${ID}"
+ continue
+ fi
+
+ unset PASSWORD BIND_INTERFACE SOURCE_ADDRESS VIP_ADDRESS OPTIONS
+ # Source ucarp settings
+ . ${CONFDIR}/vip-common.conf
+ . ${CONFDIR}/${FILE}
+ TMP_RETVAL=0
+
+ if [ -z "${PASSWORD}" ]; then
+ ${LOGGER} "no PASSWORD found for ${FILE}, skipped VIP ID ${ID}"
+ TMP_RETVAL=1
+ fi
+ if [ -z "${BIND_INTERFACE}" ]; then
+ ${LOGGER} "no BIND_INTERFACE found for ${FILE}, skipped VIP ID ${ID}"
+ TMP_RETVAL=1
+ fi
+ if [ -z "${SOURCE_ADDRESS}" ]; then
+ ${LOGGER} "no SOURCE_ADDRESS found for ${FILE}, skipped VIP ID ${ID}"
+ TMP_RETVAL=1
+ fi
+ if [ -z "${VIP_ADDRESS}" ]; then
+ ${LOGGER} "no VIP_ADDRESS found for ${FILE}, skipped VIP ID ${ID}"
+ TMP_RETVAL=1
+ fi
+
+ # If one of more of the above failed, skip the daemon launch
+ if [ ${TMP_RETVAL} -ne 0 ]; then
+ VIP_RETVAL=1
+ continue
+ fi
+
+ [ ${RETVAL} -eq -1 ] && RETVAL=0
+ daemon /usr/sbin/ucarp --daemonize --interface=${BIND_INTERFACE} --pass=${PASSWORD} --srcip=${SOURCE_ADDRESS} --vhid=${ID} --addr=${VIP_ADDRESS} ${OPTIONS} --upscript=$UPSCRIPT --downscript=$DOWNSCRIPT >/dev/null
+ LAUNCH_RETVAL=$?
+ [ ${LAUNCH_RETVAL} -ne 0 ] && RETVAL=1
+ done
+
+ # failure/success or warning if launch worked with some vip errors
+ if [ ${RETVAL} -eq 0 -a ${VIP_RETVAL} -eq 0 ]; then
+ ${LOGGER} "all ucarp configurations were applied successfully"
+ success
+ touch /var/lock/subsys/ucarp
+ elif [ ${RETVAL} -eq 0 -a ${VIP_RETVAL} -eq 1 ]; then
+ ${LOGGER} "error in one or more of the ucarp configurations"
+ warning
+ else
+ ${LOGGER} "error running one or more of the ucarp daemon instances"
+ failure
+ fi
+ fi
+ echo
+}
+
+stop() {
+ echo -n $"Stopping $prog: "
+ killproc /usr/sbin/ucarp >/dev/null
+ RETVAL=$?
+
+ # With "--shutdown" in the default OPTIONS, the down script is called
+ # when ucarp is stopped, so IP addresses are released, no "leftovers".
+
+ # failure/success (no warning, too complicated to handle properly)
+ if [ ${RETVAL} -eq 1 ]; then
+ ${LOGGER} "it seems like no ucarp daemon were running"
+ failure
+ else
+ ${LOGGER} "all ucarp daemons stopped and IP addresses unassigned"
+ success
+ rm -f /var/lock/subsys/ucarp
+ fi
+ echo
+}
+
+# See how we were called.
+#case "$1" in
+# start)
+# start
+# ;;
+# stop)
+# stop
+# ;;
+# restart)
+# stop
+# start
+# ;;
+# condrestart)
+# if [ -f /var/lock/subsys/ucarp ]; then
+# stop
+# start
+# fi
+# ;;
+# status)
+# status /usr/sbin/ucarp
+# ;;
+# *)
+# echo $"Usage: $0 {start|stop|restart|condrestart|status}"
+# exit 1
+#esac
+start
+exit $RETVAL
+
diff --git a/ucarp.spec b/ucarp.spec
index 140d261..15c2359 100644
--- a/ucarp.spec
+++ b/ucarp.spec
@@ -1,22 +1,23 @@
Summary: Common Address Redundancy Protocol (CARP) for Unix
Name: ucarp
Version: 1.5.2
-Release: 3%{?dist}
+Release: 4%{?dist}
# See the COPYING file which details everything
License: MIT and BSD
Group: System Environment/Daemons
URL: http://www.ucarp.org/
Source0: http://download.pureftpd.org/pub/ucarp/ucarp-%{version}.tar.bz2
-Source1: ucarp.init
+Source1: ucarp at .service
Source2: vip-001.conf.example
Source3: vip-common.conf
Source4: vip-up
Source5: vip-down
#Source6: vip-helper.sh
+Source7: ucarp
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
-Requires(post): /sbin/chkconfig
-Requires(preun): /sbin/chkconfig, /sbin/service
-Requires(postun): /sbin/service
+Requires(post): systemd-units
+Requires(preun): systemd-units
+Requires(postun): systemd-units
BuildRequires: gettext
BuildRequires: autoconf, automake, libtool
BuildRequires: libpcap-devel
@@ -45,9 +46,9 @@ need for any dedicated extra network link between redundant hosts.
%{__make} install DESTDIR=%{buildroot}
%find_lang %{name}
-# Install the init script
+# Install the unit file
%{__install} -D -p -m 0755 %{SOURCE1} \
- %{buildroot}/etc/rc.d/init.d/ucarp
+ %{buildroot}%{_unitdir}/ucarp at .service
%{__mkdir_p} %{buildroot}/etc/ucarp
%{__mkdir_p} %{buildroot}%{_libexecdir}/ucarp
@@ -57,7 +58,7 @@ need for any dedicated extra network link between redundant hosts.
%{buildroot}/etc/ucarp/
# Install helper scripts
-%{__install} -D -p -m 0700 %{SOURCE4} %{SOURCE5} \
+%{__install} -D -p -m 0700 %{SOURCE4} %{SOURCE5} %{SOURCE7} \
%{buildroot}%{_libexecdir}/ucarp/
@@ -73,24 +74,40 @@ if [ -f /etc/rc.d/init.d/carp ]; then
fi
%post
-/sbin/chkconfig --add ucarp
+if [ $1 -eq 1 ] ; then
+ # Initial installation
+ /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+fi
%preun
-if [ $1 -eq 0 ]; then
- /sbin/service ucarp stop &>/dev/null || :
- /sbin/chkconfig --del ucarp
+if [ $1 -eq 0 ] ; then
+ # Package removal, not upgrade
+ /bin/systemctl --no-reload disable ucarp at .service > /dev/null 2>&1 || :
+ /bin/systemctl stop ucarp at .service > /dev/null 2>&1 || :
fi
%postun
-if [ $1 -ge 1 ]; then
- /sbin/service ucarp condrestart &>/dev/null || :
+/bin/systemctl daemon-reload >/dev/null 2>&1 || :
+if [ $1 -ge 1 ] ; then
+ # Package upgrade, not uninstall
+ /bin/systemctl try-restart ucarp at .service >/dev/null 2>&1 || :
fi
+%triggerun -- ucarp < 1.5.2-4
+# Save the current service runlevel info
+# User must manually run systemd-sysv-convert --apply ucarp
+# to migrate them to systemd targets
+/usr/bin/systemd-sysv-convert --save ucarp >/dev/null 2>&1 ||:
+
+# Run these because the SysV package being removed won't do them
+/sbin/chkconfig --del ucarp >/dev/null 2>&1 || :
+/bin/systemctl try-restart ucarp at .service >/dev/null 2>&1 || :
+
%files -f %{name}.lang
%defattr(-,root,root,-)
%doc AUTHORS COPYING ChangeLog NEWS README
-/etc/rc.d/init.d/ucarp
+%{_unitdir}/ucarp at .service
%attr(0700,root,root) %dir /etc/ucarp/
%config(noreplace) /etc/ucarp/vip-common.conf
/etc/ucarp/vip-001.conf.example
@@ -98,6 +115,9 @@ fi
%{_sbindir}/ucarp
%changelog
+* Wed Mar 14 2012 Jon Ciesla <limburgher at gmail.com> - 1.5.2-4
+- Migrate to systemd, BZ 800498.
+
* Sat Jan 14 2012 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 1.5.2-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild
More information about the scm-commits
mailing list