Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP1:Update
resource-agents
0007-Medium-nfsserver-do-redhat-specific-stuff-...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0007-Medium-nfsserver-do-redhat-specific-stuff-on-redhat.patch of Package resource-agents
From fc3b6058564ab196b3f382d56a49dadcd55980e2 Mon Sep 17 00:00:00 2001 From: Dejan Muhamedagic <dejan@suse.de> Date: Tue, 22 Dec 2015 15:56:57 +0100 Subject: [PATCH 7/9] Medium: nfsserver: do redhat specific stuff on redhat The /etc/sysconfig/nfs editing code introduced in 2014 is specific to RH based linux. At best it has no effect on other distributions and at worst it can break the RA operation and/or nfs configuration. There is rudimentary support for distribution detection in ocf-distro. It should serve well for this purpose. NB: ocf-distro is intended to be used just here and just for this purpose and not to be further developed. Distribution-specific code is _not_ encouraged. --- heartbeat/Makefile.am | 2 + heartbeat/nfsserver | 175 +++--------------------------------------- heartbeat/nfsserver-redhat.sh | 169 ++++++++++++++++++++++++++++++++++++++++ heartbeat/ocf-distro | 47 ++++++++++++ heartbeat/ocf-shellfuncs.in | 1 + 5 files changed, 228 insertions(+), 166 deletions(-) create mode 100644 heartbeat/nfsserver-redhat.sh create mode 100644 heartbeat/ocf-distro diff --git a/heartbeat/Makefile.am b/heartbeat/Makefile.am index 73ce6b6..38d1016 100644 --- a/heartbeat/Makefile.am +++ b/heartbeat/Makefile.am @@ -144,12 +144,14 @@ ocfcommon_DATA = ocf-shellfuncs \ ocf-directories \ ocf-returncodes \ ocf-rarun \ + ocf-distro \ apache-conf.sh \ http-mon.sh \ sapdb-nosha.sh \ sapdb.sh \ ora-common.sh \ mysql-common.sh \ + nfsserver-redhat.sh \ findif.sh # Legacy locations diff --git a/heartbeat/nfsserver b/heartbeat/nfsserver index 02a2f7f..3cec5c8 100755 --- a/heartbeat/nfsserver +++ b/heartbeat/nfsserver @@ -12,6 +12,10 @@ else . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs fi +if is_redhat_based; then + . ${OCF_FUNCTIONS_DIR}/nfsserver-redhat.sh +fi + DEFAULT_INIT_SCRIPT="/etc/init.d/nfsserver" if ! [ -f $DEFAULT_INIT_SCRIPT ]; then # On some systems, the script is just called nfs @@ -26,9 +30,6 @@ EXEC_MODE=0 SELINUX_ENABLED=-1 STATD_PATH="/var/lib/nfs" STATD_DIR="" -NFS_SYSCONFIG="/etc/sysconfig/nfs" -NFS_SYSCONFIG_LOCAL_BACKUP="/etc/sysconfig/nfs.ha.bu" -NFS_SYSCONFIG_AUTOGEN_TAG="AUTOGENERATED by $0 high availability resource-agent" nfsserver_meta_data() { cat <<END @@ -104,83 +105,6 @@ IP addresses. <content type="string"/> </parameter> -<parameter name="nfsd_args" unique="0" required="0"> -<longdesc lang="en"> -Specifies what arguments to pass to the nfs daemon on startup. View the rpc.nfsd man page for information on what arguments are available. -Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. -</longdesc> -<shortdesc lang="en"> -rpc.nfsd options -</shortdesc> -<content type="string" /> -</parameter> - -<parameter name="lockd_udp_port" unique="0" required="0"> -<longdesc lang="en"> -The udp port lockd should listen on. -Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. -</longdesc> -<shortdesc lang="en"> -lockd udp port -</shortdesc> -<content type="integer" /> -</parameter> - -<parameter name="lockd_tcp_port" unique="0" required="0"> -<longdesc lang="en"> -The tcp port lockd should listen on. -Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. -</longdesc> -<shortdesc lang="en"> -lockd tcp port -</shortdesc> -<content type="integer" /> -</parameter> - -<parameter name="statd_outgoing_port" unique="0" required="0"> -<longdesc lang="en"> -The source port number sm-notify uses when sending reboot notifications. -Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. -</longdesc> -<shortdesc lang="en"> -sm-notify source port -</shortdesc> -<content type="integer" /> -</parameter> - -<parameter name="statd_port" unique="0" required="0"> -<longdesc lang="en"> -The port number used for RPC listener sockets. -Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. -</longdesc> -<shortdesc lang="en"> -rpc.statd listener port -</shortdesc> -<content type="integer" /> -</parameter> - -<parameter name="mountd_port" unique="0" required="0"> -<longdesc lang="en"> -The port number used for rpc.mountd listener sockets. -Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. -</longdesc> -<shortdesc lang="en"> -rpc.mountd listener port -</shortdesc> -<content type="integer" /> -</parameter> - -<parameter name="rquotad_port" unique="0" required="0"> -<longdesc lang="en"> -The port number used for rpc.rquotad. -Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. -</longdesc> -<shortdesc lang="en"> -rpc.rquotad port -</shortdesc> -<content type="integer" /> -</parameter> - <parameter name="nfs_shared_infodir" unique="0" required="0"> <longdesc lang="en"> The nfsserver resource agent will save nfs related information in this specific directory. @@ -205,6 +129,10 @@ The mount point for the sunrpc file system. <content type="string" default="$DEFAULT_RPCPIPEFS_DIR" /> </parameter> +$( +is_redhat_based && nfsserver_redhat_meta_data +) + </parameters> <actions> @@ -391,91 +319,6 @@ nfsserver_monitor () fi } -set_arg() -{ - local key="$1" - local value="$2" - local file="$3" - local requires_sysconfig="$4" - - if [ -z "$value" ]; then - return - fi - - # only write to the tmp /etc/sysconfig/nfs if sysconfig exists. - # otherwise this distro does not support setting these options. - if [ -d "/etc/sysconfig" ]; then - # replace if the value exists, append otherwise - if grep "^\s*${key}=" $file ; then - sed -i "s/\s*${key}=.*$/${key}=\"${value}\"/" $file - else - echo "${key}=\"${value}\"" >> $file - fi - elif [ "$requires_sysconfig" = "true" ]; then - ocf_log warn "/etc/sysconfig/nfs not found, unable to set port and nfsd args." - fi - - export ${key}="${value}" -} - -set_env_args() -{ - local tmpconfig=$(mktemp ${HA_RSCTMP}/nfsserver-tmp-XXXXX) - local statd_args - - if [ -f "$NFS_SYSCONFIG" ]; then - ## Take the $NFS_SYSCONFIG file as our skeleton - cp $NFS_SYSCONFIG $tmpconfig - fi - - # nfsd args - set_arg "RPCNFSDARGS" "$OCF_RESKEY_nfsd_args" "$tmpconfig" "true" - - # mountd args - if [ -n "$OCF_RESKEY_mountd_port" ]; then - set_arg "RPCMOUNTDOPTS" "-p $OCF_RESKEY_mountd_port" "$tmpconfig" "true" - fi - - # statd args. we always want to perform the notify using sm-notify after - # both rpc.statd and the nfsd daemons are initialized - statd_args="--no-notify" - if [ -n "$OCF_RESKEY_statd_outgoing_port" ]; then - statd_args="$statd_args -o $OCF_RESKEY_statd_outgoing_port" - fi - if [ -n "$OCF_RESKEY_statd_port" ]; then - statd_args="$statd_args -p $OCF_RESKEY_statd_port" - fi - set_arg "STATDARG" "$statd_args" "$tmpconfig" "false" - - # lockd ports - set_arg "LOCKD_UDPPORT" "$OCF_RESKEY_lockd_udp_port" "$tmpconfig" "true" - set_arg "LOCKD_TCPPORT" "$OCF_RESKEY_lockd_tcp_port" "$tmpconfig" "true" - - # rquotad_port - if [ -n "$OCF_RESKEY_rquotad_port" ]; then - set_arg "RPCRQUOTADOPTS" "-p $OCF_RESKEY_rquotad_port" "$tmpconfig" "true" - fi - - # override local nfs config. preserve previous local config though. - if [ -s $tmpconfig ]; then - cat $NFS_SYSCONFIG | grep -q -e "$NFS_SYSCONFIG_AUTOGEN_TAG" > /dev/null 2>&1 - if [ $? -ne 0 ]; then - # backup local nfs config if it doesn't have our HA autogen tag in it. - mv -f $NFS_SYSCONFIG $NFS_SYSCONFIG_LOCAL_BACKUP - fi - - cat $tmpconfig | grep -q -e "$NFS_SYSCONFIG_AUTOGEN_TAG" > /dev/null 2>&1 - if [ $? -ne 0 ]; then - echo "# $NFS_SYSCONFIG_AUTOGEN_TAG" > $NFS_SYSCONFIG - echo "# local config backup stored here, '$NFS_SYSCONFIG_LOCAL_BACKUP'" >> $NFS_SYSCONFIG - cat $tmpconfig >> $NFS_SYSCONFIG - else - cat $tmpconfig > $NFS_SYSCONFIG - fi - fi - rm -f $tmpconfig -} - prepare_directory () { if [ -z "$fp" ]; then @@ -686,7 +529,7 @@ nfsserver_start () return $OCF_SUCCESS fi - set_env_args + is_redhat_based && set_env_args prepare_directory bind_tree diff --git a/heartbeat/nfsserver-redhat.sh b/heartbeat/nfsserver-redhat.sh new file mode 100644 index 0000000..cef0862 --- /dev/null +++ b/heartbeat/nfsserver-redhat.sh @@ -0,0 +1,169 @@ +NFS_SYSCONFIG="/etc/sysconfig/nfs" +NFS_SYSCONFIG_LOCAL_BACKUP="/etc/sysconfig/nfs.ha.bu" +NFS_SYSCONFIG_AUTOGEN_TAG="AUTOGENERATED by $0 high availability resource-agent" + +nfsserver_redhat_meta_data() { +cat<<EOF +<parameter name="nfsd_args" unique="0" required="0"> +<longdesc lang="en"> +Specifies what arguments to pass to the nfs daemon on startup. View the rpc.nfsd man page for information on what arguments are available. +Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. +</longdesc> +<shortdesc lang="en"> +rpc.nfsd options +</shortdesc> +<content type="string" /> +</parameter> + +<parameter name="lockd_udp_port" unique="0" required="0"> +<longdesc lang="en"> +The udp port lockd should listen on. +Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. +</longdesc> +<shortdesc lang="en"> +lockd udp port +</shortdesc> +<content type="integer" /> +</parameter> + +<parameter name="lockd_tcp_port" unique="0" required="0"> +<longdesc lang="en"> +The tcp port lockd should listen on. +Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. +</longdesc> +<shortdesc lang="en"> +lockd tcp port +</shortdesc> +<content type="integer" /> +</parameter> + +<parameter name="statd_outgoing_port" unique="0" required="0"> +<longdesc lang="en"> +The source port number sm-notify uses when sending reboot notifications. +Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. +</longdesc> +<shortdesc lang="en"> +sm-notify source port +</shortdesc> +<content type="integer" /> +</parameter> + +<parameter name="statd_port" unique="0" required="0"> +<longdesc lang="en"> +The port number used for RPC listener sockets. +Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. +</longdesc> +<shortdesc lang="en"> +rpc.statd listener port +</shortdesc> +<content type="integer" /> +</parameter> + +<parameter name="mountd_port" unique="0" required="0"> +<longdesc lang="en"> +The port number used for rpc.mountd listener sockets. +Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. +</longdesc> +<shortdesc lang="en"> +rpc.mountd listener port +</shortdesc> +<content type="integer" /> +</parameter> + +<parameter name="rquotad_port" unique="0" required="0"> +<longdesc lang="en"> +The port number used for rpc.rquotad. +Note that setting this value will override all settings placed in the local /etc/sysconfig/nfs file. +</longdesc> +<shortdesc lang="en"> +rpc.rquotad port +</shortdesc> +<content type="integer" /> +</parameter> +EOF +} + +set_arg() +{ + local key="$1" + local value="$2" + local file="$3" + local requires_sysconfig="$4" + + if [ -z "$value" ]; then + return + fi + + # only write to the tmp /etc/sysconfig/nfs if sysconfig exists. + # otherwise this distro does not support setting these options. + if [ -d "/etc/sysconfig" ]; then + # replace if the value exists, append otherwise + if grep "^\s*${key}=" $file ; then + sed -i "s/\s*${key}=.*$/${key}=\"${value}\"/" $file + else + echo "${key}=\"${value}\"" >> $file + fi + elif [ "$requires_sysconfig" = "true" ]; then + ocf_log warn "/etc/sysconfig/nfs not found, unable to set port and nfsd args." + fi + + export ${key}="${value}" +} + +set_env_args() +{ + local tmpconfig=$(mktemp ${HA_RSCTMP}/nfsserver-tmp-XXXXX) + local statd_args + + if [ -f "$NFS_SYSCONFIG" ]; then + ## Take the $NFS_SYSCONFIG file as our skeleton + cp $NFS_SYSCONFIG $tmpconfig + fi + + # nfsd args + set_arg "RPCNFSDARGS" "$OCF_RESKEY_nfsd_args" "$tmpconfig" "true" + + # mountd args + if [ -n "$OCF_RESKEY_mountd_port" ]; then + set_arg "RPCMOUNTDOPTS" "-p $OCF_RESKEY_mountd_port" "$tmpconfig" "true" + fi + + # statd args. we always want to perform the notify using sm-notify after + # both rpc.statd and the nfsd daemons are initialized + statd_args="--no-notify" + if [ -n "$OCF_RESKEY_statd_outgoing_port" ]; then + statd_args="$statd_args -o $OCF_RESKEY_statd_outgoing_port" + fi + if [ -n "$OCF_RESKEY_statd_port" ]; then + statd_args="$statd_args -p $OCF_RESKEY_statd_port" + fi + set_arg "STATDARG" "$statd_args" "$tmpconfig" "false" + + # lockd ports + set_arg "LOCKD_UDPPORT" "$OCF_RESKEY_lockd_udp_port" "$tmpconfig" "true" + set_arg "LOCKD_TCPPORT" "$OCF_RESKEY_lockd_tcp_port" "$tmpconfig" "true" + + # rquotad_port + if [ -n "$OCF_RESKEY_rquotad_port" ]; then + set_arg "RPCRQUOTADOPTS" "-p $OCF_RESKEY_rquotad_port" "$tmpconfig" "true" + fi + + # override local nfs config. preserve previous local config though. + if [ -s $tmpconfig ]; then + cat $NFS_SYSCONFIG | grep -q -e "$NFS_SYSCONFIG_AUTOGEN_TAG" > /dev/null 2>&1 + if [ $? -ne 0 ]; then + # backup local nfs config if it doesn't have our HA autogen tag in it. + mv -f $NFS_SYSCONFIG $NFS_SYSCONFIG_LOCAL_BACKUP + fi + + cat $tmpconfig | grep -q -e "$NFS_SYSCONFIG_AUTOGEN_TAG" > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "# $NFS_SYSCONFIG_AUTOGEN_TAG" > $NFS_SYSCONFIG + echo "# local config backup stored here, '$NFS_SYSCONFIG_LOCAL_BACKUP'" >> $NFS_SYSCONFIG + cat $tmpconfig >> $NFS_SYSCONFIG + else + cat $tmpconfig > $NFS_SYSCONFIG + fi + fi + rm -f $tmpconfig +} diff --git a/heartbeat/ocf-distro b/heartbeat/ocf-distro new file mode 100644 index 0000000..530ee57 --- /dev/null +++ b/heartbeat/ocf-distro @@ -0,0 +1,47 @@ +# +# This is OCF Linux distribution query support +# +# Currently needed for the nfsserver RA which has some already +# released RH specific stuff (/etc/sysconfig/nfs editing) +# + +_DEBIAN_VERSION_FILE="/etc/debian_version" +_REDHAT_RELEASE_FILE="/etc/redhat-release" +_SUSE_RELEASE_FILE="/etc/SuSE-release" +_RELEASE_FILES="/etc/*-release" +_REDHAT_BASED_DISTROS_RE='red *hat|fedora|centos|scientific linux' + +get_release_id() { + if which lsb_release >/dev/null 2>&1; then + lsb_release -si + elif [ -e $_DEBIAN_VERSION_FILE ]; then + echo Debian + elif [ -e $_SUSE_RELEASE_FILE ]; then + echo SUSE + elif [ -e $_REDHAT_RELEASE_FILE ]; then + echo Redhat + else # FIXME not exactly the id here, but will do for our purpose + cat $_RELEASE_FILES 2>/dev/null + fi +} + +is_redhat_based() { + get_release_id | egrep -qsi "$_REDHAT_BASED_DISTROS_RE" +} + +# get_os_ver() is currently unused +get_os_ver() { + if which lsb_release >/dev/null 2>&1; then + OS=`lsb_release -si` + VER=`lsb_release -sr` + elif [ -f $_DEBIAN_VERSION_FILE ]; then + OS=Debian + VER=$(cat $_DEBIAN_VERSION_FILE) + elif [ -f $_REDHAT_RELEASE_FILE ]; then + OS=RedHat # redhat or similar + VER= # here some complex sed script + else + OS=$(uname -s) + VER=$(uname -r) + fi +} diff --git a/heartbeat/ocf-shellfuncs.in b/heartbeat/ocf-shellfuncs.in index 2023661..2f5f684 100644 --- a/heartbeat/ocf-shellfuncs.in +++ b/heartbeat/ocf-shellfuncs.in @@ -57,6 +57,7 @@ fi . ${OCF_FUNCTIONS_DIR}/ocf-returncodes . ${OCF_FUNCTIONS_DIR}/ocf-directories . ${OCF_FUNCTIONS_DIR}/ocf-rarun +. ${OCF_FUNCTIONS_DIR}/ocf-distro # Define OCF_RESKEY_CRM_meta_interval in case it isn't already set, # to make sure that ocf_is_probe() always works -- 2.6.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor