diff --git a/configure.ac b/configure.ac index 7b5faff58..74766899b 100644 --- a/configure.ac +++ b/configure.ac @@ -1,1083 +1,1084 @@ dnl dnl autoconf for Agents dnl dnl License: GNU General Public License (GPL) dnl =============================================== dnl Bootstrap dnl =============================================== AC_PREREQ(2.63) dnl Suggested structure: dnl information on the package dnl checks for programs dnl checks for libraries dnl checks for header files dnl checks for types dnl checks for structures dnl checks for compiler characteristics dnl checks for library functions dnl checks for system services AC_INIT([resource-agents], m4_esyscmd([make/git-version-gen .tarball-version]), [developers@clusterlabs.org]) AC_USE_SYSTEM_EXTENSIONS CRM_DTD_VERSION="1.0" AC_CONFIG_AUX_DIR(.) AC_CONFIG_MACRO_DIR([m4]) AC_CANONICAL_HOST dnl Where #defines go (e.g. `AC_CHECK_HEADERS' below) dnl dnl Internal header: include/config.h dnl - Contains ALL defines dnl - include/config.h.in is generated automatically by autoheader dnl - NOT to be included in any header files except lha_internal.h dnl (which is also not to be included in any other header files) dnl dnl External header: include/agent_config.h dnl - Contains a subset of defines checked here dnl - Manually edit include/agent_config.h.in to have configure include new defines dnl - Should not include HAVE_* defines dnl - Safe to include anywhere AM_CONFIG_HEADER(include/config.h include/agent_config.h) ALL_LINGUAS="en fr" AC_ARG_WITH(version, [ --with-version=version Override package version (if you're a packager needing to pretend) ], [ PACKAGE_VERSION="$withval" ]) AC_ARG_WITH(pkg-name, [ --with-pkg-name=name Override package name (if you're a packager needing to pretend) ], [ PACKAGE_NAME="$withval" ]) dnl dnl AM_INIT_AUTOMAKE([1.11.1 foreign dist-bzip2 dist-xz]) dnl AM_INIT_AUTOMAKE([1.10.1 foreign dist-bzip2]) AC_DEFINE_UNQUOTED(AGENTS_VERSION, "$PACKAGE_VERSION", Current agents version) CC_IN_CONFIGURE=yes export CC_IN_CONFIGURE LDD=ldd dnl ======================================================================== dnl Compiler characteristics dnl ======================================================================== # check stolen from gnulib/m4/gnu-make.m4 if ! ${MAKE-make} --version /cannot/make/this >/dev/null 2>&1; then AC_MSG_ERROR([you don't seem to have GNU make; it is required]) fi AC_PROG_CC dnl Can force other with environment variable "CC". AM_PROG_CC_C_O AC_PROG_CC_STDC AC_PROG_AWK AC_PROG_LN_S AC_PROG_INSTALL AC_PROG_MAKE_SET AC_C_STRINGIZE AC_C_INLINE AC_TYPE_SIZE_T AC_TYPE_SSIZE_T AC_TYPE_UID_T AC_TYPE_UINT16_T AC_TYPE_UINT8_T AC_TYPE_UINT32_T AC_CHECK_SIZEOF(char) AC_CHECK_SIZEOF(short) AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(long long) AC_STRUCT_TIMEZONE dnl =============================================== dnl Helpers dnl =============================================== cc_supports_flag() { local CPPFLAGS="$@" AC_MSG_CHECKING(whether $CC supports "$@") AC_PREPROC_IFELSE([AC_LANG_PROGRAM([])], [RC=0; AC_MSG_RESULT([yes])], [RC=1; AC_MSG_RESULT([no])]) return $RC } extract_header_define() { AC_MSG_CHECKING(for $2 in $1) Cfile=$srcdir/extract_define.$2.${$} printf "#include \n" > ${Cfile}.c printf "#include <%s>\n" $1 >> ${Cfile}.c printf "int main(int argc, char **argv) { printf(\"%%s\", %s); return 0; }\n" $2 >> ${Cfile}.c $CC $CFLAGS ${Cfile}.c -o ${Cfile} value=`${Cfile}` AC_MSG_RESULT($value) printf $value rm -f ${Cfile}.c ${Cfile} } AC_MSG_NOTICE(Sanitizing prefix: ${prefix}) case $prefix in NONE) prefix=/usr dnl Fix default variables - "prefix" variable if not specified if test "$localstatedir" = "\${prefix}/var"; then localstatedir="/var" fi if test "$sysconfdir" = "\${prefix}/etc"; then sysconfdir="/etc" fi ;; esac # ordering is important, PKG_PROG_PKG_CONFIG is to be invoked before any other PKG_* related stuff PKG_PROG_PKG_CONFIG(0.18) # PKG_CHECK_MODULES will fail if systemd is not found by default, so make sure # we set the proper vars and deal with it PKG_CHECK_MODULES([systemd], [systemd], [HAS_SYSTEMD=yes], [HAS_SYSTEMD=no]) if test "x$HAS_SYSTEMD" = "xyes"; then PKG_CHECK_VAR([SYSTEMD_UNIT_DIR], [systemd], [systemdsystemunitdir]) if test "x$SYSTEMD_UNIT_DIR" = "x"; then AC_MSG_ERROR([Unable to detect systemd unit dir automatically]) fi PKG_CHECK_VAR([SYSTEMD_TMPFILES_DIR], [systemd], [tmpfilesdir]) if test "x$SYSTEMD_TMPFILES_DIR" = "x"; then AC_MSG_ERROR([Unable to detect systemd tmpfiles directory automatically]) fi # sanitize systed vars when using non standard prefix if test "$prefix" != "/usr"; then SYSTEMD_UNIT_DIR="$prefix/$SYSTEMD_UNIT_DIR" AC_SUBST([SYSTEMD_UNIT_DIR]) SYSTEMD_TMPFILES_DIR="$prefix/$SYSTEMD_TMPFILES_DIR" AC_SUBST([SYSTEMD_TMPFILES_DIR]) fi fi AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$HAS_SYSTEMD" = xyes ]) dnl =============================================== dnl Configure Options dnl =============================================== dnl Some systems, like Solaris require a custom package name AC_ARG_WITH(pkgname, [ --with-pkgname=name name for pkg (typically for Solaris) ], [ PKGNAME="$withval" ], [ PKGNAME="LXHAhb" ], ) AC_SUBST(PKGNAME) AC_ARG_ENABLE([ansi], [ --enable-ansi force GCC to compile to ANSI/ANSI standard for older compilers. [default=yes]]) AC_ARG_ENABLE([fatal-warnings], [ --enable-fatal-warnings very pedantic and fatal warnings for gcc [default=yes]]) INITDIR="" AC_ARG_WITH(initdir, [ --with-initdir=DIR directory for init (rc) scripts [${INITDIR}]], [ INITDIR="$withval" ]) OCF_ROOT_DIR="${prefix}/lib/ocf" AC_ARG_WITH(ocf-root, [ --with-ocf-root=DIR directory for OCF scripts [${OCF_ROOT_DIR}]], [ OCF_ROOT_DIR="$withval" ]) HA_RSCTMPDIR=${localstatedir}/run/resource-agents AC_ARG_WITH(rsctmpdir, [ --with-rsctmpdir=DIR directory for resource agents state files [${HA_RSCTMPDIR}]], [ HA_RSCTMPDIR="$withval" ]) AC_ARG_ENABLE([libnet], [ --enable-libnet Use libnet for ARP based functionality, [default=try]], [enable_libnet="$enableval"], [enable_libnet=try]) BUILD_RGMANAGER=0 BUILD_LINUX_HA=0 RASSET=linux-ha AC_ARG_WITH(ras-set, [ --with-ras-set=SET build/install only linux-ha, rgmanager or all resource-agents [default: linux-ha]], [ RASSET="$withval" ]) if test x$RASSET = xyes || test x$RASSET = xall ; then BUILD_RGMANAGER=1 BUILD_LINUX_HA=1 fi if test x$RASSET = xlinux-ha; then BUILD_LINUX_HA=1 fi if test x$RASSET = xrgmanager; then BUILD_RGMANAGER=1 fi if test $BUILD_LINUX_HA -eq 0 && test $BUILD_RGMANAGER -eq 0; then AC_MSG_ERROR([Are you really sure you want this package?]) exit 1 fi AM_CONDITIONAL(BUILD_LINUX_HA, test $BUILD_LINUX_HA -eq 1) AM_CONDITIONAL(BUILD_RGMANAGER, test $BUILD_RGMANAGER -eq 1) AC_ARG_WITH(compat-habindir, [ --with-compat-habindir use HA_BIN directory with compatibility for the Heartbeat stack [${libexecdir}]], [], [with_compat_habindir=no]) AM_CONDITIONAL(WITH_COMPAT_HABINDIR, test "x$with_compat_habindir" != "xno") dnl =============================================== dnl General Processing dnl =============================================== echo Our Host OS: $host_os/$host AC_MSG_NOTICE(Sanitizing exec_prefix: ${exec_prefix}) case $exec_prefix in dnl For consistency with Heartbeat, map NONE->$prefix NONE) exec_prefix=$prefix;; prefix) exec_prefix=$prefix;; esac AC_MSG_NOTICE(Sanitizing INITDIR: ${INITDIR}) case $INITDIR in prefix) INITDIR=$prefix;; "") AC_MSG_CHECKING(which init (rc) directory to use) for initdir in /etc/init.d /etc/rc.d/init.d /sbin/init.d \ /usr/local/etc/rc.d /etc/rc.d do if test -d $initdir then INITDIR=$initdir break fi done if test -z $INITDIR then INITDIR=${sysconfdir}/init.d fi AC_MSG_RESULT($INITDIR);; esac AC_SUBST(INITDIR) if test "${prefix}" = "/usr"; then INITDIRPREFIX="$INITDIR" else INITDIRPREFIX="${prefix}/$INITDIR" fi AC_SUBST(INITDIRPREFIX) AC_MSG_NOTICE(Sanitizing libdir: ${libdir}) case $libdir in dnl For consistency with Heartbeat, map NONE->$prefix *prefix*|NONE) AC_MSG_CHECKING(which lib directory to use) for aDir in lib64 lib do trydir="${exec_prefix}/${aDir}" if test -d ${trydir} then libdir=${trydir} break fi done AC_MSG_RESULT($libdir); ;; esac if test "x$with_compat_habindir" != "xno" ; then libexecdir=${libdir} fi dnl Expand autoconf variables so that we dont end up with '${prefix}' dnl in #defines and python scripts dnl NOTE: Autoconf deliberately leaves them unexpanded to allow dnl make exec_prefix=/foo install dnl No longer being able to do this seems like no great loss to me... eval prefix="`eval echo ${prefix}`" eval exec_prefix="`eval echo ${exec_prefix}`" eval bindir="`eval echo ${bindir}`" eval sbindir="`eval echo ${sbindir}`" eval libexecdir="`eval echo ${libexecdir}`" eval datadir="`eval echo ${datadir}`" eval sysconfdir="`eval echo ${sysconfdir}`" eval sharedstatedir="`eval echo ${sharedstatedir}`" eval localstatedir="`eval echo ${localstatedir}`" eval libdir="`eval echo ${libdir}`" eval includedir="`eval echo ${includedir}`" eval oldincludedir="`eval echo ${oldincludedir}`" eval infodir="`eval echo ${infodir}`" eval mandir="`eval echo ${mandir}`" dnl docdir is a recent addition to autotools eval docdir="`eval echo ${docdir}`" if test "x$docdir" = "x"; then docdir="`eval echo ${datadir}/doc`" fi AC_SUBST(docdir) dnl Home-grown variables eval INITDIR="${INITDIR}" for j in prefix exec_prefix bindir sbindir libexecdir datadir sysconfdir \ sharedstatedir localstatedir libdir includedir oldincludedir infodir \ mandir INITDIR docdir do dirname=`eval echo '${'${j}'}'` if test ! -d "$dirname" then AC_MSG_WARN([$j directory ($dirname) does not exist!]) fi done dnl This OS-based decision-making is poor autotools practice; dnl feature-based mechanisms are strongly preferred. dnl dnl So keep this section to a bare minimum; regard as a "necessary evil". REBOOT_OPTIONS="-f" POWEROFF_OPTIONS="-f" case "$host_os" in *bsd*) LIBS="-L/usr/local/lib" CPPFLAGS="$CPPFLAGS -I/usr/local/include" ;; *solaris*) REBOOT_OPTIONS="-n" POWEROFF_OPTIONS="-n" LDFLAGS+=" -lssp -lssp_nonshared" ;; *linux*) AC_DEFINE_UNQUOTED(ON_LINUX, 1, Compiling for Linux platform) POWEROFF_OPTIONS="-nf" REBOOT_OPTIONS="-nf" ;; darwin*) AC_DEFINE_UNQUOTED(ON_DARWIN, 1, Compiling for Darwin platform) LIBS="$LIBS -L${prefix}/lib" CFLAGS="$CFLAGS -I${prefix}/include" ;; esac AC_DEFINE_UNQUOTED(HA_LOG_FACILITY, LOG_DAEMON, Default logging facility) AC_MSG_NOTICE(Host CPU: $host_cpu) case "$host_cpu" in ppc64|powerpc64) case $CFLAGS in *powerpc64*) ;; *) if test "$GCC" = yes; then CFLAGS="$CFLAGS -m64" fi ;; esac esac AC_MSG_CHECKING(which format is needed to print uint64_t) case "$host_cpu" in s390x)U64T="%lu";; *64*) U64T="%lu";; *) U64T="%llu";; esac AC_MSG_RESULT($U64T) AC_DEFINE_UNQUOTED(U64T, "$U64T", Correct printf format for logging uint64_t) dnl Variables needed for substitution AC_CHECK_HEADERS(heartbeat/glue_config.h) if test "$ac_cv_header_heartbeat_glue_config_h" != "yes"; then enable_libnet=no fi AC_DEFINE_UNQUOTED(OCF_ROOT_DIR,"$OCF_ROOT_DIR", OCF root directory - specified by the OCF standard) AC_SUBST(OCF_ROOT_DIR) GLUE_STATE_DIR=${localstatedir}/run AC_DEFINE_UNQUOTED(GLUE_STATE_DIR,"$GLUE_STATE_DIR", Where to keep state files and sockets) AC_SUBST(GLUE_STATE_DIR) AC_DEFINE_UNQUOTED(HA_VARRUNDIR,"$GLUE_STATE_DIR", Where Heartbeat keeps state files and sockets - old name) HA_VARRUNDIR="$GLUE_STATE_DIR" AC_SUBST(HA_VARRUNDIR) # Expand $prefix eval HA_RSCTMPDIR="`eval echo ${HA_RSCTMPDIR}`" AC_DEFINE_UNQUOTED(HA_RSCTMPDIR,"$HA_RSCTMPDIR", Where Resource agents keep state files) AC_SUBST(HA_RSCTMPDIR) dnl Eventually move out of the heartbeat dir tree and create symlinks when needed HA_VARLIBHBDIR=${localstatedir}/lib/heartbeat AC_DEFINE_UNQUOTED(HA_VARLIBHBDIR,"$HA_VARLIBHBDIR", Whatever this used to mean) AC_SUBST(HA_VARLIBHBDIR) OCF_RA_DIR="${OCF_ROOT_DIR}/resource.d" AC_DEFINE_UNQUOTED(OCF_RA_DIR,"$OCF_RA_DIR", Location for OCF RAs) AC_SUBST(OCF_RA_DIR) OCF_RA_DIR_PREFIX="$OCF_RA_DIR" AC_SUBST(OCF_RA_DIR_PREFIX) OCF_LIB_DIR="${OCF_ROOT_DIR}/lib" AC_DEFINE_UNQUOTED(OCF_LIB_DIR,"$OCF_LIB_DIR", Location for shared code for OCF RAs) AC_SUBST(OCF_LIB_DIR) OCF_LIB_DIR_PREFIX="$OCF_LIB_DIR" AC_SUBST(OCF_LIB_DIR_PREFIX) dnl =============================================== dnl rgmanager ras bits dnl =============================================== LOGDIR=${localstatedir}/log/cluster CLUSTERDATA=${datadir}/cluster AC_SUBST([LOGDIR]) AC_SUBST([CLUSTERDATA]) dnl =============================================== dnl Program Paths dnl =============================================== PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin" export PATH AC_CHECK_PROGS(MAKE, gmake make) AC_CHECK_PROGS(SHELLCHECK, shellcheck) AM_CONDITIONAL(CI_CHECKS, test "x$SHELLCHECK" != "x" ) AC_PATH_PROGS(BASH_SHELL, bash) if test x"${BASH_SHELL}" = x""; then AC_MSG_ERROR(You need bash installed in order to build ${PACKAGE}) fi AC_PATH_PROGS(XSLTPROC, xsltproc) AM_CONDITIONAL(BUILD_DOC, test "x$XSLTPROC" != "x" ) if test "x$XSLTPROC" = "x"; then AC_MSG_WARN([xsltproc not installed, unable to (re-)build manual pages]) fi AC_SUBST(XSLTPROC) AC_PATH_PROGS(XMLCATALOG, xmlcatalog) AC_PATH_PROGS(SSH, ssh, /usr/bin/ssh) AC_PATH_PROGS(SCP, scp, /usr/bin/scp) AC_PATH_PROGS(TAR, tar) AC_PATH_PROGS(MD5, md5) AC_PATH_PROGS(TEST, test) AC_PATH_PROGS(PING, ping, /bin/ping) AC_PATH_PROGS(IFCONFIG, ifconfig, /sbin/ifconfig) AC_PATH_PROGS(MAILCMD, mailx mail, mail) AC_PATH_PROGS(EGREP, egrep) AC_PATH_PROGS(RM, rm) AC_SUBST(BASH_SHELL) AC_SUBST(MAILCMD) AC_SUBST(EGREP) AC_SUBST(SHELL) AC_SUBST(PING) AC_SUBST(RM) AC_SUBST(TEST) dnl Ensure PYTHON is an absolute path AC_PATH_PROG([PYTHON], [$PYTHON]) AM_PATH_PYTHON if test -z "$PYTHON"; then echo "*** Essential program python not found" 1>&2 fi AC_PYTHON_MODULE(json) AC_PYTHON_MODULE(pyroute2) AS_VERSION_COMPARE([$PYTHON_VERSION], [2.7], [BUILD_OCF_PY=0], [BUILD_OCF_PY=1], [BUILD_OCF_PY=1]) BUILD_AZURE_EVENTS=1 if test -z "$PYTHON" || test $BUILD_OCF_PY -eq 0; then BUILD_AZURE_EVENTS=0 AC_MSG_WARN("Not building azure-events") fi AM_CONDITIONAL(BUILD_AZURE_EVENTS, test $BUILD_AZURE_EVENTS -eq 1) BUILD_AZURE_EVENTS_AZ=1 if test -z "$PYTHON" || test $BUILD_OCF_PY -eq 0; then BUILD_AZURE_EVENTS_AZ=0 AC_MSG_WARN("Not building azure-events-az") fi AM_CONDITIONAL(BUILD_AZURE_EVENTS_AZ, test $BUILD_AZURE_EVENTS_AZ -eq 1) BUILD_GCP_PD_MOVE=1 if test -z "$PYTHON" || test $BUILD_OCF_PY -eq 0; then BUILD_GCP_PD_MOVE=0 AC_MSG_WARN("Not building gcp-pd-move") fi AM_CONDITIONAL(BUILD_GCP_PD_MOVE, test $BUILD_GCP_PD_MOVE -eq 1) BUILD_GCP_VPC_MOVE_ROUTE=1 if test -z "$PYTHON" || test "x${HAVE_PYMOD_PYROUTE2}" != xyes || test $BUILD_OCF_PY -eq 0; then BUILD_GCP_VPC_MOVE_ROUTE=0 AC_MSG_WARN("Not building gcp-vpc-move-route") fi AM_CONDITIONAL(BUILD_GCP_VPC_MOVE_ROUTE, test $BUILD_GCP_VPC_MOVE_ROUTE -eq 1) BUILD_GCP_VPC_MOVE_VIP=1 if test -z "$PYTHON" || test $BUILD_OCF_PY -eq 0; then BUILD_GCP_VPC_MOVE_VIP=0 AC_MSG_WARN("Not building gcp-vpc-move-vip") fi AM_CONDITIONAL(BUILD_GCP_VPC_MOVE_VIP, test $BUILD_GCP_VPC_MOVE_VIP -eq 1) AC_PATH_PROGS(ROUTE, route) AC_DEFINE_UNQUOTED(ROUTE, "$ROUTE", path to route command) AC_MSG_CHECKING(ifconfig option to list interfaces) for IFCONFIG_A_OPT in "-A" "-a" "" do $IFCONFIG $IFCONFIG_A_OPT > /dev/null 2>&1 if test "$?" = 0 then AC_DEFINE_UNQUOTED(IFCONFIG_A_OPT, "$IFCONFIG_A_OPT", option for ifconfig command) AC_MSG_RESULT($IFCONFIG_A_OPT) break fi done AC_SUBST(IFCONFIG_A_OPT) if test x"${MAKE}" = x""; then AC_MSG_ERROR(You need (g)make installed in order to build ${PACKAGE}) fi STYLESHEET_PREFIX="" if test x"${XSLTPROC}" != x""; then AC_MSG_CHECKING(docbook to manpage transform) # first try to figure out correct template using xmlcatalog query, # resort to extensive (semi-deterministic) file search if that fails DOCBOOK_XSL_URI='http://docbook.sourceforge.net/release/xsl/current' DOCBOOK_XSL_PATH='manpages/docbook.xsl' STYLESHEET_PREFIX=$(${XMLCATALOG} "" ${DOCBOOK_XSL_URI} \ | sed -n 's|^file://||p;q') if test x"${STYLESHEET_PREFIX}" = x""; then DIRS=$(find "${datadir}" -name $(basename $(dirname ${DOCBOOK_XSL_PATH})) \ -type d | LC_ALL=C sort) if test x"${DIRS}" = x""; then # when datadir is not standard OS path, we cannot find docbook.xsl # use standard OS path as backup DIRS=$(find "/usr/share" "/usr/local/share" -name $(basename $(dirname ${DOCBOOK_XSL_PATH})) \ -type d | LC_ALL=C sort) fi XSLT=$(basename ${DOCBOOK_XSL_PATH}) for d in ${DIRS}; do if test -f "${d}/${XSLT}"; then STYLESHEET_PREFIX=$(echo "${d}" | sed 's/\/manpages//') break fi done fi if test x"${STYLESHEET_PREFIX}" = x""; then AC_MSG_ERROR(You need docbook-style-xsl installed in order to build ${PACKAGE}) fi fi AC_MSG_RESULT($STYLESHEET_PREFIX) AC_SUBST(STYLESHEET_PREFIX) dnl =============================================== dnl Libraries dnl =============================================== AC_CHECK_LIB(socket, socket) AC_CHECK_LIB(gnugetopt, getopt_long) dnl if available if test "x${enable_thread_safe}" = "xyes"; then GPKGNAME="gthread-2.0" else GPKGNAME="glib-2.0" fi PKG_CHECK_MODULES([GLIB], [$GPKGNAME]) CPPFLAGS="$CPPFLAGS $GLIB_CFLAGS" LIBS="$LIBS $GLIB_LIBS" +PKG_CHECK_MODULES([LIBQB], "libqb") dnl ======================================================================== dnl Headers dnl ======================================================================== AC_HEADER_STDC AC_CHECK_HEADERS(sys/socket.h) AC_CHECK_HEADERS(sys/sockio.h) AC_CHECK_HEADERS([arpa/inet.h]) AC_CHECK_HEADERS([fcntl.h]) AC_CHECK_HEADERS([limits.h]) AC_CHECK_HEADERS([malloc.h]) AC_CHECK_HEADERS([netdb.h]) AC_CHECK_HEADERS([netinet/in.h]) AC_CHECK_HEADERS([sys/file.h]) AC_CHECK_HEADERS([sys/ioctl.h]) AC_CHECK_HEADERS([sys/param.h]) AC_CHECK_HEADERS([sys/time.h]) AC_CHECK_HEADERS([syslog.h]) dnl ======================================================================== dnl Functions dnl ======================================================================== AC_FUNC_FORK AC_FUNC_STRNLEN AC_CHECK_FUNCS([alarm gettimeofday inet_ntoa memset mkdir socket uname]) AC_CHECK_FUNCS([strcasecmp strchr strdup strerror strrchr strspn strstr strtol strtoul]) AC_PATH_PROGS(REBOOT, reboot, /sbin/reboot) AC_SUBST(REBOOT) AC_SUBST(REBOOT_OPTIONS) AC_DEFINE_UNQUOTED(REBOOT, "$REBOOT", path to the reboot command) AC_DEFINE_UNQUOTED(REBOOT_OPTIONS, "$REBOOT_OPTIONS", reboot options) AC_PATH_PROGS(POWEROFF_CMD, poweroff, /sbin/poweroff) AC_SUBST(POWEROFF_CMD) AC_SUBST(POWEROFF_OPTIONS) AC_DEFINE_UNQUOTED(POWEROFF_CMD, "$POWEROFF_CMD", path to the poweroff command) AC_DEFINE_UNQUOTED(POWEROFF_OPTIONS, "$POWEROFF_OPTIONS", poweroff options) AC_PATH_PROGS(POD2MAN, pod2man) AM_CONDITIONAL(BUILD_POD_DOC, test "x$POD2MAN" != "x" ) if test "x$POD2MAN" = "x"; then AC_MSG_WARN([pod2man not installed, unable to (re-)build ldirector manual page]) fi AC_SUBST(POD2MAN) dnl ======================================================================== dnl Functions dnl ======================================================================== AC_CHECK_FUNCS(getopt, AC_DEFINE(HAVE_DECL_GETOPT, 1, [Have getopt function])) dnl ======================================================================== dnl sfex dnl ======================================================================== build_sfex=no case $host_os in *Linux*|*linux*) if test "$ac_cv_header_heartbeat_glue_config_h" = "yes"; then build_sfex=yes fi ;; esac AM_CONDITIONAL(BUILD_SFEX, test "$build_sfex" = "yes" ) dnl ======================================================================== dnl tickle (needs port to BSD platforms) dnl ======================================================================== AC_CHECK_MEMBERS([struct iphdr.saddr],,,[[#include ]]) AM_CONDITIONAL(BUILD_TICKLE, test "$ac_cv_member_struct_iphdr_saddr" = "yes" ) dnl ======================================================================== dnl libnet dnl ======================================================================== libnet="" libnet_version="none" LIBNETLIBS="" LIBNETDEFINES="" AC_MSG_CHECKING(if libnet is required) libnet_fatal=$enable_libnet case $enable_libnet in no) ;; yes|libnet10|libnet11|10|11) libnet_fatal=yes;; try) case $host_os in *Linux*|*linux*) libnet_fatal=no;; *) libnet_fatal=yes;; dnl legacy behavior esac ;; *) libnet_fatal=yes; enable_libnet=try;; esac AC_MSG_RESULT($libnet_fatal) if test "x$enable_libnet" != "xno"; then AC_PATH_PROGS(LIBNETCONFIG, libnet-config) AC_CHECK_LIB(nsl, t_open) dnl -lnsl AC_CHECK_LIB(socket, socket) dnl -lsocket AC_CHECK_LIB(net, libnet_get_hwaddr, LIBNETLIBS=" -lnet", []) fi AC_MSG_CHECKING(for libnet) if test "x$LIBNETLIBS" != "x" -o "x$enable_libnet" = "xlibnet11"; then LIBNETDEFINES="" if test "$ac_cv_lib_nsl_t_open" = yes; then LIBNETLIBS="-lnsl $LIBNETLIBS" fi if test "$ac_cv_lib_socket_socket" = yes; then LIBNETLIBS="-lsocket $LIBNETLIBS" fi libnet=net libnet_version="libnet1.1" fi if test "x$enable_libnet" = "xtry" -o "x$enable_libnet" = "xlibnet10"; then if test "x$LIBNETLIBS" = x -a "x${LIBNETCONFIG}" != "x" ; then LIBNETDEFINES="`$LIBNETCONFIG --defines` `$LIBNETCONFIG --cflags`"; LIBNETLIBS="`$LIBNETCONFIG --libs`"; libnet_version="libnet1.0 (old)" case $LIBNETLIBS in *-l*) libnet=`echo $LIBNETLIBS | sed 's%.*-l%%'`;; *) libnet_version=none;; esac CPPFLAGS="$CPPFLAGS $LIBNETDEFINES" AC_CHECK_HEADERS(libnet.h) if test "$ac_cv_header_libnet_h" = no; then libnet_version=none fi fi fi AC_MSG_RESULT(found $libnet_version) if test "$libnet_version" = none; then LIBNETLIBS="" LIBNETDEFINES="" if test $libnet_fatal = yes; then AC_MSG_ERROR(libnet not found) fi else AC_CHECK_LIB($libnet,libnet_init, [new_libnet=yes; AC_DEFINE(HAVE_LIBNET_1_1_API, 1, Libnet 1.1 API)], [new_libnet=no; AC_DEFINE(HAVE_LIBNET_1_0_API, 1, Libnet 1.0 API)],$LIBNETLIBS) AC_SUBST(LIBNETLIBS) fi if test "$new_libnet" = yes; then AC_MSG_CHECKING(for libnet API 1.1.4: ) save_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -fgnu89-inline -Wall -Werror" AC_COMPILE_IFELSE([ AC_LANG_SOURCE(#include int main(){libnet_t *l=NULL; libnet_pblock_record_ip_offset(l, l->total_size); return(0); })], [AC_MSG_RESULT(no)], [AC_DEFINE(HAVE_LIBNET_1_1_4_API, 1, Libnet 1.1.4 API) AC_MSG_RESULT(yes)]) CFLAGS="$save_CFLAGS" fi sendarp_linux=0 case $host_os in *Linux*|*linux*) sendarp_linux=1;; esac redhat_based=0 AC_CHECK_FILE(/etc/redhat-release, [redhat_based=1]) AC_SUBST(LIBNETLIBS) AC_SUBST(LIBNETDEFINES) AM_CONDITIONAL(SENDARP_LINUX, test $sendarp_linux = 1 ) AM_CONDITIONAL(USE_LIBNET, test "x$libnet_version" != "xnone" ) AM_CONDITIONAL(NFSCONVERT, test $redhat_based = 1 ) dnl ************************************************************************ dnl * Check for netinet/icmp6.h to enable the IPv6addr resource agent AC_CHECK_HEADERS(netinet/icmp6.h,[],[],[#include ]) AM_CONDITIONAL(USE_IPV6ADDR_AGENT, test "$ac_cv_header_netinet_icmp6_h" = yes && test "$ac_cv_header_heartbeat_glue_config_h" = yes) AM_CONDITIONAL(IPV6ADDR_COMPATIBLE, test "$ac_cv_header_netinet_icmp6_h" = yes) dnl ======================================================================== dnl Compiler flags dnl ======================================================================== dnl Make sure that CFLAGS is not exported. If the user did dnl not have CFLAGS in their environment then this should have dnl no effect. However if CFLAGS was exported from the user's dnl environment, then the new CFLAGS will also be exported dnl to sub processes. CC_ERRORS="" CC_EXTRAS="" if export -p | fgrep " CFLAGS=" > /dev/null; then SAVED_CFLAGS="$CFLAGS" unset CFLAGS CFLAGS="$SAVED_CFLAGS" unset SAVED_CFLAGS fi if test "$GCC" != yes; then CFLAGS="$CFLAGS -g" enable_fatal_warnings=no else CFLAGS="$CFLAGS -ggdb3" # We had to eliminate -Wnested-externs because of libtool changes # Also remove -Waggregate-return because we use one libnet # call which returns a struct EXTRA_FLAGS="-fgnu89-inline -fstack-protector-all -Wall -Wbad-function-cast -Wcast-qual -Wdeclaration-after-statement -Wendif-labels -Wfloat-equal -Wformat=2 -Wformat-security -Wformat-nonliteral -Winline -Wmissing-prototypes -Wmissing-declarations -Wmissing-format-attribute -Wnested-externs -Wno-long-long -Wno-strict-aliasing -Wpointer-arith -Wstrict-prototypes -Wunsigned-char -Wwrite-strings -Wno-maybe-uninitialized" # Additional warnings it might be nice to enable one day # -Wshadow # -Wunreachable-code for j in $EXTRA_FLAGS do if cc_supports_flag $j then CC_EXTRAS="$CC_EXTRAS $j" fi done dnl In lib/ais/Makefile.am there's a gcc option available as of v4.x GCC_MAJOR=`gcc -v 2>&1 | awk 'END{print $3}' | sed 's/[.].*//'` AM_CONDITIONAL(GCC_4, test "${GCC_MAJOR}" = 4) dnl System specific options case "$host_os" in *linux*|*bsd*) if test "${enable_fatal_warnings}" = "unknown"; then enable_fatal_warnings=yes fi ;; esac if test "x${enable_fatal_warnings}" != xno && cc_supports_flag -Werror ; then enable_fatal_warnings=yes else enable_fatal_warnings=no fi if test "x${enable_ansi}" != xno && cc_supports_flag -std=iso9899:199409 ; then AC_MSG_NOTICE(Enabling ANSI Compatibility) CC_EXTRAS="$CC_EXTRAS -ansi -D_GNU_SOURCE -DANSI_ONLY" fi AC_MSG_NOTICE(Activated additional gcc flags: ${CC_EXTRAS}) fi CFLAGS="$CFLAGS $CC_EXTRAS" NON_FATAL_CFLAGS="$CFLAGS" AC_SUBST(NON_FATAL_CFLAGS) dnl dnl We reset CFLAGS to include our warnings *after* all function dnl checking goes on, so that our warning flags don't keep the dnl AC_*FUNCS() calls above from working. In particular, -Werror will dnl *always* cause us troubles if we set it before here. dnl dnl if test "x${enable_fatal_warnings}" = xyes ; then AC_MSG_NOTICE(Enabling Fatal Warnings) CFLAGS="$CFLAGS -Werror" fi AC_SUBST(CFLAGS) dnl This is useful for use in Makefiles that need to remove one specific flag CFLAGS_COPY="$CFLAGS" AC_SUBST(CFLAGS_COPY) AC_SUBST(LOCALE) AC_SUBST(CC) AC_SUBST(MAKE) dnl The Makefiles and shell scripts we output AC_CONFIG_FILES(Makefile \ resource-agents.pc \ include/Makefile \ heartbeat/Makefile \ heartbeat/ocf-binaries \ heartbeat/ocf-directories \ heartbeat/ocf-shellfuncs \ heartbeat/shellfuncs \ systemd/Makefile \ systemd/resource-agents.conf \ tools/Makefile \ tools/nfsconvert \ tools/ocf-tester \ tools/ocft/Makefile \ tools/ocft/ocft \ tools/ocft/caselib \ tools/ocft/README \ tools/ocft/README.zh_CN \ ldirectord/Makefile \ ldirectord/ldirectord \ ldirectord/init.d/Makefile \ ldirectord/init.d/ldirectord \ ldirectord/init.d/ldirectord.debian \ ldirectord/init.d/ldirectord.debian.default \ ldirectord/systemd/Makefile \ ldirectord/systemd/ldirectord.service \ ldirectord/logrotate.d/Makefile \ ldirectord/OCF/Makefile \ ldirectord/OCF/ldirectord \ doc/Makefile \ doc/man/Makefile \ rgmanager/Makefile \ rgmanager/src/Makefile \ rgmanager/src/resources/Makefile \ rgmanager/src/resources/ocf-shellfuncs \ rgmanager/src/resources/svclib_nfslock \ rgmanager/src/resources/lvm_by_lv.sh \ rgmanager/src/resources/lvm_by_vg.sh \ rgmanager/src/resources/utils/Makefile \ rgmanager/src/resources/utils/fs-lib.sh \ rgmanager/src/resources/utils/messages.sh \ rgmanager/src/resources/utils/config-utils.sh \ rgmanager/src/resources/utils/member_util.sh \ rgmanager/src/resources/utils/ra-skelet.sh \ ) dnl Files we output that need to be executable AC_CONFIG_FILES([heartbeat/azure-events], [chmod +x heartbeat/azure-events]) AC_CONFIG_FILES([heartbeat/azure-events-az], [chmod +x heartbeat/azure-events-az]) AC_CONFIG_FILES([heartbeat/AoEtarget], [chmod +x heartbeat/AoEtarget]) AC_CONFIG_FILES([heartbeat/ManageRAID], [chmod +x heartbeat/ManageRAID]) AC_CONFIG_FILES([heartbeat/ManageVE], [chmod +x heartbeat/ManageVE]) AC_CONFIG_FILES([heartbeat/Squid], [chmod +x heartbeat/Squid]) AC_CONFIG_FILES([heartbeat/SysInfo], [chmod +x heartbeat/SysInfo]) AC_CONFIG_FILES([heartbeat/aws-vpc-route53], [chmod +x heartbeat/aws-vpc-route53]) AC_CONFIG_FILES([heartbeat/clvm], [chmod +x heartbeat/clvm]) AC_CONFIG_FILES([heartbeat/conntrackd], [chmod +x heartbeat/conntrackd]) AC_CONFIG_FILES([heartbeat/dnsupdate], [chmod +x heartbeat/dnsupdate]) AC_CONFIG_FILES([heartbeat/dummypy], [chmod +x heartbeat/dummypy]) AC_CONFIG_FILES([heartbeat/eDir88], [chmod +x heartbeat/eDir88]) AC_CONFIG_FILES([heartbeat/fio], [chmod +x heartbeat/fio]) AC_CONFIG_FILES([heartbeat/galera], [chmod +x heartbeat/galera]) AC_CONFIG_FILES([heartbeat/gcp-pd-move], [chmod +x heartbeat/gcp-pd-move]) AC_CONFIG_FILES([heartbeat/gcp-vpc-move-ip], [chmod +x heartbeat/gcp-vpc-move-ip]) AC_CONFIG_FILES([heartbeat/gcp-vpc-move-vip], [chmod +x heartbeat/gcp-vpc-move-vip]) AC_CONFIG_FILES([heartbeat/gcp-vpc-move-route], [chmod +x heartbeat/gcp-vpc-move-route]) AC_CONFIG_FILES([heartbeat/iSCSILogicalUnit], [chmod +x heartbeat/iSCSILogicalUnit]) AC_CONFIG_FILES([heartbeat/iSCSITarget], [chmod +x heartbeat/iSCSITarget]) AC_CONFIG_FILES([heartbeat/jira], [chmod +x heartbeat/jira]) AC_CONFIG_FILES([heartbeat/kamailio], [chmod +x heartbeat/kamailio]) AC_CONFIG_FILES([heartbeat/lxc], [chmod +x heartbeat/lxc]) AC_CONFIG_FILES([heartbeat/lxd-info], [chmod +x heartbeat/lxd-info]) AC_CONFIG_FILES([heartbeat/machine-info], [chmod +x heartbeat/machine-info]) AC_CONFIG_FILES([heartbeat/mariadb], [chmod +x heartbeat/mariadb]) AC_CONFIG_FILES([heartbeat/mpathpersist], [chmod +x heartbeat/mpathpersist]) AC_CONFIG_FILES([heartbeat/nfsnotify], [chmod +x heartbeat/nfsnotify]) AC_CONFIG_FILES([heartbeat/openstack-info], [chmod +x heartbeat/openstack-info]) AC_CONFIG_FILES([heartbeat/rabbitmq-cluster], [chmod +x heartbeat/rabbitmq-cluster]) AC_CONFIG_FILES([heartbeat/redis], [chmod +x heartbeat/redis]) AC_CONFIG_FILES([heartbeat/rsyslog], [chmod +x heartbeat/rsyslog]) AC_CONFIG_FILES([heartbeat/smb-share], [chmod +x heartbeat/smb-share]) AC_CONFIG_FILES([heartbeat/sg_persist], [chmod +x heartbeat/sg_persist]) AC_CONFIG_FILES([heartbeat/slapd], [chmod +x heartbeat/slapd]) AC_CONFIG_FILES([heartbeat/storage-mon], [chmod +x heartbeat/storage-mon]) AC_CONFIG_FILES([heartbeat/sybaseASE], [chmod +x heartbeat/sybaseASE]) AC_CONFIG_FILES([heartbeat/syslog-ng], [chmod +x heartbeat/syslog-ng]) AC_CONFIG_FILES([heartbeat/vsftpd], [chmod +x heartbeat/vsftpd]) AC_CONFIG_FILES([heartbeat/CTDB], [chmod +x heartbeat/CTDB]) AC_CONFIG_FILES([rgmanager/src/resources/ASEHAagent.sh], [chmod +x rgmanager/src/resources/ASEHAagent.sh]) AC_CONFIG_FILES([rgmanager/src/resources/apache.sh], [chmod +x rgmanager/src/resources/apache.sh]) AC_CONFIG_FILES([rgmanager/src/resources/bind-mount.sh], [chmod +x rgmanager/src/resources/bind-mount.sh]) AC_CONFIG_FILES([rgmanager/src/resources/clusterfs.sh], [chmod +x rgmanager/src/resources/clusterfs.sh]) AC_CONFIG_FILES([rgmanager/src/resources/db2.sh], [chmod +x rgmanager/src/resources/db2.sh]) AC_CONFIG_FILES([rgmanager/src/resources/drbd.sh], [chmod +x rgmanager/src/resources/drbd.sh]) AC_CONFIG_FILES([rgmanager/src/resources/fs.sh], [chmod +x rgmanager/src/resources/fs.sh]) AC_CONFIG_FILES([rgmanager/src/resources/ip.sh], [chmod +x rgmanager/src/resources/ip.sh]) AC_CONFIG_FILES([rgmanager/src/resources/lvm.sh], [chmod +x rgmanager/src/resources/lvm.sh]) AC_CONFIG_FILES([rgmanager/src/resources/mysql.sh], [chmod +x rgmanager/src/resources/mysql.sh]) AC_CONFIG_FILES([rgmanager/src/resources/named.sh], [chmod +x rgmanager/src/resources/named.sh]) AC_CONFIG_FILES([rgmanager/src/resources/netfs.sh], [chmod +x rgmanager/src/resources/netfs.sh]) AC_CONFIG_FILES([rgmanager/src/resources/nfsclient.sh], [chmod +x rgmanager/src/resources/nfsclient.sh]) AC_CONFIG_FILES([rgmanager/src/resources/nfsexport.sh], [chmod +x rgmanager/src/resources/nfsexport.sh]) AC_CONFIG_FILES([rgmanager/src/resources/nfsserver.sh], [chmod +x rgmanager/src/resources/nfsserver.sh]) AC_CONFIG_FILES([rgmanager/src/resources/openldap.sh], [chmod +x rgmanager/src/resources/openldap.sh]) AC_CONFIG_FILES([rgmanager/src/resources/oracledb.sh], [chmod +x rgmanager/src/resources/oracledb.sh]) AC_CONFIG_FILES([rgmanager/src/resources/oradg.sh], [chmod +x rgmanager/src/resources/oradg.sh]) AC_CONFIG_FILES([rgmanager/src/resources/orainstance.sh], [chmod +x rgmanager/src/resources/orainstance.sh]) AC_CONFIG_FILES([rgmanager/src/resources/oralistener.sh], [chmod +x rgmanager/src/resources/oralistener.sh]) AC_CONFIG_FILES([rgmanager/src/resources/postgres-8.sh], [chmod +x rgmanager/src/resources/postgres-8.sh]) AC_CONFIG_FILES([rgmanager/src/resources/samba.sh], [chmod +x rgmanager/src/resources/samba.sh]) AC_CONFIG_FILES([rgmanager/src/resources/script.sh], [chmod +x rgmanager/src/resources/script.sh]) AC_CONFIG_FILES([rgmanager/src/resources/service.sh], [chmod +x rgmanager/src/resources/service.sh]) AC_CONFIG_FILES([rgmanager/src/resources/smb.sh], [chmod +x rgmanager/src/resources/smb.sh]) AC_CONFIG_FILES([rgmanager/src/resources/tomcat-5.sh], [chmod +x rgmanager/src/resources/tomcat-5.sh]) AC_CONFIG_FILES([rgmanager/src/resources/tomcat-6.sh], [chmod +x rgmanager/src/resources/tomcat-6.sh]) AC_CONFIG_FILES([rgmanager/src/resources/vm.sh], [chmod +x rgmanager/src/resources/vm.sh]) dnl Now process the entire list of files added by previous dnl calls to AC_CONFIG_FILES() AC_OUTPUT() dnl ***************** dnl Configure summary dnl ***************** AC_MSG_RESULT([]) AC_MSG_RESULT([$PACKAGE configuration:]) AC_MSG_RESULT([ Version = ${VERSION}]) AC_MSG_RESULT([ Build Version = $Format:%H$]) AC_MSG_RESULT([]) AC_MSG_RESULT([ Prefix = ${prefix}]) AC_MSG_RESULT([ Executables = ${sbindir}]) AC_MSG_RESULT([ Man pages = ${mandir}]) AC_MSG_RESULT([ Libraries = ${libdir}]) AC_MSG_RESULT([ Header files = ${includedir}]) AC_MSG_RESULT([ Arch-independent files = ${datadir}]) AC_MSG_RESULT([ Documentation = ${docdir}]) AC_MSG_RESULT([ State information = ${localstatedir}]) AC_MSG_RESULT([ System configuration = ${sysconfdir}]) AC_MSG_RESULT([ HA_BIN directory prefix = ${libexecdir}]) AC_MSG_RESULT([ RA state files = ${HA_RSCTMPDIR}]) AC_MSG_RESULT([ AIS Plugins = ${LCRSODIR}]) AC_MSG_RESULT([]) AC_MSG_RESULT([ CPPFLAGS = ${CPPFLAGS}]) AC_MSG_RESULT([ CFLAGS = ${CFLAGS}]) AC_MSG_RESULT([ Libraries = ${LIBS}]) AC_MSG_RESULT([ Stack Libraries = ${CLUSTERLIBS}]) diff --git a/heartbeat/storage-mon.in b/heartbeat/storage-mon.in index d764b49d7..81d8f5bce 100644 --- a/heartbeat/storage-mon.in +++ b/heartbeat/storage-mon.in @@ -1,263 +1,381 @@ #!@BASH_SHELL@ # # Copyright (C) 2021 Red Hat, Inc. All rights reserved. # # Authors: Christine Caulfield # Fabio M. Di Nitto # # 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. # # # Checks storage I/O status of all given drives and writes the #health-storage # status into the CIB # Implementation is heavily based on ocf:pacemaker:HealtSMART # # It sends a single block on IO to a radom location on the device and reports any errors returned. # If the IO hangs, that will also be returned. (bear in mind tha tmay also hang the C app in some # instances). # # It's worth making a note in the RA description that the smartmon RA is also recommended (this # does not replace it), and that Pacemaker health checking should be configued. # # https://clusterlabs.org/pacemaker/doc/2.1/Pacemaker_Explained/singlehtml/index.html#tracking-node-health ####################################################################### ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs # -STORAGEMON=$HA_BIN/storage_mon -ATTRDUP=/usr/sbin/attrd_updater +STORAGEMON=${HA_BIN}/storage_mon +ATTRDUP=${HA_SBIN_DIR}/attrd_updater +PIDFILE=${HA_VARRUN}/storage-mon-${OCF_RESOURCE_INSTANCE}.pid +ATTRNAME="#health-${OCF_RESOURCE_INSTANCE}" OCF_RESKEY_CRM_meta_interval_default="0" OCF_RESKEY_io_timeout_default="10" +OCF_RESKEY_check_interval_default="30" OCF_RESKEY_inject_errors_default="" OCF_RESKEY_state_file_default="${HA_RSCTMP%%/}/storage-mon-${OCF_RESOURCE_INSTANCE}.state" +OCF_RESKEY_daemonize_default="" # Explicitly list all environment variables used, to make static analysis happy : ${OCF_RESKEY_CRM_meta_interval:=${OCF_RESKEY_CRM_meta_interval_default}} : ${OCF_RESKEY_drives:=""} : ${OCF_RESKEY_io_timeout:=${OCF_RESKEY_io_timeout_default}} +: ${OCF_RESKEY_check_interval:=${OCF_RESKEY_check_interval_default}} : ${OCF_RESKEY_inject_errors:=${OCF_RESKEY_inject_errors_default}} : ${OCF_RESKEY_state_file:=${OCF_RESKEY_state_file_default}} +: ${OCF_RESKEY_daemonize:=${OCF_RESKEY_daemonize_default}} ####################################################################### meta_data() { cat < 1.0 System health agent that checks the storage I/O status of the given drives and updates the #health-storage attribute. Usage is highly recommended in combination with the HealthSMART monitoring agent. The agent currently support a maximum of 25 devices per instance. storage I/O health status Location to store the resource state in. State file The drive(s) to check as a SPACE separated list. Enter the full path to the device, e.g. "/dev/sda". Drives to check Specify disk I/O timeout in seconds. Minimum 1, recommended 10 (default). Disk I/O timeout + + +Specify interval between I/O checks in seconds.(Only supported with the damonize option.) + +I/O check interval + + + Used only for testing! Specify % of I/O errors to simulate drives failures. Specify % of I/O errors to simulate drives failures + + +Specifies to start storage-mon as a daemon and check for devices. + +start storage-mon with daemon + + + END return $OCF_SUCCESS } ####################################################################### storage-mon_usage() { cat < /dev/null 2>&1 + case "$?" in + 0) rc=$OCF_SUCCESS;; + 1|2) rc=$OCF_NOT_RUNNING;; + *) rc=$OCF_ERR_GENERIC;; + esac + + if [ $rc -ne $OCF_SUCCESS ]; then + return "$rc" + fi + if [ "$1" = "pid_check_only" ]; then + return "$rc" + fi - "$ATTRDUP" -n "#health-${OCF_RESOURCE_INSTANCE}" -U "$status" -d "5s" - return $OCF_SUCCESS + # generate client command line + cmdline="" + cmdline="$cmdline --client --attrname ${ATTRNAME}" + while : + do + # 0 : Normal. + # greater than 0 : monitoring error. + # 255(-1) : communication system error. + # 254(-2) : Not all checks completed for first device in daemon mode. + $STORAGEMON $cmdline + rc=$? + case "$rc" in + 254|255) + # If there is a communication error or the initial check of all devices has not been completed, + # it will loop and try to reconnect. + # When everything ends with a communication error during monitor, a monitor timeout occurs. + ocf_log debug "client monitor error : $rc" + ;; + 0) + status="green" + break + ;; + *) + status="red" + break + ;; + esac + done + + "$ATTRDUP" -n ${ATTRNAME} -U "$status" -d "5s" + return $OCF_SUCCESS + fi } storage-mon_start() { - storage-mon_monitor - if [ $? -eq $OCF_SUCCESS ]; then - return $OCF_SUCCESS + if [ -z "$OCF_RESKEY_daemonize" ]; then + storage-mon_monitor + if [ $? -eq $OCF_SUCCESS ]; then + return $OCF_SUCCESS + fi + touch "${OCF_RESKEY_state_file}" + else + storage-mon_init + # generate command line + cmdline="" + for DRIVE in ${OCF_RESKEY_drives}; do + cmdline="$cmdline --device $DRIVE --score 1" + done + #cmdline="$cmdline --daemonize --timeout ${OCF_RESKEY_io_timeout} --interval ${OCF_RESKEY_check_interval} --pidfile ${PIDFILE} --attrname ${ATTRNAME} --ha-sbin-dir ${HA_SBIN_DIR}" + cmdline="$cmdline --daemonize --timeout ${OCF_RESKEY_io_timeout} --interval ${OCF_RESKEY_check_interval} --pidfile ${PIDFILE} --attrname ${ATTRNAME}" + if [ -n "${OCF_RESKEY_inject_errors}" ]; then + cmdline="$cmdline --inject-errors-percent ${OCF_RESKEY_inject_errors}" + fi + $STORAGEMON $cmdline + if [ "$?" -ne 0 ]; then + return $OCF_ERR_GENERIC + fi fi - touch "${OCF_RESKEY_state_file}" } storage-mon_stop() { storage-mon_monitor - if [ $? -eq $OCF_SUCCESS ]; then - rm "${OCF_RESKEY_state_file}" + rc=$? + + if [ -z "$OCF_RESKEY_daemonize" ]; then + if [ $rc -eq $OCF_SUCCESS ]; then + rm "${OCF_RESKEY_state_file}" + fi + else + case "$rc" in + $OCF_SUCCESS) + ;; + $OCF_NOT_RUNNING) + return "$OCF_SUCCESS";; + *) + return "$rc";; + esac + + kill -TERM $(cat "${PIDFILE}") + if [ "$?" -ne 0 ]; then + return $OCF_ERR_GENERIC + fi + + while true; do + storage-mon_monitor pid_check_only + rc="$?" + case "$rc" in + $OCF_SUCCESS) + ;; + $OCF_NOT_RUNNING) + return "$OCF_SUCCESS";; + *) + return "$rc";; + esac + sleep 1 + done fi return $OCF_SUCCESS } storage-mon_validate() { storage-mon_init - # Is the state directory writable? - state_dir=$(dirname "${OCF_RESKEY_state_file}") - touch "$state_dir/$$" - if [ $? -ne 0 ]; then - return $OCF_ERR_CONFIGURED + if [ -z "$OCF_RESKEY_daemonize" ]; then + # Is the state directory writable? + state_dir=$(dirname "${OCF_RESKEY_state_file}") + touch "$state_dir/$$" + if [ $? -ne 0 ]; then + return $OCF_ERR_CONFIGURED + fi + rm "$state_dir/$$" fi - rm "$state_dir/$$" return $OCF_SUCCESS } case "$__OCF_ACTION" in start) storage-mon_start;; stop) storage-mon_stop;; monitor) storage-mon_monitor;; validate-all) storage-mon_validate;; meta-data) meta_data;; usage|help) storage-mon_usage $OCF_SUCCESS;; *) storage-mon_usage $OCF_ERR_UNIMPLEMENTED;; esac rc=$? ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc" exit $rc # vim: set filetype=sh: diff --git a/resource-agents.spec.in b/resource-agents.spec.in index 2ffa00d94..1cbf28c03 100644 --- a/resource-agents.spec.in +++ b/resource-agents.spec.in @@ -1,385 +1,385 @@ # # 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@ # Whether this platform defaults to using systemd as an init system # (needs to be evaluated prior to BuildRequires being enumerated and # installed as it's intended to conditionally select some of these, and # for that there are only few indicators with varying reliability: # - presence of systemd-defined macros (when building in a full-fledged # environment, which is not the case with ordinary mock-based builds) # - systemd-aware rpm as manifested with the presence of particular # macro (rpm itself will trivially always be present when building) # - existence of /usr/lib/os-release file, which is something heavily # propagated by systemd project # - when not good enough, there's always a possibility to check # particular distro-specific macros (incl. version comparison) %define systemd_native (%{?_unitdir:1}%{!?_unitdir:0}%{nil \ } || %{?__transaction_systemd_inhibit:1}%{!?__transaction_systemd_inhibit:0}%{nil \ } || %(test -f /usr/lib/os-release; test $? -ne 0; echo $?)) # 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 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: GPL-2.0-or-later AND LGPL-2.1-or-later URL: https://github.com/ClusterLabs/resource-agents Source0: %{name}-%{version}%{?rcver:%{rcver}}%{?numcomm:.%{numcomm}}%{?alphatag:-%{alphatag}}%{?dirty:-%{dirty}}.tar.bz2 Obsoletes: heartbeat-resources <= %{version} Provides: heartbeat-resources = %{version} # Build dependencies BuildRequires: make BuildRequires: automake autoconf pkgconfig gcc BuildRequires: perl -BuildRequires: libxslt glib2-devel +BuildRequires: libxslt glib2-devel libqb-devel BuildRequires: systemd BuildRequires: which %if 0%{?fedora} || 0%{?centos} > 7 || 0%{?rhel} > 7 || 0%{?suse_version} BuildRequires: python3-devel %else BuildRequires: python-devel %endif %ifarch x86_64 %if 0%{?fedora} || 0%{?centos} > 7 || 0%{?rhel} > 7 BuildRequires: python3-pyroute2 %endif %endif %if 0%{?fedora} || 0%{?centos} || 0%{?rhel} BuildRequires: docbook-style-xsl docbook-dtds %if 0%{?rhel} == 0 BuildRequires: libnet-devel %endif %endif %if 0%{?suse_version} BuildRequires: libnet-devel %if 0%{?suse_version} > 1500 BuildRequires: cluster-glue-devel %else BuildRequires: libglue-devel %endif BuildRequires: libxslt docbook_4 docbook-xsl-stylesheets %endif ## Runtime deps # system tools shared by several agents Requires: /bin/bash /usr/bin/grep /bin/sed /bin/gawk Requires: /bin/ps /usr/bin/pkill /usr/bin/hostname /usr/bin/netstat Requires: /bin/mount %if 0%{?suse_version} Requires: /usr/bin/fuser %else Requires: /usr/sbin/fuser %endif # Filesystem / fs.sh / netfs.sh %if 0%{?suse_version} Requires: /usr/sbin/fsck %else Requires: /sbin/fsck %endif Requires: /usr/sbin/fsck.ext2 /usr/sbin/fsck.ext3 /usr/sbin/fsck.ext4 Requires: /usr/sbin/fsck.xfs %if 0%{?suse_version} Requires: /usr/sbin/mount.nfs /usr/sbin/mount.nfs4 %else Requires: /sbin/mount.nfs /sbin/mount.nfs4 %endif %if (0%{?fedora} && 0%{?fedora} < 33) || (0%{?rhel} && 0%{?rhel} < 9) || (0%{?centos} && 0%{?centos} < 9) || 0%{?suse_version} %if (0%{?rhel} && 0%{?rhel} < 8) || (0%{?centos} && 0%{?centos} < 8) Requires: /usr/sbin/mount.cifs %else Recommends: /usr/sbin/mount.cifs %endif %endif # IPaddr2 Requires: /sbin/ip # LVM / lvm.sh Requires: /usr/sbin/lvm # nfsserver / netfs.sh %if 0%{?suse_version} Requires: /usr/sbin/rpc.statd %else Requires: /sbin/rpc.statd %endif Requires: /usr/sbin/rpc.nfsd /usr/sbin/rpc.mountd # rgmanager %if %{with rgmanager} # ip.sh Requires: /usr/sbin/ethtool Requires: /sbin/rdisc /usr/sbin/arping /bin/ping /bin/ping6 # nfsexport.sh Requires: /sbin/findfs Requires: /sbin/quotaon /sbin/quotacheck %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: GPL-2.0-or-later Summary: A Monitoring Daemon for Maintaining High Availability Resources Obsoletes: heartbeat-ldirectord <= %{version} Provides: heartbeat-ldirectord = %{version} %if 0%{?fedora} > 18 || 0%{?centos} > 6 || 0%{?rhel} > 6 BuildRequires: perl-podlators %endif Requires: %{SSLeay} perl-libwww-perl perl-MailTools Requires: ipvsadm logrotate %if 0%{?fedora} Requires: perl-Net-IMAP-Simple-SSL perl-IO-Socket-INET6 %endif %if 0%{?fedora} < 34 Requires(post): /sbin/chkconfig Requires(preun): /sbin/chkconfig %endif %if %{systemd_native} BuildRequires: systemd %endif %{?systemd_requires} %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. ldirectord is simple to install and works with Pacemaker (http://clusterlabs.org/). See 'ldirectord -h' and linux-ha/doc/ldirectord for more information. %endif %prep %if 0%{?suse_version} == 0 && 0%{?fedora} == 0 && 0%{?centos} == 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 %autosetup -n %{name}-%{version}%{?rcver:%{rcver}}%{?numcomm:.%{numcomm}}%{?alphatag:-%{alphatag}}%{?dirty:-%{dirty}} -p1 %build if [ ! -f configure ]; then ./autogen.sh fi %if 0%{?fedora} >= 11 || 0%{?centos} > 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 \ %if 0%{?fedora} || 0%{?centos} > 7 || 0%{?rhel} > 7 || 0%{?suse_version} PYTHON="%{__python3}" \ %endif %{conf_opt_fatal} \ %if %{defined _unitdir} SYSTEMD_UNIT_DIR=%{_unitdir} \ %endif %if %{defined _tmpfilesdir} SYSTEMD_TMPFILES_DIR=%{_tmpfilesdir} \ --with-rsctmpdir=/run/resource-agents \ %endif --with-pkg-name=%{name} \ --with-ras-set=%{rasset} make %{_smp_mflags} %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 ln -sf /%{_sysconfdir}/init.d/ldirectord rcldirectord ) || true %endif %endif %files %doc AUTHORS COPYING COPYING.GPLv3 COPYING.LGPL ChangeLog %if %{with linuxha} %doc heartbeat/README.galera %doc doc/README.webapps %doc %{_datadir}/%{name}/ra-api-1.dtd %doc %{_datadir}/%{name}/metadata.rng %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 %{_datadir}/pkgconfig/%{name}.pc %if %{defined _unitdir} %{_unitdir}/resource-agents-deps.target %endif %if %{defined _tmpfilesdir} %{_tmpfilesdir}/%{name}.conf %endif %dir %{_datadir}/%{name} %dir %{_datadir}/%{name}/ocft %{_datadir}/%{name}/ocft/configs %{_datadir}/%{name}/ocft/caselib %{_datadir}/%{name}/ocft/README %{_datadir}/%{name}/ocft/README.zh_CN %{_datadir}/%{name}/ocft/helpers.sh %exclude %{_datadir}/%{name}/ocft/runocft %exclude %{_datadir}/%{name}/ocft/runocft.prereq %{_sbindir}/ocf-tester %{_sbindir}/ocft %if 0%{?suse_version} %{_sbindir}/sfex_* %endif %{_includedir}/heartbeat %if %{defined _tmpfilesdir} %dir %attr (1755, root, root) /run/resource-agents %else %dir %attr (1755, root, root) %{_var}/run/resource-agents %endif %{_mandir}/man7/*.7* %{_mandir}/man8/ocf-tester.8* %if 0%{?suse_version} %{_mandir}/man8/sfex_init.8* %endif # For compatability with pre-existing agents %dir %{_sysconfdir}/ha.d %{_sysconfdir}/ha.d/shellfuncs %{_libexecdir}/heartbeat %if %{with rgmanager} %post -n resource-agents ccs_update_schema > /dev/null 2>&1 ||: %endif %if 0%{?suse_version} %preun -n ldirectord %stop_on_removal ldirectord %postun -n ldirectord %insserv_cleanup %endif %if 0%{?fedora} %preun -n ldirectord %if %{defined _unitdir} %systemd_preun ldirectord.service %else /sbin/chkconfig --del ldirectord %endif %postun -n ldirectord /sbin/ldconfig %if %{defined _unitdir} %systemd_postun_with_restart ldirectord.service %endif %post -n ldirectord %if %{defined _unitdir} %systemd_post ldirectord.service %else /sbin/chkconfig --add ldirectord %endif %endif %endif %if %{with linuxha} %files -n ldirectord %{_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 %exclude %{_sysconfdir}/rc.d/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/Makefile.am b/tools/Makefile.am index 08323fee3..55e292cec 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,84 +1,85 @@ # # heartbeat: Linux-HA heartbeat code # # Copyright (C) 2001 Michael Moerz # # 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 SUBDIRS = ocft AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include halibdir = $(libexecdir)/heartbeat EXTRA_DIST = ocf-tester.8 sfex_init.8 sbin_PROGRAMS = sbin_SCRIPTS = ocf-tester halib_PROGRAMS = findif \ storage_mon halib_SCRIPTS = man8_MANS = ocf-tester.8 if BUILD_SFEX halib_PROGRAMS += sfex_daemon sbin_PROGRAMS += sfex_init sfex_stat man8_MANS += sfex_init.8 endif if USE_LIBNET halib_PROGRAMS += send_arp send_arp_SOURCES = send_arp.libnet.c send_arp_CFLAGS = @LIBNETDEFINES@ send_arp_LDADD = $(GLIBLIB) -lplumb @LIBNETLIBS@ else if SENDARP_LINUX halib_PROGRAMS += send_arp send_arp_SOURCES = send_arp.linux.c endif if NFSCONVERT halib_SCRIPTS += nfsconvert endif endif sfex_daemon_SOURCES = sfex_daemon.c sfex.h sfex_lib.c sfex_lib.h sfex_daemon_CFLAGS = -D_GNU_SOURCE sfex_daemon_LDADD = $(GLIBLIB) -lplumb -lplumbgpl sfex_init_SOURCES = sfex_init.c sfex.h sfex_lib.c sfex_lib.h sfex_init_CFLAGS = -D_GNU_SOURCE sfex_init_LDADD = $(GLIBLIB) -lplumb -lplumbgpl sfex_stat_SOURCES = sfex_stat.c sfex.h sfex_lib.c sfex_lib.h sfex_stat_CFLAGS = -D_GNU_SOURCE sfex_stat_LDADD = $(GLIBLIB) -lplumb -lplumbgpl findif_SOURCES = findif.c storage_mon_SOURCES = storage_mon.c -storage_mon_CFLAGS = -D_GNU_SOURCE +storage_mon_CFLAGS = -D_GNU_SOURCE ${LIBQB_CFLAGS} +storage_mon_LDADD = ${LIBQB_LIBS} if BUILD_TICKLE halib_PROGRAMS += tickle_tcp tickle_tcp_SOURCES = tickle_tcp.c endif .PHONY: install-exec-hook diff --git a/tools/storage_mon.c b/tools/storage_mon.c index b0e277cbe..1231570c8 100644 --- a/tools/storage_mon.c +++ b/tools/storage_mon.c @@ -1,312 +1,896 @@ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef __FreeBSD__ #include #endif +#include +#include +#include + +#include +#include +#include +#include +#include +#include #define MAX_DEVICES 25 #define DEFAULT_TIMEOUT 10 +#define DEFAULT_INTERVAL 30 +#define DEFAULT_PIDFILE HA_VARRUNDIR "storage_mon.pid" +#define DEFAULT_ATTRNAME "#health-storage_mon" +#define SMON_GET_RESULT_COMMAND "get_check_value" +#define SMON_RESULT_OK "green" +#define SMON_RESULT_NG "red" +#define SMON_RESULT_COMMAND_ERROR "unknown command" +#define SMON_BUFF_1MEG 1048576 +#define SMON_MAX_IPCSNAME 256 +#define SMON_MAX_MSGSIZE 128 +#define SMON_MAX_RESP_SIZE 100 + +#define PRINT_STORAGE_MON_ERR(fmt, ...) if (!daemonize) { \ + fprintf(stderr, fmt"\n", __VA_ARGS__); \ + } else { \ + syslog(LOG_ERR, fmt, __VA_ARGS__); \ + } +#define PRINT_STORAGE_MON_ERR_NOARGS(str) if (!daemonize) { \ + fprintf(stderr, str"\n"); \ + } else { \ + syslog(LOG_ERR, str); \ + } + +#define PRINT_STORAGE_MON_INFO(fmt, ...) if (!daemonize) { \ + printf(fmt"\n", __VA_ARGS__); \ + } else { \ + syslog(LOG_INFO, fmt, __VA_ARGS__); \ + } + +struct storage_mon_timer_data { + int interval; +}; + +struct storage_mon_check_value_req { + struct qb_ipc_request_header hdr; + char message[SMON_MAX_MSGSIZE]; +}; + + +struct storage_mon_check_value_res { + struct qb_ipc_response_header hdr; + char message[SMON_MAX_MSGSIZE]; +}; + + +char *devices[MAX_DEVICES]; +int scores[MAX_DEVICES]; +size_t device_count = 0; +int timeout = DEFAULT_TIMEOUT; +int verbose = 0; +int inject_error_percent = 0; +const char *attrname = DEFAULT_ATTRNAME; +gboolean daemonize = FALSE; +int shutting_down = FALSE; +static qb_ipcs_service_t *ipcs; +int final_score = 0; +int response_final_score = 0; +pid_t test_forks[MAX_DEVICES]; +size_t finished_count = 0; +gboolean daemon_check_first_all_devices = FALSE; + +static qb_loop_t *storage_mon_poll_handle; +static qb_loop_timer_handle timer_handle; +static qb_loop_timer_handle expire_handle; +static struct storage_mon_timer_data timer_d; + +static int test_device_main(gpointer data); +static void wrap_test_device_main(void *data); static void usage(char *name, FILE *f) { fprintf(f, "usage: %s [-hv] [-d ]... [-s ]... [-t ]\n", name); fprintf(f, " --device device to test, up to %d instances\n", MAX_DEVICES); fprintf(f, " --score score if device fails the test. Must match --device count\n"); fprintf(f, " --timeout max time to wait for a device test to come back. in seconds (default %d)\n", DEFAULT_TIMEOUT); fprintf(f, " --inject-errors-percent Generate EIO errors %% of the time (for testing only)\n"); + fprintf(f, " --daemonize test run in daemons.\n"); + fprintf(f, " --client client connection to daemon. requires the attrname option.\n"); + fprintf(f, " --interval interval to test. in seconds (default %d)(for daemonize only)\n", DEFAULT_INTERVAL); + fprintf(f, " --pidfile file path to record pid (default %s)(for daemonize only)\n", DEFAULT_PIDFILE); + fprintf(f, " --attrname attribute name to update test result (default %s)(for daemonize/client only)\n", DEFAULT_ATTRNAME); fprintf(f, " --verbose emit extra output to stdout\n"); fprintf(f, " --help print this message\n"); } /* Check one device */ static void *test_device(const char *device, int verbose, int inject_error_percent) { uint64_t devsize; int flags = O_RDONLY | O_DIRECT; int device_fd; int res; off_t seek_spot; if (verbose) { printf("Testing device %s\n", device); } device_fd = open(device, flags); if (device_fd < 0) { if (errno != EINVAL) { - fprintf(stderr, "Failed to open %s: %s\n", device, strerror(errno)); + PRINT_STORAGE_MON_ERR("Failed to open %s: %s", device, strerror(errno)); exit(-1); } flags &= ~O_DIRECT; device_fd = open(device, flags); if (device_fd < 0) { - fprintf(stderr, "Failed to open %s: %s\n", device, strerror(errno)); + PRINT_STORAGE_MON_ERR("Failed to open %s: %s", device, strerror(errno)); exit(-1); } } #ifdef __FreeBSD__ res = ioctl(device_fd, DIOCGMEDIASIZE, &devsize); #else res = ioctl(device_fd, BLKGETSIZE64, &devsize); #endif if (res < 0) { - fprintf(stderr, "Failed to get device size for %s: %s\n", device, strerror(errno)); + PRINT_STORAGE_MON_ERR("Failed to get device size for %s: %s", device, strerror(errno)); goto error; } if (verbose) { - printf("%s: opened %s O_DIRECT, size=%zu\n", device, (flags & O_DIRECT)?"with":"without", devsize); + PRINT_STORAGE_MON_INFO("%s: opened %s O_DIRECT, size=%zu", device, (flags & O_DIRECT)?"with":"without", devsize); } /* Don't fret about real randomness */ srand(time(NULL) + getpid()); /* Pick a random place on the device - sector aligned */ seek_spot = (rand() % (devsize-1024)) & 0xFFFFFFFFFFFFFE00; res = lseek(device_fd, seek_spot, SEEK_SET); if (res < 0) { - fprintf(stderr, "Failed to seek %s: %s\n", device, strerror(errno)); + PRINT_STORAGE_MON_ERR("Failed to seek %s: %s", device, strerror(errno)); goto error; } if (verbose) { - printf("%s: reading from pos %ld\n", device, seek_spot); + PRINT_STORAGE_MON_INFO("%s: reading from pos %ld", device, seek_spot); } if (flags & O_DIRECT) { int sec_size = 0; void *buffer; #ifdef __FreeBSD__ res = ioctl(device_fd, DIOCGSECTORSIZE, &sec_size); #else res = ioctl(device_fd, BLKSSZGET, &sec_size); #endif if (res < 0) { - fprintf(stderr, "Failed to get block device sector size for %s: %s\n", device, strerror(errno)); + PRINT_STORAGE_MON_ERR("Failed to get block device sector size for %s: %s", device, strerror(errno)); goto error; } if (posix_memalign(&buffer, sysconf(_SC_PAGESIZE), sec_size) != 0) { - fprintf(stderr, "Failed to allocate aligned memory: %s\n", strerror(errno)); + PRINT_STORAGE_MON_ERR("Failed to allocate aligned memory: %s", strerror(errno)); goto error; } res = read(device_fd, buffer, sec_size); free(buffer); if (res < 0) { - fprintf(stderr, "Failed to read %s: %s\n", device, strerror(errno)); + PRINT_STORAGE_MON_ERR("Failed to read %s: %s", device, strerror(errno)); goto error; } if (res < sec_size) { - fprintf(stderr, "Failed to read %d bytes from %s, got %d\n", sec_size, device, res); + PRINT_STORAGE_MON_ERR("Failed to read %d bytes from %s, got %d", sec_size, device, res); goto error; } } else { char buffer[512]; res = read(device_fd, buffer, sizeof(buffer)); if (res < 0) { - fprintf(stderr, "Failed to read %s: %s\n", device, strerror(errno)); + PRINT_STORAGE_MON_ERR("Failed to read %s: %s", device, strerror(errno)); goto error; } if (res < (int)sizeof(buffer)) { - fprintf(stderr, "Failed to read %ld bytes from %s, got %d\n", sizeof(buffer), device, res); + PRINT_STORAGE_MON_ERR("Failed to read %ld bytes from %s, got %d", sizeof(buffer), device, res); goto error; } } /* Fake an error */ if (inject_error_percent && ((rand() % 100) < inject_error_percent)) { - fprintf(stderr, "People, please fasten your seatbelts, injecting errors!\n"); + PRINT_STORAGE_MON_ERR_NOARGS("People, please fasten your seatbelts, injecting errors!"); goto error; } res = close(device_fd); if (res != 0) { - fprintf(stderr, "Failed to close %s: %s\n", device, strerror(errno)); + PRINT_STORAGE_MON_ERR("Failed to close %s: %s", device, strerror(errno)); exit(-1); } if (verbose) { - printf("%s: done\n", device); + PRINT_STORAGE_MON_INFO("%s: done", device); } exit(0); error: close(device_fd); exit(-1); } -static int test_device_main(size_t device_count, char *devices[MAX_DEVICES], int scores[MAX_DEVICES], int verbose, int inject_error_percent, int timeout) +static gboolean is_child_runnning(void) { - pid_t test_forks[MAX_DEVICES]; size_t i; - struct timespec ts; - time_t start_time; - size_t finished_count = 0; - int final_score = 0; - memset(test_forks, 0, sizeof(test_forks)); for (i=0; i ts.tv_sec)) { + /* If there is an unfired timer, stop it. */ + qb_loop_timer_del(storage_mon_poll_handle, timer_handle); + + /* Send SIGTERM to non-terminating device monitoring processes. */ + if (is_child_runnning()) { + /* See if threads have finished */ for (i=0; i 0 ) { + stop_child(test_forks[i], SIGTERM); + } + } + } + + /* Set a timer for termination. */ + qb_loop_timer_add(storage_mon_poll_handle, QB_LOOP_HIGH, 0, NULL, wrap_test_device_main, &timer_handle); + + return 0; +} + +static size_t find_child_pid(int pid) +{ + size_t i; + + for (i=0; i 0 ) { + if (test_forks[i] == pid) { + return i; + } + } + } + return -1; +} + +static int32_t sigchld_handler(int32_t sig, void *data) +{ + pid_t pid; + size_t index; + int status; + + if (is_child_runnning()) { + while(1) { + pid = waitpid(-1, &status, WNOHANG); + if (pid > 0) { + if (WIFEXITED(status)) { + index = find_child_pid(pid); + if (index >= 0) { + /* If the expire timer is running, no timeout has occurred, */ + /* so add the final_score from the exit code of the terminated child process. */ + if (qb_loop_timer_is_running(storage_mon_poll_handle, expire_handle)) { + if (WEXITSTATUS(status) !=0) { + final_score += scores[index]; + + /* Update response values immediately in preparation for inquiries from clients. */ + response_final_score = final_score; + + /* Even in the first demon mode check, if there is an error device, clear */ + /* the flag to return the response to the client without waiting for all devices to finish. */ + daemon_check_first_all_devices = TRUE; + } + } +#if 0 + if (shutting_down == FALSE) { + finished_count++; + test_forks[index] = 0; + } +#endif + finished_count++; + test_forks[index] = 0; + + } + } + } else { + break; + } + } + } + return 0; +} + +static void child_shutdown(int nsig) +{ + exit(1); +} + +static int write_pid_file(const char *pidfile) +{ + char *pid; + char *dir, *str = NULL; + int fd = -1; + int rc = -1; + int i, len; + + if (asprintf(&pid, "%jd", (intmax_t)getpid()) < 0) { + syslog(LOG_ERR, "Failed to allocate memory to store PID"); + pid = NULL; + goto done; + } + + str = strdup(pidfile); + if (str == NULL) { + syslog(LOG_ERR, "Failed to duplicate string ['%s']", pidfile); + goto done; + } + dir = dirname(str); + for (i = 1, len = strlen(dir); i < len; i++) { + if (dir[i] == '/') { + dir[i] = 0; + if ((mkdir(dir, 0640) < 0) && (errno != EEXIST)) { + syslog(LOG_ERR, "Failed to create directory %s: %s", dir, strerror(errno)); + goto done; + } + dir[i] = '/'; + } + } + if ((mkdir(dir, 0640) < 0) && (errno != EEXIST)) { + syslog(LOG_ERR, "Failed to create directory %s: %s", dir, strerror(errno)); + goto done; + } + + fd = open(pidfile, O_CREAT | O_WRONLY, 0640); + if (fd < 0) { + syslog(LOG_ERR, "Failed to open %s: %s", pidfile, strerror(errno)); + goto done; + } + + if (write(fd, pid, strlen(pid)) != strlen(pid)) { + syslog(LOG_ERR, "Failed to write '%s' to %s: %s", pid, pidfile, strerror(errno)); + goto done; + } + close(fd); + rc = 0; +done: + if (pid != NULL) { + free(pid); + } + if (str != NULL) { + free(str); + } + return rc; +} + +static void child_timeout_handler(void *data) +{ + size_t i; + + if (is_child_runnning()) { + for (i=0; i 0) { - w = waitpid(test_forks[i], &wstatus, WUNTRACED | WNOHANG | WCONTINUED); - if (w < 0) { - fprintf(stderr, "waitpid on %s failed: %s\n", devices[i], strerror(errno)); - return -1; + /* If timeout occurs before SIGCHLD, add child process failure score to final_score. */ + final_score += scores[i]; + + /* Update response values immediately in preparation for inquiries from clients. */ + response_final_score = final_score; + + /* Even in the first demon mode check, if there is an error device, clear */ + /* the flag to return the response to the client without waiting for all devices to finish. */ + daemon_check_first_all_devices = TRUE; + } + } + } +} + +static void wrap_test_device_main(void *data) +{ + struct storage_mon_timer_data *timer_data = (struct storage_mon_timer_data*)data; + test_device_main((timer_data != NULL) ? &timer_data->interval : NULL); +} + +static int test_device_main(gpointer data) +{ + size_t i; + struct timespec ts; + time_t start_time; + gboolean device_check = TRUE; + + if (daemonize) { + if (shutting_down == TRUE) { + goto done; + } + + /* In the case of daemon mode, it is avoided that the timer is triggered and the number of */ + /* child processes increases while the device monitoring child process is not completed. */ + if (is_child_runnning()) { + device_check = FALSE; + } + + if (device_count == finished_count && device_check) { + /* Update the result value for the client response once all checks have completed. */ + response_final_score = final_score; + + if (!daemon_check_first_all_devices) { + daemon_check_first_all_devices = TRUE; + } + } + } + + if (device_check) { + /* Reset final_score, finished_count, test_forks[] */ + final_score = 0; + finished_count = 0; + + memset(test_forks, 0, sizeof(test_forks)); + for (i=0; i ts.tv_sec)) { + for (i=0; i 0) { + w = waitpid(test_forks[i], &wstatus, WUNTRACED | WNOHANG | WCONTINUED); + if (w < 0) { + PRINT_STORAGE_MON_ERR("waitpid on %s failed: %s", devices[i], strerror(errno)); + return -1; } - finished_count++; - test_forks[i] = 0; + if (w == test_forks[i]) { + if (WIFEXITED(wstatus)) { + if (WEXITSTATUS(wstatus) != 0) { + syslog(LOG_ERR, "Error reading from device %s", devices[i]); + final_score += scores[i]; + } + + finished_count++; + test_forks[i] = 0; + } + } } } + + usleep(100000); + + clock_gettime(CLOCK_REALTIME, &ts); + } + + /* See which threads have not finished */ + for (i=0; ihdr.id, request->hdr.size, request->message); + + if (strcmp(request->message, SMON_GET_RESULT_COMMAND) != 0) { + syslog(LOG_DEBUG, "request command is unknown."); + send_score = -1; + } else if (!daemon_check_first_all_devices) { + send_score = -2; } - /* See which threads have not finished */ - for (i=0; i 0) { + rc = qb_ipcc_recv(conn, &response, sizeof(response), -1); + if (rc < 0) { + syslog(LOG_ERR, "qb_ipcc_recv error : %d\n", rc); + return(-1); } } - if (verbose) { - printf("Final score is %d\n", final_score); + qb_ipcc_disconnect(conn); + + /* Set score to result */ + /* 0 : Normal. */ + /* greater than 0 : monitoring error. */ + /* -1 : communication system error. */ + /* -2 : Not all checks completed for first device in daemon mode. */ + rc = atoi(response.message); + + syslog(LOG_DEBUG, "daemon response[%d]: %s \n", response.hdr.id, response.message); + + return(rc); +} + +static int32_t +storage_mon_daemon(int interval, const char *pidfile) +{ + int32_t rc; + char ipcs_name[SMON_MAX_IPCSNAME]; + + struct qb_ipcs_service_handlers service_handle = { + .connection_accept = storage_mon_ipcs_connection_accept_fn, + .connection_created = storage_mon_ipcs_connection_created_fn, + .msg_process = storage_mon_ipcs_msg_process_fn, + .connection_destroyed = storage_mon_ipcs_connection_destroyed_fn, + .connection_closed = storage_mon_ipcs_connection_closed_fn, + }; + + struct qb_ipcs_poll_handlers poll_handle = { + .job_add = storage_mon_job_add, + .dispatch_add = storage_mon_dispatch_add, + .dispatch_mod = storage_mon_dispatch_mod, + .dispatch_del = storage_mon_dispatch_del, + }; + + if (daemon(0, 0) < 0) { + syslog(LOG_ERR, "Failed to daemonize: %s", strerror(errno)); + return -1; } - return final_score; + + umask(S_IWGRP | S_IWOTH | S_IROTH); + + if (write_pid_file(pidfile) < 0) { + return -1; + } + + snprintf(ipcs_name, SMON_MAX_IPCSNAME, "storage_mon_%s", attrname); + ipcs = qb_ipcs_create(ipcs_name, 0, QB_IPC_NATIVE, &service_handle); + if (ipcs == 0) { + syslog(LOG_ERR, "qb_ipcs_create"); + return -1; + } + + qb_ipcs_enforce_buffer_size(ipcs, SMON_BUFF_1MEG); + + storage_mon_poll_handle = qb_loop_create(); + + qb_ipcs_poll_handlers_set(ipcs, &poll_handle); + rc = qb_ipcs_run(ipcs); + if (rc != 0) { + errno = -rc; + syslog(LOG_ERR, "qb_ipcs_run"); + return -1; + } + + qb_loop_signal_add(storage_mon_poll_handle, QB_LOOP_HIGH, + SIGTERM, NULL, sigterm_handler, NULL); + + qb_loop_signal_add(storage_mon_poll_handle, QB_LOOP_MED, + SIGCHLD, NULL, sigchld_handler, NULL); + + timer_d.interval = interval; + qb_loop_timer_add(storage_mon_poll_handle, QB_LOOP_MED, 0, &timer_d, wrap_test_device_main, &timer_handle); + + qb_loop_run(storage_mon_poll_handle); + qb_loop_destroy(storage_mon_poll_handle); + + unlink(pidfile); + + return 0; } int main(int argc, char *argv[]) { - char *devices[MAX_DEVICES]; - int scores[MAX_DEVICES]; - size_t device_count = 0; size_t score_count = 0; - int timeout = DEFAULT_TIMEOUT; - int final_score = 0; int opt, option_index; - int verbose = 0; - int inject_error_percent = 0; + int interval = DEFAULT_INTERVAL; + const char *pidfile = DEFAULT_PIDFILE; + gboolean client = FALSE; struct option long_options[] = { {"timeout", required_argument, 0, 't' }, {"device", required_argument, 0, 'd' }, {"score", required_argument, 0, 's' }, {"inject-errors-percent", required_argument, 0, 0 }, + {"daemonize", no_argument, 0, 0 }, + {"client", no_argument, 0, 0 }, + {"interval", required_argument, 0, 'i' }, + {"pidfile", required_argument, 0, 'p' }, + {"attrname", required_argument, 0, 'a' }, {"verbose", no_argument, 0, 'v' }, {"help", no_argument, 0, 'h' }, {0, 0, 0, 0 } }; - while ( (opt = getopt_long(argc, argv, "hvt:d:s:", + + while ( (opt = getopt_long(argc, argv, "hvt:d:s:i:p:a:", long_options, &option_index)) != -1 ) { switch (opt) { case 0: /* Long-only options */ if (strcmp(long_options[option_index].name, "inject-errors-percent") == 0) { inject_error_percent = atoi(optarg); if (inject_error_percent < 1 || inject_error_percent > 100) { fprintf(stderr, "inject_error_percent should be between 1 and 100\n"); return -1; } } + if (strcmp(long_options[option_index].name, "daemonize") == 0) { + daemonize = TRUE; + } + if (strcmp(long_options[option_index].name, "client") == 0) { + client = TRUE; + } + if (daemonize && client) { + fprintf(stderr,"The daemonize option and client option cannot be specified at the same time."); + return -1; + } break; case 'd': if (device_count < MAX_DEVICES) { devices[device_count++] = strdup(optarg); } else { fprintf(stderr, "too many devices, max is %d\n", MAX_DEVICES); return -1; } break; case 's': if (score_count < MAX_DEVICES) { int score = atoi(optarg); if (score < 1 || score > 10) { fprintf(stderr, "Score must be between 1 and 10 inclusive\n"); return -1; } scores[score_count++] = score; } else { fprintf(stderr, "too many scores, max is %d\n", MAX_DEVICES); return -1; } break; case 'v': verbose++; break; case 't': timeout = atoi(optarg); if (timeout < 1) { fprintf(stderr, "invalid timeout %d. Min 1, recommended %d (default)\n", timeout, DEFAULT_TIMEOUT); return -1; } break; case 'h': usage(argv[0], stdout); return 0; break; + case 'i': + interval = atoi(optarg); + if (interval < 1) { + fprintf(stderr, "invalid interval %d. Min 1, default is %d\n", interval, DEFAULT_INTERVAL); + return -1; + } + break; + case 'p': + pidfile = strdup(optarg); + if (pidfile == NULL) { + fprintf(stderr, "Failed to duplicate string ['%s']\n", optarg); + return -1; + } + break; + case 'a': + attrname = strdup(optarg); + if (attrname == NULL) { + fprintf(stderr, "Failed to duplicate string ['%s']\n", optarg); + return -1; + } + break; default: usage(argv[0], stderr); return -1; break; } } + + if (client) { + return(storage_mon_client()); + } + if (device_count == 0) { fprintf(stderr, "No devices to test, use the -d or --device argument\n"); return -1; } if (device_count != score_count) { fprintf(stderr, "There must be the same number of devices and scores\n"); return -1; } openlog("storage_mon", 0, LOG_DAEMON); - - final_score = test_device_main(device_count, devices, scores, verbose, inject_error_percent, timeout); + if (!daemonize) { + final_score = test_device_main(NULL); + } else { + return(storage_mon_daemon(interval, pidfile)); + } return final_score; }