diff --git a/rgmanager/src/resources/script.sh b/rgmanager/src/resources/script.sh index fa07f1db7..fa3b4124c 100755 --- a/rgmanager/src/resources/script.sh +++ b/rgmanager/src/resources/script.sh @@ -1,121 +1,171 @@ #!/bin/bash # # Script to handle a non-OCF script (e.g. a normal init-script) # # # Copyright (C) 1997-2003 Sistina Software, Inc. All rights reserved. # Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved. # # 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. # LC_ALL=C LANG=C PATH=/bin:/sbin:/usr/bin:/usr/sbin export LC_ALL LANG PATH . $(dirname $0)/ocf-shellfuncs meta_data() { cat < 1.0 The script resource allows a standard LSB-compliant init script to be used to start a clustered service. LSB-compliant init script as a clustered resource. Name Name Path to script Path to script Inherit the service name, in case the script wants to know this information. Inherit the service name. EOT } +validate_all() +{ + if [ -z "${OCF_RESKEY_file}" ]; then + ocf_log err "No file provided" + return $OCF_ERR_ARGS # Invalid Argument + fi + + if ! [ -e "${OCF_RESKEY_file}" ]; then + ocf_log err "${OCF_RESKEY_file} does not exist" + return $OCF_ERR_INSTALLED # Program not installed + fi + + if [ -b "${OCF_RESKEY_file}" ]; then + ocf_log err "${OCF_RESKEY_file} is a block device" + return $OCF_ERR_ARGS # Invalid Argument + fi + + if [ -d "${OCF_RESKEY_file}" ]; then + ocf_log err "${OCF_RESKEY_file} is a directory" + return $OCF_ERR_ARGS # Invalid Argument + fi + + if [ -c "${OCF_RESKEY_file}" ]; then + ocf_log err "${OCF_RESKEY_file} is a character device" + return $OCF_ERR_ARGS # Invalid Argument + fi + + if [ -p "${OCF_RESKEY_file}" ]; then + ocf_log err "${OCF_RESKEY_file} is a named pipe" + return $OCF_ERR_ARGS # Invalid Argument + fi + + if [ -S "${OCF_RESKEY_file}" ]; then + ocf_log err "${OCF_RESKEY_file} is a socket" + return $OCF_ERR_ARGS # Invalid Argument + fi + + if ! [ -s "${OCF_RESKEY_file}" ]; then + ocf_log err "${OCF_RESKEY_file} is empty" + return $OCF_ERR_GENERIC # ??? + fi + + if ! [ -x "${OCF_RESKEY_file}" ]; then + ocf_log err "${OCF_RESKEY_file} is not executable" + return $OCF_ERR_PERM + fi + + return 0 +} + case $1 in meta-data) meta_data exit 0 ;; validate-all) - exit 0 # XXX XXX XXX + validate_all + exit $? ;; *) ;; esac -[ -n "${OCF_RESKEY_file}" ] || exit $OCF_ERR_ARGS # Invalid Argument -[ -f "${OCF_RESKEY_file}" ] || exit $OCF_ERR_INSTALLED # Program not installed -[ -x "${OCF_RESKEY_file}" ] || exit $OCF_ERR_GENERIC # Generic error -# Don't need to catch return codes; this one will work. +validate_all || exit $? + +# Execute the script ocf_log info "Executing ${OCF_RESKEY_file} $1" ${OCF_RESKEY_file} $1 declare -i rv=$? if [ $rv -ne 0 ]; then ocf_log err "script:$OCF_RESKEY_name: $1 of $OCF_RESKEY_file failed (returned $rv)" exit $OCF_ERR_GENERIC fi