diff --git a/resource-agents.spec.in b/resource-agents.spec.in index 0211cae8e..fbdb7ef0f 100644 --- a/resource-agents.spec.in +++ b/resource-agents.spec.in @@ -1,344 +1,347 @@ # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed # upon. The license for this file, and modifications and additions to the # file, is the same license as for the pristine package itself (unless the # license for the pristine package is not an Open Source License, in which # case the license is the MIT License). An "Open Source License" is a # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. # %global rcver @rcver@ %global alphatag @alphatag@ %global numcomm @numcomm@ %global dirty @dirty@ # # Since this spec file supports multiple distributions, ensure we # use the correct group for each. # # SSLeay (required by ldirectord) %if 0%{?suse_version} %global SSLeay perl-Net_SSLeay %else %global SSLeay perl-Net-SSLeay %endif # determine the ras-set to process based on configure invokation %bcond_@rgmanager@ rgmanager %bcond_@linux-ha@ linuxha # build with HA_BIN compatibility for the existing Heartbeat stack %bcond_@compat-habindir@ compat_habindir %if %{with compat_habindir} %global _libexecdir %{_libdir} %endif Name: resource-agents Summary: Open Source HA Reusable Cluster Resource Scripts Version: @version@ Release: @specver@%{?rcver:%{rcver}}%{?numcomm:.%{numcomm}}%{?alphatag:.%{alphatag}}%{?dirty:.%{dirty}}%{?dist} License: GPLv2+ and LGPLv2+ URL: https://github.com/ClusterLabs/resource-agents %if 0%{?fedora} || 0%{?centos_version} || 0%{?rhel} Group: System Environment/Base %else Group: Productivity/Clustering/HA %endif Source0: %{name}-%{version}%{?rcver:%{rcver}}%{?numcomm:.%{numcomm}}%{?alphatag:-%{alphatag}}%{?dirty:-%{dirty}}.tar.bz2 Obsoletes: heartbeat-resources <= %{version} Provides: heartbeat-resources = %{version} ## Setup/build bits BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) # Build dependencies BuildRequires: automake autoconf pkgconfig BuildRequires: perl python-devel BuildRequires: libxslt glib2-devel BuildRequires: which %if 0%{?fedora} || 0%{?centos_version} || 0%{?rhel} BuildRequires: cluster-glue-libs-devel BuildRequires: docbook-style-xsl docbook-dtds %if 0%{?rhel} == 0 BuildRequires: libnet-devel %endif %endif %if 0%{?suse_version} %if 0%{?suse_version} >= 1140 BuildRequires: libnet1 %else BuildRequires: libnet %endif BuildRequires: libglue-devel BuildRequires: libxslt docbook_4 docbook-xsl-stylesheets %endif ## Runtime deps ## These apply to rgmanager agents only to guarantee agents ## are functional %if %{with rgmanager} # system tools shared by several agents Requires: /bin/bash /bin/grep /bin/sed /bin/gawk Requires: /bin/ps /usr/bin/pkill /bin/hostname Requires: /sbin/fuser Requires: /sbin/findfs /bin/mount # fs.sh Requires: /sbin/quotaon /sbin/quotacheck Requires: /sbin/fsck Requires: /sbin/fsck.ext2 /sbin/fsck.ext3 /sbin/fsck.ext4 Requires: /sbin/fsck.xfs # ip.sh Requires: /sbin/ip /usr/sbin/ethtool Requires: /sbin/rdisc /usr/sbin/arping /bin/ping /bin/ping6 # lvm.sh Requires: /sbin/lvm # netfs.sh Requires: /sbin/mount.nfs /sbin/mount.nfs4 /sbin/mount.cifs Requires: /usr/sbin/rpc.nfsd /sbin/rpc.statd /usr/sbin/rpc.mountd %endif %description A set of scripts to interface with several services to operate in a High Availability environment for both Pacemaker and rgmanager service managers. %if %{with linuxha} %package -n ldirectord License: GPLv2+ Summary: A Monitoring Daemon for Maintaining High Availability Resources %if 0%{?fedora} || 0%{?centos_version} || 0%{?rhel} Group: System Environment/Daemons %else Group: Productivity/Clustering/HA %endif Obsoletes: heartbeat-ldirectord <= %{version} Provides: heartbeat-ldirectord = %{version} %if 0%{?fedora} > 18 || 0%{?centos_version} > 6 || 0%{?rhel} > 6 BuildRequires: perl-podlators %endif Requires: %{SSLeay} perl-libwww-perl perl-MailTools Requires: ipvsadm logrotate %if 0%{?fedora_version} Requires: perl-Net-IMAP-Simple-SSL Requires(post): /sbin/chkconfig Requires(preun):/sbin/chkconfig %endif %if %{defined systemd_requires} BuildRequires: systemd %{?systemd_requires} %endif %description -n ldirectord The Linux Director Daemon (ldirectord) was written by Jacob Rief. ldirectord is a stand alone daemon for monitoring the services on real servers. Currently, HTTP, HTTPS, and FTP services are supported. lditrecord is simple to install and works with the heartbeat code (http://www.linux-ha.org/). See 'ldirectord -h' and linux-ha/doc/ldirectord for more information. %endif %prep %if 0%{?suse_version} == 0 && 0%{?fedora} == 0 && 0%{?centos_version} == 0 && 0%{?rhel} == 0 %{error:Unable to determine the distribution/version. This is generally caused by missing /etc/rpm/macros.dist. Please install the correct build packages or define the required macros manually.} exit 1 %endif %setup -q -n %{name}-%{version}%{?rcver:%{rcver}}%{?numcomm:.%{numcomm}}%{?alphatag:-%{alphatag}}%{?dirty:-%{dirty}} %build if [ ! -f configure ]; then ./autogen.sh fi %if 0%{?fedora} >= 11 || 0%{?centos_version} > 5 || 0%{?rhel} > 5 CFLAGS="$(echo '%{optflags}')" %global conf_opt_fatal "--enable-fatal-warnings=no" %else CFLAGS="${CFLAGS} ${RPM_OPT_FLAGS}" %global conf_opt_fatal "--enable-fatal-warnings=yes" %endif %if %{with rgmanager} %global rasset rgmanager %endif %if %{with linuxha} %global rasset linux-ha %endif %if %{with rgmanager} && %{with linuxha} %global rasset all %endif export CFLAGS %configure \ %{?conf_opt_rsctmpdir:%conf_opt_rsctmpdir} \ %{conf_opt_fatal} \ %if %{defined _unitdir} --with-systemdsystemunitdir=%{_unitdir} \ %endif --with-pkg-name=%{name} \ --with-ras-set=%{rasset} %if %{defined jobs} JFLAGS="$(echo '-j%{jobs}')" %else JFLAGS="$(echo '%{_smp_mflags}')" %endif make $JFLAGS %install rm -rf %{buildroot} make install DESTDIR=%{buildroot} ## tree fixup # remove docs (there is only one and they should come from doc sections in files) rm -rf %{buildroot}/usr/share/doc/resource-agents %if %{with linuxha} %if 0%{?suse_version} test -d %{buildroot}/sbin || mkdir %{buildroot}/sbin ( cd %{buildroot}/sbin %if %{defined _unitdir} ln -s /usr/sbin/service rcldirectord %else ln -sf /%{_sysconfdir}/init.d/ldirectord rcldirectord %endif ) || true %endif %endif %clean rm -rf %{buildroot} %files %defattr(-,root,root) %doc AUTHORS COPYING COPYING.GPLv3 COPYING.LGPL ChangeLog %if %{with linuxha} %doc doc/README.webapps %doc %{_datadir}/%{name}/ra-api-1.dtd %endif %if %{with rgmanager} %{_datadir}/cluster %{_sbindir}/rhev-check.sh %endif %if %{with linuxha} %dir /usr/lib/ocf %dir /usr/lib/ocf/resource.d %dir /usr/lib/ocf/lib /usr/lib/ocf/lib/heartbeat /usr/lib/ocf/resource.d/heartbeat %if %{with rgmanager} /usr/lib/ocf/resource.d/redhat %endif %dir %{_datadir}/%{name} %dir %{_datadir}/%{name}/ocft %{_datadir}/%{name}/ocft/configs %{_datadir}/%{name}/ocft/caselib +%{_datadir}/%{name}/ocft/helpers.sh +%{_datadir}/%{name}/ocft/runocft +%{_datadir}/%{name}/ocft/runocft.prereq %{_datadir}/%{name}/ocft/README %{_datadir}/%{name}/ocft/README.zh_CN %{_sbindir}/ocf-tester %{_sbindir}/ocft %{_sbindir}/sfex_init %{_sbindir}/sfex_stat %{_includedir}/heartbeat %dir %attr (1755, root, root) %{_var}/run/resource-agents %{_mandir}/man7/*.7* %{_mandir}/man8/ocf-tester.8* %{_mandir}/man8/sfex_init.8* # For compatability with pre-existing agents %dir %{_sysconfdir}/ha.d %{_sysconfdir}/ha.d/shellfuncs %{_libexecdir}/heartbeat %post -n resource-agents if [ $1 = 2 ]; then if [ -d %{_var}/run/heartbeat/rsctmp ]; then cp -fpr %{_var}/run/heartbeat/rsctmp/* %{_var}/run/resource-agents/ 1>/dev/null 2>&1 rm -fr %{_var}/run/heartbeat/rsctmp fi fi %if %{with rgmanager} ccs_update_schema > /dev/null 2>&1 ||: %endif %if 0%{?suse_version} %preun -n ldirectord %if %{defined _unitdir} %service_del_preun ldirectord.service %else %stop_on_removal ldirectord %endif %postun -n ldirectord %if %{defined _unitdir} %service_del_postun ldirectord.service %else %insserv_cleanup %endif %post -n ldirectord %if %{defined _unitdir} %service_add_post ldirectord.service %endif %pre -n ldirectord %if %{defined _unitdir} %service_add_pre ldirectord.service %endif %endif %if 0%{?fedora} %preun -n ldirectord /sbin/chkconfig --del ldirectord %postun -n ldirectord -p /sbin/ldconfig %post -n ldirectord /sbin/chkconfig --add ldirectord %endif %files -n ldirectord %defattr(-,root,root) %{_sbindir}/ldirectord %doc ldirectord/ldirectord.cf COPYING %{_mandir}/man8/ldirectord.8* %config(noreplace) %{_sysconfdir}/logrotate.d/ldirectord %dir %{_sysconfdir}/ha.d %dir %{_sysconfdir}/ha.d/resource.d %{_sysconfdir}/ha.d/resource.d/ldirectord %if %{defined _unitdir} %{_unitdir}/ldirectord.service %exclude %{_sysconfdir}/init.d/ldirectord %else %{_sysconfdir}/init.d/ldirectord %endif %if 0%{?suse_version} /sbin/rcldirectord %endif %if 0%{?fedora} /usr/lib/ocf/resource.d/heartbeat/ldirectord %endif %endif %changelog * @date@ Autotools generated version - @version@-@specver@-@numcomm@.@alphatag@.@dirty@ - Autotools generated version diff --git a/tools/ocft/Filesystem b/tools/ocft/Filesystem index 0b4d7813f..2b22d1b88 100644 --- a/tools/ocft/Filesystem +++ b/tools/ocft/Filesystem @@ -1,113 +1,105 @@ # Filesystem # by dejan@suse.de on # Tue Feb 15 18:50:04 CET 2011 # -# NB: Replace /var/run below with /run if your system mounts /run -# as tmpfs! - CONFIG Agent Filesystem AgentRoot /usr/lib/ocf/resource.d/heartbeat HangTimeout 20 VARIABLE - OCFT_fs=/var/run/resource-agents/ocft-Filesystem-fs - OCFT_loop=/dev/loop7 - OCFT_dir=/var/run/resource-agents/ocft-Filesystem-mnt + OCFT_rundir="`get_rundir`" + OCFT_fs="$OCFT_rundir/resource-agents/ocft-Filesystem-fs" + OCFT_dir="$OCFT_rundir/resource-agents/ocft-Filesystem-mnt" + OCFT_loop="`loopbackeddev make $OCFT_fs 16M`" SETUP-AGENT - losetup $OCFT_loop 2>/dev/null && exit 1 - rmdir $OCFT_dir 2>/dev/null || true - mkdir $OCFT_dir - dd if=/dev/zero of=$OCFT_fs bs=1 count=0 seek=16M 2>/dev/null - mke2fs -j -Fq -m 0 $OCFT_fs - losetup $OCFT_loop $OCFT_fs + mke2fs -j -Fq -m 0 $OCFT_loop CLEANUP-AGENT + loopbackeddev unmake $OCFT_fs rmdir $OCFT_dir - rm $OCFT_fs - losetup -d $OCFT_loop CASE-BLOCK required_args Env OCF_RESKEY_device=$OCFT_loop Env OCF_RESKEY_fstype=ext3 Env OCF_RESKEY_directory=$OCFT_dir CASE-BLOCK default_status AgentRun stop CASE-BLOCK prepare Include required_args Include default_status CASE "check base env" Include prepare AgentRun start OCF_SUCCESS CASE "check base env: invalid 'OCF_RESKEY_device'" Include prepare Env OCF_RESKEY_device=/dev/no_such_device AgentRun start OCF_ERR_INSTALLED CASE "check base env: unset 'OCF_RESKEY_device'" Include prepare Unenv OCF_RESKEY_device AgentRun start OCF_ERR_CONFIGURED CASE "normal start" Include prepare AgentRun start OCF_SUCCESS CASE "normal stop" Include prepare AgentRun start AgentRun stop OCF_SUCCESS CASE "double start" Include prepare AgentRun start AgentRun start OCF_SUCCESS CASE "double stop" Include prepare AgentRun stop OCF_SUCCESS CASE "monitor when running" Include prepare AgentRun start AgentRun monitor OCF_SUCCESS CASE "monitor when not running" Include prepare AgentRun monitor OCF_NOT_RUNNING CASE "monitor depth 10 when running" Include prepare AgentRun start Env OCF_CHECK_LEVEL=10 AgentRun monitor OCF_SUCCESS CASE "monitor depth 20 with running" Include prepare AgentRun start Env OCF_CHECK_LEVEL=20 AgentRun monitor OCF_SUCCESS CASE "start insert failure (remove device)" Include prepare Bash losetup -d $OCFT_loop BashAtExit losetup $OCFT_loop $OCFT_fs AgentRun start OCF_ERR_GENERIC CASE "monitor depth 20 insert failure (r/o fs)" Include prepare AgentRun start Bash mount -o remount,ro $OCFT_dir BashAtExit mount -o remount,rw $OCFT_dir Env OCF_CHECK_LEVEL=20 AgentRun monitor OCF_ERR_GENERIC CASE "unimplemented command" Include prepare AgentRun no_cmd OCF_ERR_UNIMPLEMENTED diff --git a/tools/ocft/LVM b/tools/ocft/LVM index 4bd2b221b..00b69ee7d 100644 --- a/tools/ocft/LVM +++ b/tools/ocft/LVM @@ -1,86 +1,83 @@ # LVM # by dejan@suse.de on # Wed Feb 16 13:15:01 CET 2011 CONFIG Agent LVM AgentRoot /usr/lib/ocf/resource.d/heartbeat HangTimeout 20 VARIABLE - OCFT_pv=/var/run/resource-agents/ocft-LVM-pv + OCFT_rundir="`get_rundir`" + OCFT_pv=$OCFT_rundir/resource-agents/ocft-LVM-pv OCFT_vg=ocft-vg OCFT_lv=ocft-lv - OCFT_loop=/dev/loop7 + OCFT_loop="`loopbackeddev make $OCFT_pv 16M`" SETUP-AGENT - losetup $OCFT_loop 2>/dev/null && exit 1 - dd if=/dev/zero of=$OCFT_pv bs=1 count=0 seek=16M 2>/dev/null - losetup $OCFT_loop $OCFT_pv pvcreate $OCFT_loop vgcreate -s 4K $OCFT_vg $OCFT_loop lvcreate -n $OCFT_lv -L 600K $OCFT_vg CLEANUP-AGENT vgchange -an $OCFT_vg lvremove -f /dev/$OCFT_vg/$OCFT_lv vgremove -f $OCFT_vg pvremove $OCFT_loop - losetup -d $OCFT_loop - rm $OCFT_pv + loopbackeddev unmake $OCFT_pv CASE-BLOCK required_args Env OCF_RESKEY_volgrpname=$OCFT_vg CASE-BLOCK default_status AgentRun stop CASE-BLOCK prepare Include required_args Include default_status CASE "check base env" Include prepare AgentRun start OCF_SUCCESS CASE "check base env: invalid 'OCF_RESKEY_volgrpname'" Include prepare Env OCF_RESKEY_volgrpname=/dev/no_such_device AgentRun start OCF_ERR_GENERIC CASE "check base env: unset 'OCF_RESKEY_volgrpname'" Include prepare Unenv OCF_RESKEY_volgrpname AgentRun start OCF_ERR_CONFIGURED CASE "normal start" Include prepare AgentRun start OCF_SUCCESS CASE "normal stop" Include prepare AgentRun start AgentRun stop OCF_SUCCESS CASE "double start" Include prepare AgentRun start AgentRun start OCF_SUCCESS CASE "double stop" Include prepare AgentRun stop OCF_SUCCESS CASE "monitor when running" Include prepare AgentRun start AgentRun monitor OCF_SUCCESS CASE "monitor when not running" Include prepare AgentRun monitor OCF_NOT_RUNNING CASE "unimplemented command" Include prepare AgentRun no_cmd OCF_ERR_UNIMPLEMENTED diff --git a/tools/ocft/Makefile.am b/tools/ocft/Makefile.am index 6218bc370..8191c11d1 100644 --- a/tools/ocft/Makefile.am +++ b/tools/ocft/Makefile.am @@ -1,60 +1,63 @@ # Author: John Shi # jshi@suse.de # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # MAINTAINERCLEANFILES = Makefile.in EXTRA_DIST = $(ocftcfgs_DATA) $(ocft_DATA) sbin_SCRIPTS = ocft ocftcfgsdir = $(datadir)/$(PACKAGE_NAME)/ocft/configs ocftcfgs_DATA = apache \ IPaddr2 \ IPaddr2v4 \ IPaddr2v6 \ IPv6addr \ Filesystem \ LVM \ Raid1 \ IPsrcaddr \ MailTo \ jboss \ mysql \ mysql-proxy \ pgsql \ db2 \ oracle \ drbd.linbit \ exportfs \ exportfs-multidir \ nfsserver \ portblock \ iscsi \ named \ postfix \ sg_persist \ tomcat \ Xinetd \ Xen \ VirtualDomain \ SendArp ocftdir = $(datadir)/$(PACKAGE_NAME)/ocft ocft_DATA = README \ README.zh_CN \ - caselib + caselib \ + helpers.sh \ + runocft.prereq +ocft_SCRIPTS = runocft diff --git a/tools/ocft/Raid1 b/tools/ocft/Raid1 index 1c239c8a0..462b9b981 100644 --- a/tools/ocft/Raid1 +++ b/tools/ocft/Raid1 @@ -1,146 +1,134 @@ # Raid1 # by dejan@suse.de on # Fri Aug 24 17:01:40 CEST 2012 CONFIG Agent Raid1 AgentRoot /usr/lib/ocf/resource.d/heartbeat InstallPackage mdadm HangTimeout 20 VARIABLE - OCFT_disk0=/var/run/resource-agents/ocft-Raid1-disk0 - OCFT_disk1=/var/run/resource-agents/ocft-Raid1-disk1 - OCFT_disk2=/var/run/resource-agents/ocft-Raid1-disk2 - OCFT_disk3=/var/run/resource-agents/ocft-Raid1-disk3 - OCFT_raidconf=/var/run/resource-agents/ocft-mdadm.conf + OCFT_rundir="`get_rundir`" + OCFT_disk0=$OCFT_rundir/resource-agents/ocft-Raid1-disk0 + OCFT_disk1=$OCFT_rundir/resource-agents/ocft-Raid1-disk1 + OCFT_disk2=$OCFT_rundir/resource-agents/ocft-Raid1-disk2 + OCFT_disk3=$OCFT_rundir/resource-agents/ocft-Raid1-disk3 + OCFT_raidconf=$OCFT_rundir/resource-agents/ocft-mdadm.conf OCFT_raiddev=/dev/md8 OCFT_raiddev2=/dev/md9 - OCFT_loop0=/dev/loop6 - OCFT_loop1=/dev/loop7 - OCFT_loop2=/dev/loop4 - OCFT_loop3=/dev/loop5 + OCFT_loop0="`loopbackeddev make $OCFT_disk0 16M`" + OCFT_loop1="`loopbackeddev make $OCFT_disk1 16M`" + OCFT_loop2="`loopbackeddev make $OCFT_disk2 16M`" + OCFT_loop3="`loopbackeddev make $OCFT_disk3 16M`" SETUP-AGENT - losetup $OCFT_loop0 2>/dev/null && exit 1 - losetup $OCFT_loop1 2>/dev/null && exit 1 - losetup $OCFT_loop2 2>/dev/null && exit 1 - losetup $OCFT_loop3 2>/dev/null && exit 1 - dd if=/dev/zero of=$OCFT_disk0 bs=1 count=0 seek=16M 2>/dev/null - dd if=/dev/zero of=$OCFT_disk1 bs=1 count=0 seek=16M 2>/dev/null - dd if=/dev/zero of=$OCFT_disk2 bs=1 count=0 seek=16M 2>/dev/null - dd if=/dev/zero of=$OCFT_disk3 bs=1 count=0 seek=16M 2>/dev/null - losetup $OCFT_loop0 $OCFT_disk0 - losetup $OCFT_loop1 $OCFT_disk1 - losetup $OCFT_loop2 $OCFT_disk2 - losetup $OCFT_loop3 $OCFT_disk3 mdadm --create $OCFT_raiddev -l 0 --raid-devices=2 $OCFT_loop0 $OCFT_loop1 mdadm --create $OCFT_raiddev2 -l 0 --raid-devices=2 $OCFT_loop2 $OCFT_loop3 echo DEVICE $OCFT_loop0 $OCFT_loop1 > $OCFT_raidconf echo DEVICE $OCFT_loop2 $OCFT_loop3 >> $OCFT_raidconf echo ARRAY $OCFT_raiddev devices=$OCFT_loop0,$OCFT_loop1 >> $OCFT_raidconf echo ARRAY $OCFT_raiddev2 devices=$OCFT_loop2,$OCFT_loop3 >> $OCFT_raidconf CLEANUP-AGENT mdadm --zero-superblock $OCFT_loop0 mdadm --zero-superblock $OCFT_loop1 mdadm --zero-superblock $OCFT_loop2 mdadm --zero-superblock $OCFT_loop3 mdadm --remove $OCFT_raiddev 2>/dev/null mdadm --remove $OCFT_raiddev2 2>/dev/null - losetup -d $OCFT_loop0 - losetup -d $OCFT_loop1 - losetup -d $OCFT_loop2 - losetup -d $OCFT_loop3 - rm $OCFT_disk0 $OCFT_disk1 $OCFT_raidconf - rm $OCFT_disk2 $OCFT_disk3 + loopbackeddev unmake $OCFT_disk0 + loopbackeddev unmake $OCFT_disk1 + loopbackeddev unmake $OCFT_disk2 + loopbackeddev unmake $OCFT_disk3 + rm -f $OCFT_raidconf CASE-BLOCK required_args Env OCF_RESKEY_raidconf=$OCFT_raidconf Env OCF_RESKEY_raiddev=$OCFT_raiddev CASE-BLOCK default_status AgentRun stop CASE-BLOCK prepare Include required_args Include default_status CASE-BLOCK prepare_auto Include required_args Env OCF_RESKEY_raiddev="auto" Include default_status CASE-BLOCK prepare_multiple Include required_args Env OCF_RESKEY_raiddev="$OCFT_raiddev $OCFT_raiddev2" Include default_status CASE "check base env" Include prepare AgentRun start OCF_SUCCESS CASE "check base env: invalid 'OCF_RESKEY_raiddev'" Include prepare Env OCF_RESKEY_raiddev=/dev/no_such_device AgentRun start OCF_ERR_GENERIC CASE "check base env: unset 'OCF_RESKEY_raiddev'" Include prepare Unenv OCF_RESKEY_raiddev AgentRun start OCF_ERR_CONFIGURED CASE "normal start" Include prepare AgentRun start OCF_SUCCESS CASE "normal stop" Include prepare AgentRun start AgentRun stop OCF_SUCCESS CASE "double start" Include prepare AgentRun start AgentRun start OCF_SUCCESS CASE "double stop" Include prepare AgentRun stop OCF_SUCCESS CASE "monitor when running" Include prepare AgentRun start AgentRun monitor OCF_SUCCESS CASE "monitor when not running" Include prepare AgentRun monitor OCF_NOT_RUNNING CASE "normal start (auto)" Include prepare_auto AgentRun start OCF_SUCCESS AgentRun monitor OCF_SUCCESS CASE "normal stop (auto)" Include prepare_auto AgentRun start AgentRun stop OCF_SUCCESS AgentRun monitor OCF_NOT_RUNNING CASE "normal start (multiple)" Include prepare AgentRun start OCF_SUCCESS AgentRun monitor OCF_SUCCESS CASE "normal stop (multiple)" Include prepare Env OCF_RESKEY_raiddev="$OCFT_raiddev $OCFT_raiddev2" AgentRun start AgentRun stop OCF_SUCCESS AgentRun monitor OCF_NOT_RUNNING CASE "unimplemented command" Include prepare AgentRun no_cmd OCF_ERR_UNIMPLEMENTED diff --git a/tools/ocft/Xinetd b/tools/ocft/Xinetd index ba9c85c7f..53f4f6504 100644 --- a/tools/ocft/Xinetd +++ b/tools/ocft/Xinetd @@ -1,56 +1,64 @@ # Xinetd CONFIG Agent Xinetd AgentRoot /usr/lib/ocf/resource.d/heartbeat InstallPackage xinetd +SETUP-AGENT + sed -i /disable/s/yes/no/ /etc/xinetd.d/echo + if which /etc/init.d/xinetd >/dev/null 2>&1; then + /etc/init.d/xinetd start + elif systemctl list-unit-files | grep -qs xinetd; then + systemctl start xinetd + fi + CASE-BLOCK required_args Env OCF_RESKEY_service=discard CASE-BLOCK default_status AgentRun stop CASE-BLOCK prepare Include required_args Include default_status CASE "check base env" Include prepare AgentRun start OCF_SUCCESS CASE "check base env: unset 'OCF_RESKEY_protocol'" Include prepare Unenv OCF_RESKEY_service AgentRun start OCF_ERR_CONFIGURED CASE "normal start" Include prepare AgentRun start OCF_SUCCESS CASE "normal stop" Include prepare AgentRun start AgentRun stop OCF_SUCCESS CASE "double start" Include prepare AgentRun start AgentRun start OCF_SUCCESS CASE "double stop" Include prepare AgentRun stop OCF_SUCCESS CASE "monitor with running" Include prepare AgentRun start AgentRun monitor OCF_SUCCESS CASE "monitor with not running" Include prepare AgentRun monitor OCF_NOT_RUNNING CASE "unimplemented command" Include prepare AgentRun no_cmd OCF_ERR_UNIMPLEMENTED diff --git a/tools/ocft/apache b/tools/ocft/apache index b2219ec26..fe4f1930b 100644 --- a/tools/ocft/apache +++ b/tools/ocft/apache @@ -1,63 +1,68 @@ # apache # make sure that your apache configuration loads mod_status CONFIG Agent apache AgentRoot /usr/lib/ocf/resource.d/heartbeat InstallPackage apache2 HangTimeout 20 SETUP-AGENT - rcapache2 start - rcapache2 stop + if systemctl list-unit-files 2>/dev/null | fgrep -q apache2.service; then + systemctl start apache2.service + systemctl stop apache2.service + else + /etc/init.d/apache2 start + /etc/init.d/apache2 stop + fi CASE-BLOCK default_status AgentRun stop CASE-BLOCK prepare Include default_status CASE "check base env" Include prepare AgentRun start OCF_SUCCESS CASE "check base env: set non-existing OCF_RESKEY_statusurl" Include prepare Env OCF_RESKEY_statusurl="yoyoyoyo" AgentRun start OCF_ERR_GENERIC CASE "check base env: set non-existing OCF_RESKEY_configfile" Include prepare Env OCF_RESKEY_configfile="/yoyoyoyo/nosuchfile" AgentRun start OCF_ERR_INSTALLED CASE "normal start" Include prepare AgentRun start OCF_SUCCESS CASE "normal stop" Include prepare AgentRun start AgentRun stop OCF_SUCCESS CASE "double start" Include prepare AgentRun start AgentRun start OCF_SUCCESS CASE "double stop" Include prepare AgentRun stop OCF_SUCCESS CASE "running monitor" Include prepare AgentRun start AgentRun monitor OCF_SUCCESS CASE "not running monitor" Include prepare AgentRun monitor OCF_NOT_RUNNING CASE "unimplemented command" Include prepare AgentRun no_cmd OCF_ERR_UNIMPLEMENTED diff --git a/tools/ocft/caselib.in b/tools/ocft/caselib.in index 01b108fab..2c5735aff 100644 --- a/tools/ocft/caselib.in +++ b/tools/ocft/caselib.in @@ -1,306 +1,299 @@ # # Copyright (c) 2010-2011 Novell Inc, John Shi # All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. quit() { local ret ret="$1" while [ $__OCFT__atexit_num -gt 0 ]; do atexit$__OCFT__atexit_num let __OCFT__atexit_num-- done rm -rf $__OCFT__fakebin exit $ret } agent_install() { local pkg if [ $# -eq 0 ]; then return 0 fi for pkg in "$@"; do if [ -e /etc/SuSE-release ]; then - if ! rpm -ql "$pkg" >/dev/null 2>&1; then - echo "${__OCFT__showhost}Installing $pkg ..." - zypper -q install -y "$pkg" >/dev/null 2>&1 - if ! rpm -ql "$pkg" >/dev/null 2>&1; then - echo - echo "${__OCFT__showhost}ERROR: Install '$pkg' failed." - quit 2 - fi - echo "done" + if ! zypper -q install -y "$pkg" >/dev/null 2>&1; then echo + echo "${__OCFT__showhost}ERROR: Install '$pkg' failed." + quit 2 fi elif [ -e /etc/debian_version ]; then - if ! dpkg -L "$pkg" >/dev/null 2>&1; then - echo "${__OCFT__showhost}Installing $pkg ..." - apt-get -y install "$pkg" >/dev/null 2>&1 - if ! dpkg -L "$pkg" >/dev/null 2>&1; then - echo - echo "${__OCFT__showhost}ERROR: Install '$pkg' failed." - quit 2 - fi - echo "done" + if ! apt-get -y install "$pkg" >/dev/null 2>&1; then echo + echo "${__OCFT__showhost}ERROR: Install '$pkg' failed." + quit 2 fi elif [ -e /etc/redhat-release ]; then - if ! rpm -ql "$pkg" >/dev/null 2>&1; then - echo "${__OCFT__showhost}Installing $pkg ..." - yum -y install "$pkg" >/dev/null 2>&1 - if ! rpm -ql "$pkg" >/dev/null 2>&1; then - echo - echo "${__OCFT__showhost}ERROR: Install '$pkg' failed." - quit 2 - fi - echo "done" + if ! yum -y install "$pkg" >/dev/null 2>&1; then echo + echo "${__OCFT__showhost}ERROR: Install '$pkg' failed." + quit 2 fi else echo "${__OCFT__showhost}ERROR: Cannot detect your OS type." quit 2 fi done } set_ocf_env() { export OCF_RA_VERSION_MAJOR=1 export OCF_RA_VERSION_MINOR=0 export OCF_RESOURCE_TYPE=$1 export OCF_RESOURCE_INSTANCE=${OCF_RESOURCE_INSTANCE:-"ocft"} } agent_run() { local agent cmd timeout pid i ret aroot agent="$1" cmd="$2" timeout="$3" set_ocf_env $agent + export OCF_RESKEY_CRM_meta_timeout + : ${OCF_RESKEY_CRM_meta_timeout:=$timeout} + aroot=${__OCFT__MYROOT:-$__OCFT__AGENT_ROOT} setsid $aroot/$agent $cmd >/tmp/.ocft_runlog 2>&1 & pid=$! i=0 while [ $i -lt $timeout ]; do if [ ! -e /proc/$pid ]; then break fi sleep 1 let i++ done if [ $i -ge $timeout ]; then kill -SIGTERM -$pid >/dev/null 2>&1 sleep 3 kill -SIGKILL -$pid >/dev/null 2>&1 echo -n "${__OCFT__showhost}ERROR: The agent was hanging, killed it, " echo "maybe you damaged the agent or system's environment, see details below:" cat /tmp/.ocft_runlog echo quit 1 fi wait $pid } check_success() { local ret msg ret="$1" msg="$2" if [ $ret -ne 0 ]; then echo "${__OCFT__showhost}ERROR: '${msg}' failed, the return code is ${ret}." quit 1 fi } __maxfd() { (echo 0; ls -1 /proc/$$/fd) | sort -rn | head -1 } __getfd() { local host rw fd file host="$1" rw="$2" for fd in /proc/$$/fd/*; do file=$(basename "$(readlink $fd)") if [ "$file" = "${host}_$rw" ]; then basename $fd break fi done } backbash_start() { local host fd rfd wfd host="$1" if [ ! -d "$__OCFT__CASES_DIR" ]; then echo "${__OCFT__showhost}ERROR: Could not found Directory: ${__OCFT__CASES_DIR}." quit 1 fi if lsof $__OCFT__CASES_DIR/${host}_r $__OCFT__CASES_DIR/${host}_w >/dev/null 2>&1; then echo "${__OCFT__showhost}ERROR: Connection exist with $host." quit 1 fi if [ ! -p "$__OCFT__CASES_DIR/${host}_r" ] || [ ! -p "$__OCFT__CASES_DIR/${host}_w" ]; then rm -f $__OCFT__CASES_DIR/${host}_r $__OCFT__CASES_DIR/${host}_w if ! mkfifo $__OCFT__CASES_DIR/${host}_r $__OCFT__CASES_DIR/${host}_w >/dev/null 2>&1; then echo "${__OCFT__showhost}ERROR: Could not create pipe file: $__OCFT__CASES_DIR/${host}_*." quit 1 fi fi ssh root@$host '/bin/bash 2>&1 sed "s/00/001/g" /tmp/.backbash-log echo 000 echo 1' >$__OCFT__CASES_DIR/${host}_r <$__OCFT__CASES_DIR/${host}_w & fd=$(__maxfd) rfd=$(expr $fd + 1) wfd=$(expr $fd + 2) eval "exec ${rfd}<$__OCFT__CASES_DIR/${host}_r ${wfd}>$__OCFT__CASES_DIR/${host}_w" } backbash() { local host rfd wfd ret host="$1" rfd=$(__getfd $host r) wfd=$(__getfd $host w) if [ -z "$rfd" -o -z "$wfd" ]; then echo "${__OCFT__showhost}ERROR: Could not found connection with $host." fi cat >&$wfd <&$wfd cat >&$wfd <&/tmp/.backbash-log sed 's/00/001/g' /tmp/.backbash-log echo 000 echo 0 EOF if [ $? -ne 0 ]; then echo "${__OCFT__showhost}ERROR: Broken connection with $host." quit 1 fi awk -vlive=2 '{ if (sub(/000$/, "")) { if ($0 != "") { gsub("001", "00"); printf("%s", $0); } getline live; exit; } gsub("001", "00"); print; } END { exit(live); }' <&$rfd case $? in 1) quit 1 ;; 2) echo "${__OCFT__showhost}ERROR: Broken connection with $host." quit 1 ;; esac } backbash_stop() { local host rfd wfd host="$1" wfd=$(__getfd $host w) if [ -n "$wfd" ]; then cat >&$wfd <<<'quit 0' fi rm -f $__OCFT__CASES_DIR/${host}_r $__OCFT__CASES_DIR/${host}_w } export OCF_ROOT=@OCF_ROOT_DIR@ export OCF_LIB=@OCF_LIB_DIR@/heartbeat __OCFT__AGENT_ROOT=@OCF_RA_DIR@/heartbeat __OCFT__CASES_DIR=/var/lib/@PACKAGE_NAME@/ocft/cases +OCFT_DIR=@datadir@/@PACKAGE_NAME@/ocft + +. $OCFT_DIR/helpers.sh __OCFT__atexit_num=0 if [ $EUID -ne 0 ]; then echo "${__OCFT__showhost}ERROR: '$0' needs to be run by root." quit 3 fi __OCFT__fakebin=./fakebin mkdir -p $__OCFT__fakebin >/dev/null 2>&1 && ln -sf /bin/true $__OCFT__fakebin/crm_master >/dev/null 2>&1 && ln -sf /bin/true $__OCFT__fakebin/crm_mon >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "${__OCFT__showhost}ERROR: initialize 'fakebin' failed." quit 3 fi export HA_SBIN_DIR=$__OCFT__fakebin . $OCF_LIB/ocf-returncodes || { echo "${__OCFT__showhost}ERROR: $OCF_LIB/ocf-returncodes not found." quit 3 } +. $OCF_LIB/ocf-directories || { + echo "${__OCFT__showhost}ERROR: $OCF_LIB/ocf-directories not found." + quit 3 +} + while read __OCFT__line; do if [ -n "$__OCFT__line" ]; then __OCFT__retn=${__OCFT__line%%=*} __OCFT__reti=$(eval echo \$$__OCFT__retn) __OCFT__retval[__OCFT__reti]=$__OCFT__retn fi done <<<"$(sed 's/#.*//' $OCF_LIB/ocf-returncodes)" # vim:ts=2:sw=2:et: diff --git a/tools/ocft/exportfs b/tools/ocft/exportfs index 8db482725..618627336 100644 --- a/tools/ocft/exportfs +++ b/tools/ocft/exportfs @@ -1,79 +1,80 @@ # exportfs # # CONFIG Agent exportfs AgentRoot /usr/lib/ocf/resource.d/heartbeat - HangTimeout 40 + InstallPackage nfs-kernel-server + HangTimeout 40 SETUP-AGENT # nothing CASE-BLOCK set_testenv - Env OCF_RESKEY_directory=/usr - Env OCF_RESKEY_fsid=105 - Env OCF_RESKEY_clientspec="*" + Env OCF_RESKEY_directory=/usr + Env OCF_RESKEY_fsid=105 + Env OCF_RESKEY_clientspec="*" Env OCF_RESKEY_CRM_meta_timeout=30000 CASE-BLOCK default_status AgentRun stop CASE-BLOCK prepare - Include set_testenv + Include set_testenv Include default_status CASE "check base env" Include prepare AgentRun start OCF_SUCCESS CASE "check base env: no 'OCF_RESKEY_fsid'" Include prepare Env OCF_RESKEY_fsid= AgentRun start OCF_ERR_CONFIGURED CASE "check base env: invalid 'OCF_RESKEY_directory'" Include prepare Env OCF_RESKEY_directory=/no_such AgentRun start OCF_ERR_INSTALLED CASE "check base env: non-decimal 'OCF_RESKEY_fsid'" Include prepare Env OCF_RESKEY_fsid="4f838db14f838db14f838db14f838db1" AgentRun start OCF_SUCCESS CASE "unimplemented command" Include prepare AgentRun no_cmd OCF_ERR_UNIMPLEMENTED CASE "normal start" Include prepare AgentRun start OCF_SUCCESS CASE "normal stop" Include prepare AgentRun start AgentRun stop OCF_SUCCESS CASE "double start" Include prepare AgentRun start AgentRun start OCF_SUCCESS CASE "double stop" Include prepare AgentRun stop OCF_SUCCESS CASE "stop with no env" Include prepare Env OCF_RESKEY_directory=/no_such AgentRun stop OCF_SUCCESS CASE "started: monitor" Include prepare AgentRun start AgentRun monitor OCF_SUCCESS CASE "not started: monitor" Include prepare AgentRun monitor OCF_NOT_RUNNING diff --git a/tools/ocft/exportfs-multidir b/tools/ocft/exportfs-multidir index 72551c669..2e35e79b2 100644 --- a/tools/ocft/exportfs-multidir +++ b/tools/ocft/exportfs-multidir @@ -1,79 +1,80 @@ # exportfs # # CONFIG Agent exportfs AgentRoot /usr/lib/ocf/resource.d/heartbeat - HangTimeout 40 + InstallPackage nfs-kernel-server + HangTimeout 40 SETUP-AGENT - # nothing + # nothing CASE-BLOCK set_testenv - Env OCF_RESKEY_directory="/usr /var" - Env OCF_RESKEY_fsid=105 - Env OCF_RESKEY_clientspec="*" + Env OCF_RESKEY_directory="/usr /var" + Env OCF_RESKEY_fsid=105 + Env OCF_RESKEY_clientspec="*" Env OCF_RESKEY_CRM_meta_timeout=30000 CASE-BLOCK default_status AgentRun stop CASE-BLOCK prepare - Include set_testenv + Include set_testenv Include default_status CASE "check base env" Include prepare AgentRun start OCF_SUCCESS CASE "check base env: no 'OCF_RESKEY_fsid'" Include prepare Env OCF_RESKEY_fsid= AgentRun start OCF_ERR_CONFIGURED CASE "check base env: invalid 'OCF_RESKEY_directory'" Include prepare Env OCF_RESKEY_directory=/no_such AgentRun start OCF_ERR_INSTALLED CASE "check base env: invalid 'OCF_RESKEY_fsid'" Include prepare Env OCF_RESKEY_fsid=root AgentRun start OCF_ERR_CONFIGURED CASE "unimplemented command" Include prepare AgentRun no_cmd OCF_ERR_UNIMPLEMENTED CASE "normal start" Include prepare AgentRun start OCF_SUCCESS CASE "normal stop" Include prepare AgentRun start AgentRun stop OCF_SUCCESS CASE "double start" Include prepare AgentRun start AgentRun start OCF_SUCCESS CASE "double stop" Include prepare AgentRun stop OCF_SUCCESS CASE "stop with no env" Include prepare Env OCF_RESKEY_directory="/usr /no_such" AgentRun stop OCF_SUCCESS CASE "started: monitor" Include prepare AgentRun start AgentRun monitor OCF_SUCCESS CASE "not started: monitor" Include prepare AgentRun monitor OCF_NOT_RUNNING diff --git a/tools/ocft/helpers.sh b/tools/ocft/helpers.sh new file mode 100644 index 000000000..98489349b --- /dev/null +++ b/tools/ocft/helpers.sh @@ -0,0 +1,43 @@ +get_rundir() { + local rundir + rundir="`mount | grep '/run ' | awk '{print $3}'`" + echo ${rundir:-"/var/run"} +} + +loopbackeddev() { + local action file size ctlfile + + action="$1" + file="$2" + size="$3" + ctlfile=$HA_RSCTMP/`echo $file | tr / _` + + case "$action" in + start|setup|make) + if [ ! -f "$ctlfile" ]; then + if [ -z "$size" ]; then + echo "usage: $0 action file size" >&2 + exit 1 + fi + loopdev=`losetup -f` + if ! dd if=/dev/zero of=$file bs=1 count=0 seek=$size 2>/dev/null; then + echo "$0: dd failed" >&2 + exit 1 + fi + if ! losetup $loopdev $file; then + echo "$0: losetup failed" >&2 + exit 1 + fi + echo $loopdev | tee $ctlfile + else + cat $ctlfile + fi + ;; + stop|undo|unmake) + if [ -f "$ctlfile" ]; then + losetup -d `cat $ctlfile` + rm -f $file $ctlfile + fi + ;; + esac +} diff --git a/tools/ocft/iscsi b/tools/ocft/iscsi index 7b0452a6c..3c5d5244a 100644 --- a/tools/ocft/iscsi +++ b/tools/ocft/iscsi @@ -1,82 +1,108 @@ # iscsi CONFIG Agent iscsi AgentRoot /usr/lib/ocf/resource.d/heartbeat - InstallPackage open-iscsi - InstallPackage iscsitarget + InstallPackage open-iscsi targetcli HangTimeout 20 VARIABLE - OCFT_disk=/var/run/resource-agents/ocft-iscsi - OCFT_target="iqn.2011-03.ocft.localhost:disk0" + OCFT_rundir="`get_rundir`" + OCFT_disk="$OCFT_rundir/resource-agents/ocft-iscsi" + OCFT_target="iqn.2003-01.org.linux-iscsi:ocft" OCFT_portal="127.0.0.1:3260" + OCFT_loop="`loopbackeddev make $OCFT_disk 16M`" + OCF_RESKEY_iqn=$OCFT_target + OCF_RESKEY_portals=$OCFT_portal + OCF_RESKEY_target_iqn=$OCFT_target + OCF_RESKEY_path=$OCFT_loop + OCF_RESKEY_lun=1 SETUP-AGENT - dd if=/dev/zero of=$OCFT_disk bs=1024k count=1 2>/dev/null - echo Target $OCFT_target >> /etc/ietd.conf - echo " Lun 0 Path=$OCFT_disk,Type=fileio" >> /etc/ietd.conf - rciscsitarget start - rcopen-iscsi start - rciscsitarget restart + if systemctl list-unit-files 2>/dev/null | fgrep -q iscsid.service; then + systemctl start iscsid.service + else + /etc/init.d/open-iscsi start + fi + if systemctl list-unit-files 2>/dev/null | fgrep -q target.service; then + systemctl start target.service + else + /etc/init.d/target start + fi + export OCF_RESKEY_iqn=$OCFT_target + export OCF_RESKEY_portals=$OCFT_portal + export OCF_RESKEY_target_iqn=$OCFT_target + export OCF_RESKEY_path=$OCFT_loop + export OCF_RESKEY_lun=1 + /usr/lib/ocf/resource.d/heartbeat/iSCSITarget start + /usr/lib/ocf/resource.d/heartbeat/iSCSILogicalUnit start CLEANUP-AGENT - rm -f $OCFT_disk - sed -i "/^Target $OCFT_target/,+1d" /etc/ietd.conf + export OCF_RESKEY_iqn=$OCFT_target + export OCF_RESKEY_portals=$OCFT_portal + export OCF_RESKEY_target_iqn=$OCFT_target + export OCF_RESKEY_path=$OCFT_loop + export OCF_RESKEY_lun=1 + /usr/lib/ocf/resource.d/heartbeat/iSCSILogicalUnit stop + /usr/lib/ocf/resource.d/heartbeat/iSCSITarget stop + if systemctl list-unit-files 2>/dev/null | fgrep -q target.service; then + systemctl stop target.service + fi + loopbackeddev unmake $OCFT_disk CASE-BLOCK required_args Env OCF_RESKEY_portal=$OCFT_portal Env OCF_RESKEY_target=$OCFT_target CASE-BLOCK default_status AgentRun stop CASE-BLOCK prepare Include required_args Include default_status CASE "check base env" Include prepare AgentRun start OCF_SUCCESS CASE "check base env: invalid 'OCF_RESKEY_portal'" Include prepare Unenv OCF_RESKEY_portal AgentRun start OCF_ERR_CONFIGURED CASE "check base env: unset 'OCF_RESKEY_target'" Include prepare Unenv OCF_RESKEY_target AgentRun start OCF_ERR_CONFIGURED CASE "normal start" Include prepare AgentRun start OCF_SUCCESS CASE "normal stop" Include prepare AgentRun start AgentRun stop OCF_SUCCESS CASE "double start" Include prepare AgentRun start AgentRun start OCF_SUCCESS CASE "double stop" Include prepare AgentRun stop OCF_SUCCESS CASE "monitor when running" Include prepare AgentRun start AgentRun monitor OCF_SUCCESS CASE "monitor when not running" Include prepare AgentRun monitor OCF_NOT_RUNNING CASE "unimplemented command" Include prepare AgentRun no_cmd OCF_ERR_UNIMPLEMENTED diff --git a/tools/ocft/mysql b/tools/ocft/mysql index bae0dc723..305a900a4 100644 --- a/tools/ocft/mysql +++ b/tools/ocft/mysql @@ -1,77 +1,82 @@ # mysql CONFIG Agent mysql AgentRoot /usr/lib/ocf/resource.d/heartbeat InstallPackage mysql HangTimeout 20 SETUP-AGENT - rcmysql start - rcmysql stop + if systemctl list-unit-files 2>/dev/null | fgrep -q mysql.service; then + systemctl start mysql.service + systemctl stop mysql.service + else + /etc/init.d/mysql start + /etc/init.d/mysql stop + fi CASE-BLOCK crm_setting Env OCF_RESKEY_CRM_meta_timeout=15000 CASE-BLOCK default_status AgentRun stop CASE-BLOCK prepare Include crm_setting Include default_status CASE "check base env" Include prepare AgentRun start OCF_SUCCESS CASE "check base env: invalid 'OCF_RESKEY_binary'" Include prepare Env OCF_RESKEY_binary=no_such AgentRun start OCF_ERR_INSTALLED CASE "normal start" Include prepare AgentRun start OCF_SUCCESS CASE "normal stop" Include prepare AgentRun start AgentRun stop OCF_SUCCESS CASE "double start" Include prepare AgentRun start AgentRun start OCF_SUCCESS CASE "double stop" Include prepare AgentRun stop OCF_SUCCESS CASE "running monitor" Include prepare AgentRun start AgentRun monitor OCF_SUCCESS CASE "not running monitor" Include prepare AgentRun monitor OCF_NOT_RUNNING CASE "check lib file" Include prepare Bash chmod u-w /var/lib/mysql BashAtExit chmod u+w /var/lib/mysql AgentRun start OCF_ERR_PERM CASE "unimplemented command" Include prepare AgentRun no_cmd OCF_ERR_UNIMPLEMENTED CASE "non-existent user" Include prepare Env OCF_RESKEY_user=no_user AgentRun start OCF_ERR_INSTALLED CASE "invalid user" Include prepare Env OCF_RESKEY_user=nobody AgentRun start OCF_ERR_PERM diff --git a/tools/ocft/named b/tools/ocft/named index 15024a8bb..90a4351bc 100644 --- a/tools/ocft/named +++ b/tools/ocft/named @@ -1,69 +1,69 @@ #named # To work properly this test requires that standard bind and bin-utils # packages installed. CONFIG Agent named AgentRoot /usr/lib/ocf/resource.d/heartbeat InstallPackage bind InstallPackage bind-utils SETUP-AGENT - rcnamed start - rcnamed stop + /etc/init.d/named start + /etc/init.d/named stop CASE-BLOCK crm_setting Env OCF_RESKEY_CRM_meta_timeout=15000 CASE-BLOCK default_status AgentRun stop CASE-BLOCK prepare Include crm_setting Include default_status CASE "check base env" Include prepare AgentRun start OCF_SUCCESS CASE "check base env: invalid 'OCF_RESKEY_named'" Include prepare Env OCF_RESKEY_named=no_such AgentRun start OCF_ERR_INSTALLED CASE "normal start" Include prepare AgentRun start OCF_SUCCESS CASE "normal stop" Include prepare AgentRun start AgentRun stop OCF_SUCCESS CASE "double start" Include prepare AgentRun start AgentRun start OCF_SUCCESS CASE "double stop" Include prepare AgentRun stop OCF_SUCCESS CASE "running monitor" Include prepare AgentRun start AgentRun monitor OCF_SUCCESS CASE "not running monitor" Include prepare AgentRun monitor OCF_NOT_RUNNING CASE "unimplemented command" Include prepare AgentRun no_cmd OCF_ERR_UNIMPLEMENTED CASE "non-existent user" Include prepare Env OCF_RESKEY_named_user=no_user AgentRun start OCF_ERR_INSTALLED diff --git a/tools/ocft/nfsserver b/tools/ocft/nfsserver index 7c69de91a..cf2ac8943 100644 --- a/tools/ocft/nfsserver +++ b/tools/ocft/nfsserver @@ -1,74 +1,69 @@ # nfsserver CONFIG Agent nfsserver AgentRoot /usr/lib/ocf/resource.d/heartbeat - InstallPackage $NFSPKG + InstallPackage nfs-kernel-server HangTimeout 20 SETUP-AGENT INITSCRIPT="" if test -f /etc/init.d/nfsserver; then INITSCRIPT="/etc/init.d/nfsserver" fi - if test -e /etc/SuSE-release; then - NFSPKG=nfs-kernel-server - elif test -e /etc/redhat-release; then - NFSPKG=nfs-utils - fi true CASE-BLOCK required_args Env OCF_RESKEY_nfs_init_script=$INITSCRIPT CASE-BLOCK default_status AgentRun stop CASE-BLOCK prepare Include required_args Include default_status CASE "check base env" Include prepare AgentRun start OCF_SUCCESS CASE "check base env: invalid 'OCF_RESKEY_nfs_init_script'" Include prepare Env OCF_RESKEY_nfs_init_script=no_such_script AgentRun start OCF_ERR_INSTALLED CASE "check base env: invalid 'OCF_RESKEY_nfs_notify_cmd'" Include prepare Env OCF_RESKEY_nfs_notify_cmd=no_such_program AgentRun start OCF_ERR_INSTALLED CASE "normal start" Include prepare AgentRun start OCF_SUCCESS CASE "normal stop" Include prepare AgentRun start AgentRun stop OCF_SUCCESS CASE "double start" Include prepare AgentRun start AgentRun start OCF_SUCCESS CASE "double stop" Include prepare AgentRun stop OCF_SUCCESS CASE "monitor with running" Include prepare AgentRun start AgentRun monitor OCF_SUCCESS CASE "monitor with not running" Include prepare AgentRun monitor OCF_NOT_RUNNING CASE "unimplemented command" Include prepare AgentRun no_cmd OCF_ERR_UNIMPLEMENTED diff --git a/tools/ocft/ocft.in b/tools/ocft/ocft.in index bfa9dcb3c..3f7dfcf48 100644 --- a/tools/ocft/ocft.in +++ b/tools/ocft/ocft.in @@ -1,889 +1,893 @@ #!/bin/bash # Copyright (c) 2010-2013 Novell Inc, John Shi # All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. die() { local str str="$1" echo "ERROR: $str" >&2 exit 1 } warn() { local str str="$1" echo "WARNING: $str" >&2 } parse_die() { local str str="$1" agent_parse_finish die "${agent}: line ${line_num}: ${str}" } # add quotes to string for Here Documents add_quotes() { local typ str a b typ="$1" str="$2" case "$typ" in 1) a=\'; b=\";; 2) a=\"; b=\';; esac echo "$str" | sed "s/$a/$a$b$a$b$a/g; 1 s/^/$a/; $ s/$/$a/" } # split strings explode() { local str str="$1" echo "$str" | awk -F'"' '{ if (NF > 0 && NF%2 == 0) exit(1); for (i=1; i<=NF; i++) { if (i%2 == 0) print $i; else { len = split($i, str, /[ \t]+/); for (j=1; j<=len; j++) { sb = sub(/#.*/, "", str[j]); if (str[j] != "") print str[j]; if (sb) exit(0); } } } }' } # phase 1: parse the string to 'command' and 'argument collection'. line2trunk() { trunk[0]="${line%%[[:blank:]]*}" trunk[1]="${line#*[[:blank:]]}" } # phase 2: split the argument collection. trunk2branch() { local IFS # Some of statements need one parameter at least. if [ "$line" = "${trunk[0]}" ]; then parse_die "missing parameter." fi IFS=$'\n' branch=($(explode "${trunk[1]}")) if [ $? -ne 0 ]; then parse_die "missing '\"'." fi } preparse_cfg() { local agent line trunk branch macro num host agent="$1" if [ ! -r "$opt_cfgsdir/$agent" ]; then die "${agent}: configuration file not found." fi line_num=0 while read -r line; do let line_num++ num=" $line_num" case "$line" in ""|\#*) continue;; esac line2trunk case "${trunk[0]}" in CASE-BLOCK) trunk2branch macro="$CASES_DIR/${agent}_macro.${branch[0]}" continue ;; Include|Include@*) host=$(echo "${trunk[0]}" | awk -F@ '{print $2}') trunk2branch if [ ! -r "$CASES_DIR/${agent}_macro.${branch[0]}" ]; then parse_die "Macro '${branch[0]}' not found." fi if [ -n "$host" ]; then line="$(sed -e 's/^\([^[:blank:]]*\)@[^[:blank:]]*/\1/' -e "s/^[^[:blank:]]*/&@$host/" "$CASES_DIR/${agent}_macro.${branch[0]}")" else line="$(<"$CASES_DIR/${agent}_macro.${branch[0]}")" fi num= ;; *[!A-Z-]*) : ;; *) macro= ;; esac if [ -n "$macro" ]; then echo "$line$num" >>"$macro" else echo "$line$num" >>"$CASES_DIR/${agent}_preparse" fi done <"$opt_cfgsdir/$agent" } case_parse_finish() { local host if [ -n "$sh" ]; then cat >>$sh <>$sh done echo "quit 0" >>$sh fi atexit_num=0 hosts= sh= } init_cfg_vars() { cfg_agent= cfg_agent_root= cfg_install_package=() cfg_hang_timeout=20 } agent_parse_finish() { local suf for suf in preparse setup cleanup var hosts; do rm -f $CASES_DIR/${agent}_$suf done rm -f $CASES_DIR/${agent}_macro.* init_cfg_vars } need_make() { local src_time obj_time if [ ! -f "$CASES_DIR/0_${agent}.sh" ]; then return 0 fi src_time=$(stat -c '%Y' "$opt_cfgsdir/$agent") obj_time=$(stat -c '%Y' "$CASES_DIR/0_${agent}.sh") test $src_time -ge $obj_time } parse_cfg() { local agents i line stat sh trunk branch atexit_num host hosts if [ $# -eq 0 ]; then agents=($opt_cfgsdir/*) else agents=("$@") fi for agent in "${agents[@]}"; do agent="$(basename "$agent")" if ! need_make; then continue fi agent_obj_clean $agent agent_parse_finish i=0 echo "Making '$agent': " preparse_cfg "$agent" while read -r line; do line_num="${line##* }" line="${line% *}" line2trunk # state switch case "${trunk[0]}" in CONFIG) case_parse_finish stat=1 continue ;; VARIABLE) case_parse_finish stat=2 continue ;; SETUP-AGENT) case_parse_finish stat=3 continue ;; CLEANUP-AGENT) case_parse_finish stat=4 continue ;; CASE) case_parse_finish trunk2branch echo " - case ${i}: ${branch[0]}" sh="$CASES_DIR/${i}_${agent}.sh" cat >$sh <>$CASES_DIR/${agent}_var ;; 3) echo "$line" >>$CASES_DIR/${agent}_setup ;; 4) echo "$line" >>$CASES_DIR/${agent}_cleanup ;; 5) host=$(echo ${trunk[0]} | awk -F@ '{print $2}') if [ -n "$host" ]; then if ! echo "$hosts" | grep -q "$host"; then echo "$host" >>$CASES_DIR/${agent}_hosts hosts=$hosts$'\n'$host cat >>$sh <>$sh if [ -n "$host" ]; then echo "backbash $host <<'CMD'" >>$sh fi case "${trunk[0]}" in Env|Env@*) cat >>$sh <>$sh <>$sh <>$sh <>$sh <>$sh <>$sh <>$sh <>$sh <>$sh fi ;; *) parse_die "unimplemented statement: ${trunk[0]}" ;; esac done <$CASES_DIR/${agent}_preparse if [ -r "$CASES_DIR/${agent}_setup" ]; then cat >$CASES_DIR/setup_${agent}.sh <>$CASES_DIR/setup_${agent}.sh <>$CASES_DIR/setup_${agent}.sh <$CASES_DIR/cleanup_${agent}.sh <>$CASES_DIR/cleanup_${agent}.sh <>$CASES_DIR/cleanup_${agent}.sh </dev/null 2>&1; then die "cases directory not found." fi if [ ! -d logs ]; then mkdir logs fi export __OCFT__VERBOSE=$opt_verbose if [ $# -eq 0 ]; then agents=($(ls -1 *.sh 2>/dev/null | sed 's/.*_\([^_]*\)\.sh$/\1/' | sort | uniq)) else agents=("$@") fi for shs in "${agents[@]}"; do if [ -z "$opt_incremental" ]; then testsh="setup_${shs}.sh $(ls -1 [0-9]*_${shs}.sh 2>/dev/null | sort -n) cleanup_${shs}.sh" else testsh="setup_${shs}.sh $(ls -1 [0-9]*_${shs}.retest 2>/dev/null | sed 's/retest$/sh/' | sort -n) cleanup_${shs}.sh" fi if [ -n "$opt_trace_ra" ]; then varlib=${HA_VARLIB:="/var/lib/heartbeat"} export OCF_RESKEY_trace_ra=1 echo "RA trace on, output in $varlib/trace_ra" fi - for sh in $testsh; do + rc_f=`mktemp` + (for sh in $testsh; do if [ -r "$sh" ]; then if [ -n "$opt_trace_ra" ]; then export OCF_RESOURCE_INSTANCE="`echo $sh | sed 's/_.*//'`" fi ./$sh ret=$? case "$sh" in setup*) + rc=$((rc|ret)) if [ $ret -ne 0 ]; then warn "SETUP failed, break all tests of '$shs'." break fi - rc=$((rc|ret)) ;; cleanup*) if [ $ret -ne 0 ]; then warn "CLEANUP failed." fi ;; [0-9]*) case $ret in 3) die "core function failed, break all tests." ;; 2) warn "core function failed, break all tests of '$shs'."; break ;; 1) touch ${sh%.*}.retest ;; 0) rm -f ${sh%.*}.retest ;; esac rc=$((rc|ret)) ;; esac fi - done 2>&1 | while read -r line; do + done 2>&1; echo $rc > $rc_f) | while read -r line; do echo "$line" echo "$(date '+%F %T'): $line" | cat -A | sed -r 's/\^\[\[[0-9]+m|\^I|.$//g' >>logs/$shs.log done done + rc=`cat $rc_f` + rm -f $rc_f return $rc } agent_clean() { local typ ra typ=$1 shift if [ $# -eq 0 ]; then rm -f $CASES_DIR/*.$typ else for ra in "$@"; do rm -f $CASES_DIR/*_${ra}.$typ done fi } agent_retest_clean() { agent_clean retest "$@" } agent_obj_clean() { agent_clean sh "$@" } usage() { cat </dev/null 2>&1 +} + +rm -f ocft.FAILED +rc=0 +while read f prereq; do + if [ -n "$prereq" ] && ! test_prereq; then + echo "$f: prerequisite not fulfilled, skipping" + continue + fi + ocft make $f + if ! ocft test $f; then + echo $f >> ocft.FAILED + rc=1 + fi +done < $OCFTDIR/runocft.prereq + +if [ -f ocft.FAILED ]; then + echo "The following ocft tests failed:" + cat ocft.FAILED +fi + +exit $rc diff --git a/tools/ocft/runocft.prereq b/tools/ocft/runocft.prereq new file mode 100644 index 000000000..3bc222c14 --- /dev/null +++ b/tools/ocft/runocft.prereq @@ -0,0 +1,30 @@ +apache +db2 prog:~db2inst1/sqllib/bin/db2 +drbd.linbit run:false +exportfs +exportfs-multidir +Filesystem +IPaddr2 run:ip addr show dev eth0 +IPaddr2v4 run:ip addr show dev eth0 && ip addr show dev eth1 +IPaddr2v6 run:ip addr show dev eth0 && ip addr show dev eth1 +IPsrcaddr run:false +IPv6addr run:ip addr show dev eth0 && ip addr show dev eth1 +iscsi +jboss run:false +LVM +MailTo +mysql +mysql-proxy run:false +named +nfsserver +oracle prog:sqlplus +pgsql +portblock +postfix +Raid1 +SendArp +sg_persist run:false +tomcat run:false +VirtualDomain run:false +Xen run:false +Xinetd