From 113101f50f17b29758dc26ac8f0a7e29b2b3be92 Mon Sep 17 00:00:00 2001 From: Sumit Bose <sbose@redhat.com> Date: Tue, 10 Jan 2012 10:20:35 +0100 Subject: [PATCH 2/2] Add systemd support --- config/ctdb.service | 19 ++++++++++++ config/systemd/ctdb.systemd | 32 ++++++++++++++++++++ config/systemd/ctdb_check_persistent_databases.pre | 20 ++++++++++++ config/systemd/ctdb_drop_all_public_ips | 22 +++++++++++++ config/systemd/ctdb_set_ctdb_variables.post | 26 ++++++++++++++++ packaging/RPM/ctdb.spec.in | 22 +++++++++++++- 6 files changed, 140 insertions(+), 1 deletions(-) create mode 100644 config/ctdb.service create mode 100755 config/systemd/ctdb.systemd create mode 100755 config/systemd/ctdb_check_persistent_databases.pre create mode 100644 config/systemd/ctdb_drop_all_public_ips create mode 100644 config/systemd/ctdb_set_ctdb_variables.post diff --git a/config/ctdb.service b/config/ctdb.service new file mode 100644 index 0000000..76b47bd --- /dev/null +++ b/config/ctdb.service @@ -0,0 +1,19 @@ +[Unit] +Description=CTDB +After=network.target + +[Service] +Type=forking +LimitCORE=infinity +PIDFile=/run/ctdbd/ctdbd.pid +ExecStartPre=/etc/ctdb/systemd/ctdb_drop_all_public_ips +ExecStartPre=/etc/ctdb/systemd/ctdb_check_persistent_databases.pre +ExecStart=/etc/ctdb/systemd/ctdb.systemd +ExecStartPost=/etc/ctdb/systemd/ctdb_set_ctdb_variables.post +ExecStop=/usr/bin/ctdb shutdown +ExecStopPost=-/etc/ctdb/systemd/ctdb_drop_all_public_ips +KillMode=control-group +Restart=no + +[Install] +WantedBy=multi-user.target diff --git a/config/systemd/ctdb.systemd b/config/systemd/ctdb.systemd new file mode 100755 index 0000000..6f29e85 --- /dev/null +++ b/config/systemd/ctdb.systemd @@ -0,0 +1,32 @@ +#!/bin/sh +# + +# Avoid using root's TMPDIR +unset TMPDIR + +[ -z "$CTDB_BASE" ] && { + export CTDB_BASE="/etc/ctdb" +} + +[ -z "$CTDB_VARDIR" ] && { + export CTDB_VARDIR="/var/ctdb" +} + +. $CTDB_BASE/functions +. $CTDB_BASE/init_functions + +. /etc/sysconfig/ctdb + +ctdbd=${CTDBD:-/usr/sbin/ctdbd} + +if [ "$CTDB_SUPPRESS_COREFILE" = "yes" ]; then + ulimit -c 0 +else + ulimit -c unlimited +fi + +build_ctdb_options + +exec $ctdbd "$CTDB_OPTIONS" >/dev/null 2>&1 </dev/null + +exit 1 diff --git a/config/systemd/ctdb_check_persistent_databases.pre b/config/systemd/ctdb_check_persistent_databases.pre new file mode 100755 index 0000000..7659225 --- /dev/null +++ b/config/systemd/ctdb_check_persistent_databases.pre @@ -0,0 +1,20 @@ +#!/bin/sh +# + +# Avoid using root's TMPDIR +unset TMPDIR + +[ -z "$CTDB_BASE" ] && { + export CTDB_BASE="/etc/ctdb" +} + +[ -z "$CTDB_VARDIR" ] && { + export CTDB_VARDIR="/var/ctdb" +} + +. $CTDB_BASE/functions +. $CTDB_BASE/init_functions + +. /etc/sysconfig/ctdb + +check_persistent_databases || exit 1 diff --git a/config/systemd/ctdb_drop_all_public_ips b/config/systemd/ctdb_drop_all_public_ips new file mode 100644 index 0000000..7a05c6f --- /dev/null +++ b/config/systemd/ctdb_drop_all_public_ips @@ -0,0 +1,22 @@ +#!/bin/sh +# + +# Avoid using root's TMPDIR +unset TMPDIR + +[ -z "$CTDB_BASE" ] && { + export CTDB_BASE="/etc/ctdb" +} + +[ -z "$CTDB_VARDIR" ] && { + export CTDB_VARDIR="/var/ctdb" +} + +. $CTDB_BASE/functions +. $CTDB_BASE/init_functions + +. /etc/sysconfig/ctdb + +drop_all_public_ips + +exit 0 diff --git a/config/systemd/ctdb_set_ctdb_variables.post b/config/systemd/ctdb_set_ctdb_variables.post new file mode 100644 index 0000000..f02ca5d --- /dev/null +++ b/config/systemd/ctdb_set_ctdb_variables.post @@ -0,0 +1,26 @@ +#!/bin/sh +# + +# Avoid using root's TMPDIR +unset TMPDIR + +[ -z "$CTDB_BASE" ] && { + export CTDB_BASE="/etc/ctdb" +} + +[ -z "$CTDB_VARDIR" ] && { + export CTDB_VARDIR="/var/ctdb" +} + +. $CTDB_BASE/functions +. $CTDB_BASE/init_functions + +. /etc/sysconfig/ctdb + +if wait_until_ready ; then + set_ctdb_variables +else + exit 1 +fi + +exit 0 diff --git a/packaging/RPM/ctdb.spec.in b/packaging/RPM/ctdb.spec.in index 53c6080..a7ef034 100644 --- a/packaging/RPM/ctdb.spec.in +++ b/packaging/RPM/ctdb.spec.in @@ -1,3 +1,4 @@ +%define with_systemd 0 %define initdir %{_sysconfdir}/init.d Name: ctdb Summary: Clustered TDB @@ -62,12 +63,23 @@ rm -rf $RPM_BUILD_ROOT # Create the target build directory hierarchy mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig -mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/init.d make DESTDIR=$RPM_BUILD_ROOT docdir=%{_docdir} install install -m644 config/ctdb.sysconfig $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/ctdb + +%if %{with_systemd} +mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/ctdb/systemd +install -m 755 config/systemd/ctdb_check_persistent_databases.pre $RPM_BUILD_ROOT%{_sysconfdir}/ctdb/systemd +install -m 755 config/systemd/ctdb_set_ctdb_variables.post $RPM_BUILD_ROOT%{_sysconfdir}/ctdb/systemd +install -m 755 config/systemd/ctdb_drop_all_public_ips $RPM_BUILD_ROOT%{_sysconfdir}/ctdb/systemd +install -m 755 config/systemd/ctdb.systemd $RPM_BUILD_ROOT%{_sysconfdir}/ctdb/systemd +mkdir -p $RPM_BUILD_ROOT%{_unitdir} +install -m 755 config/ctdb.service $RPM_BUILD_ROOT%{_unitdir} +%else +mkdir -p $RPM_BUILD_ROOT%{initdir} install -m755 config/ctdb.init $RPM_BUILD_ROOT%{initdir}/ctdb +%endif mkdir -p $RPM_BUILD_ROOT%{_docdir}/ctdb/tests/bin install -m755 tests/bin/ctdb_transaction $RPM_BUILD_ROOT%{_docdir}/ctdb/tests/bin @@ -90,7 +102,15 @@ rm -rf $RPM_BUILD_ROOT %config(noreplace) %{_sysconfdir}/ctdb/notify.sh %config(noreplace) %{_sysconfdir}/ctdb/ctdb-crash-cleanup.sh %config(noreplace) %{_sysconfdir}/ctdb/functions +%if %{with_systemd} +%{_sysconfdir}/ctdb/systemd/ctdb_check_persistent_databases.pre +%{_sysconfdir}/ctdb/systemd/ctdb_set_ctdb_variables.post +%{_sysconfdir}/ctdb/systemd/ctdb_drop_all_public_ips +%{_sysconfdir}/ctdb/systemd/ctdb.systemd +%{_unitdir}/ctdb.service +%else %attr(755,root,root) %{initdir}/ctdb +%endif %{_docdir}/ctdb/README.eventscripts %{_docdir}/ctdb/recovery-process.txt -- 1.7.7.6