ulimit -n $CTDB_MAX_OPEN_FILES
fi
- mkdir -p $(dirname "$pidfile")
+ _d=$(dirname "$pidfile")
+ mkdir -p "$_d"
if [ -n "$CTDB_VALGRIND" -a "$CTDB_VALGRIND" != "no" ] ; then
if [ "$CTDB_VALGRIND" = "yes" ] ; then
echo "===== Start of hung script debug for PID=\"$1\", event=\"$2\" ====="
echo "pstree -p -a ${1}:"
- out=$(pstree -p -a $1)
+ out=$(pstree -p -a "$1")
echo "$out"
# Check for processes matching a regular expression and print
grep -F "POSIX ADVISORY WRITE" |
awk '{ if($2 == "->") { print $6, $7, $8, $9, "W" } else { print $5, $6, $7, $8 } }' |
while read pid rest ; do
- pname=$(readlink /proc/$pid/exe)
+ pname=$(readlink "/proc/${pid}/exe")
echo $pid $pname $rest
done | sed -e "$sed_cmd" | grep "\.tdb" )
# For each process waiting, log stack trace
for pid in $pids ; do
echo "----- Stack trace for PID=$pid -----"
- read x x state x </proc/$pid/stat
+ read x x state x <"/proc/${pid}/stat"
if [ "$state" = "D" ] ; then
# Don't run gstack on a process in D state since
# gstack will hang until the process exits D state.
# deadlock... but it will probably give us someone to
# blame!
echo "----- Process in D state, printing kernel stack only"
- cat /proc/$pid/stack
+ cat "/proc/${pid}/stack"
else
- gstack $pid
+ gstack "$pid"
# gcore -o /var/log/core-deadlock-ctdb $pid
fi
done
while read v; do
varname="${v#CTDB_SET_}"
value=$(eval echo "\$$v")
- if $CTDB setvar $varname $value ; then
+ if $CTDB setvar "$varname" "$value" ; then
echo "Set $varname to $value"
else
echo "Invalid configuration: CTDB_SET_${varname}=${value}"
# Try to stat the reclock file as a background process so that
# we don't block in case the cluster filesystem is unavailable
(
- if stat $CTDB_RECOVERY_LOCK ; then
+ if stat "$CTDB_RECOVERY_LOCK" ; then
# We could stat the file, reset the counter
ctdb_counter_init
fi
loadconfig
[ -z "$CTDB_PUBLIC_ADDRESSES" ] && {
- CTDB_PUBLIC_ADDRESSES=$CTDB_BASE/public_addresses
+ CTDB_PUBLIC_ADDRESSES="${CTDB_BASE}/public_addresses"
}
[ ! -f "$CTDB_PUBLIC_ADDRESSES" ] && {
get_all_interfaces ()
{
# Get all the interfaces listed in the public_addresses file
- all_interfaces=$(sed -e "s/^[^\t ]*[\t ]*//" -e "s/,/ /g" -e "s/[\t ]*$//" $CTDB_PUBLIC_ADDRESSES)
+ all_interfaces=$(sed -e "s/^[^\t ]*[\t ]*//" \
+ -e "s/,/ /g" \
+ -e "s/[\t ]*$//" "$CTDB_PUBLIC_ADDRESSES")
# Add some special interfaces if they're defined
[ "$CTDB_PUBLIC_INTERFACE" ] && all_interfaces="$CTDB_PUBLIC_INTERFACE $all_interfaces"
ip=$3
maskbits=$4
- add_ip_to_iface $iface $ip $maskbits || {
+ add_ip_to_iface "$iface" "$ip" "$maskbits" || {
exit 1;
}
kill_tcp_connections "$iface" "$ip"
- delete_ip_from_iface $iface $ip $maskbits || {
+ delete_ip_from_iface "$iface" "$ip" "$maskbits" || {
ip_unblock "$ip" "$iface"
exit 1
}
ip_block "$ip" "$oiface"
- delete_ip_from_iface $oiface $ip $maskbits 2>/dev/null
- delete_ip_from_iface $niface $ip $maskbits 2>/dev/null
+ delete_ip_from_iface "$oiface" "$ip" "$maskbits" 2>/dev/null
+ delete_ip_from_iface "$niface" "$ip" "$maskbits" 2>/dev/null
- add_ip_to_iface $niface $ip $maskbits || {
+ add_ip_to_iface "$niface" "$ip" "$maskbits" || {
ip_unblock "$ip" "$oiface"
exit 1
}
flush_route_cache
# propagate the new mac address
- $CTDB gratiousarp $ip $niface
+ $CTDB gratiousarp "$ip" "$niface"
# tickle all existing connections, so that dropped packets
# are retransmited and the tcp streams work
- tickle_tcp_connections $ip
+ tickle_tcp_connections "$ip"
;;
monitor)
_maskbits="${CTDB_NATGW_PUBLIC_IP#*/}"
delete_ip_from_iface \
- $CTDB_NATGW_PUBLIC_IFACE $_ip $_maskbits >/dev/null 2>&1
+ "$CTDB_NATGW_PUBLIC_IFACE" "$_ip" "$_maskbits" >/dev/null 2>&1
for _net_gw in $CTDB_NATGW_STATIC_ROUTES ; do
_net="${_net_gw%@*}"
ip route del "$_net" metric 10 >/dev/null 2>/dev/null
# Delete the masquerading setup from a previous iteration where we
# were the NAT-GW
iptables -D POSTROUTING -t nat \
- -s $CTDB_NATGW_PRIVATE_NETWORK ! -d $CTDB_NATGW_PRIVATE_NETWORK \
+ -s "$CTDB_NATGW_PRIVATE_NETWORK" ! -d "$CTDB_NATGW_PRIVATE_NETWORK" \
-j MASQUERADE >/dev/null 2>/dev/null
- iptables -D INPUT -p tcp --syn -d $_ip/32 -j REJECT 2>/dev/null
+ iptables -D INPUT -p tcp --syn -d "${_ip}/32" -j REJECT 2>/dev/null
}
natgw_clear ()
{
if [ -r "$natgw_cfg_old" ] ; then
- (. $natgw_cfg_old ; _natgw_clear)
+ (. "$natgw_cfg_old" ; _natgw_clear)
else
_natgw_clear
fi
{
set_proc sys/net/ipv4/ip_forward 1
iptables -A POSTROUTING -t nat \
- -s $CTDB_NATGW_PRIVATE_NETWORK ! -d $CTDB_NATGW_PRIVATE_NETWORK \
+ -s "$CTDB_NATGW_PRIVATE_NETWORK" ! -d "$CTDB_NATGW_PRIVATE_NETWORK" \
-j MASQUERADE
# block all incoming connections to the NATGW IP address
ctdb_natgw_public_ip_host="${CTDB_NATGW_PUBLIC_IP%/*}/32"
iptables -D INPUT -p tcp --syn \
- -d $ctdb_natgw_public_ip_host -j REJECT 2>/dev/null
+ -d "$ctdb_natgw_public_ip_host" -j REJECT 2>/dev/null
iptables -I INPUT -p tcp --syn \
- -d $ctdb_natgw_public_ip_host -j REJECT 2>/dev/null
+ -d "$ctdb_natgw_public_ip_host" -j REJECT 2>/dev/null
- ip addr add $CTDB_NATGW_PUBLIC_IP dev $CTDB_NATGW_PUBLIC_IFACE
+ ip addr add "$CTDB_NATGW_PUBLIC_IP" dev "$CTDB_NATGW_PUBLIC_IFACE"
for _net_gw in $CTDB_NATGW_STATIC_ROUTES ; do
_net="${_net_gw%@*}"
if [ "$_net" != "$_net_gw" ] ; then
loadconfig
-[ -f $CTDB_BASE/static-routes ] || {
+[ -f "${CTDB_BASE}/static-routes" ] || {
exit 0
}
# is invalid. Therefore, go to a little bit of trouble to indent
# the failure message so that it is associated with the above
# warning message and doesn't look too nasty.
- ip route flush table $_table_id 2>&1 | sed -e 's@^.@ &@'
+ ip route flush table "$_table_id" 2>&1 | sed -e 's@^.@ &@'
}
######################################################################
_out="${smbconf_cache}.out"
_err="${smbconf_cache}.err"
- timeout $_timeout testparm -v -s >"$_out" 2>"$_err"
+ timeout "$_timeout" testparm -v -s >"$_out" 2>"$_err"
case $? in
0) : ;;
124)
{
_timeout="$1"
- testparm_foreground_update $_timeout >/dev/null 2>&1 </dev/null &
+ testparm_foreground_update "$_timeout" >/dev/null 2>&1 </dev/null &
}
testparm_cat ()
_localhost="${CTDB_RPCINFO_LOCALHOST:-127.0.0.1}"
esac
- if ! ctdb_check_rpc_out=$(rpcinfo -T $_family $_localhost \
- $_progname $_version 2>&1) ; then
+ if ! ctdb_check_rpc_out=$(rpcinfo -T "$_family" "$_localhost" \
+ "$_progname" $_version 2>&1) ; then
ctdb_check_rpc_out="$_progname failed RPC check:
$ctdb_check_rpc_out"
echo "$ctdb_check_rpc_out"
for _family in $_families ; do
if [ -n "$_versions" ] ; then
for _version in $_versions ; do
- ctdb_check_rpc $_progname $_version $_family || return $?
+ ctdb_check_rpc "$_progname" "$_version" "$_family" || return $?
done
else
- ctdb_check_rpc $_progname "" $_family || return $?
+ ctdb_check_rpc "$_progname" "" "$_family" || return $?
fi
done
}
tgtd >/dev/null 2>&1
# Run a script for each currently hosted public IP address
- ips=$(echo "$all_ips" | awk -F'|' -v pnn=$pnn '$3 == pnn {print $2}')
+ ips=$(echo "$all_ips" | awk -F'|' -v pnn="$pnn" '$3 == pnn {print $2}')
for ip in $ips ; do
script="${CTDB_START_ISCSI_SCRIPTS}/${ip}.sh"
if [ -x "$script" ] ; then
"${CTDB_HELPER_BINDIR}/ctdb_lvs" list |
awk -v pnn="$pnn" '$1 != pnn { print $2 }' |
while read ip ; do
- ipvsadm -a -t "$CTDB_LVS_PUBLIC_IP" -r $ip -g
- ipvsadm -a -u "$CTDB_LVS_PUBLIC_IP" -r $ip -g
+ ipvsadm -a -t "$CTDB_LVS_PUBLIC_IP" -r "$ip" -g
+ ipvsadm -a -u "$CTDB_LVS_PUBLIC_IP" -r "$ip" -g
done
# Add localhost too...
return
fi
- if [ -f $CTDB_SYS_ETCDIR/sysconfig/$1 ]; then
- . $CTDB_SYS_ETCDIR/sysconfig/$1
- elif [ -f $CTDB_SYS_ETCDIR/default/$1 ]; then
- . $CTDB_SYS_ETCDIR/default/$1
- elif [ -f $CTDB_BASE/sysconfig/$1 ]; then
- . $CTDB_BASE/sysconfig/$1
+ if [ -f "${CTDB_SYS_ETCDIR}/sysconfig/$1" ]; then
+ . "${CTDB_SYS_ETCDIR}/sysconfig/$1"
+ elif [ -f "${CTDB_SYS_ETCDIR}/default/$1" ]; then
+ . "${CTDB_SYS_ETCDIR}/default/$1"
+ elif [ -f "${CTDB_BASE}/sysconfig/$1" ]; then
+ . "${CTDB_BASE}/sysconfig/$1"
fi
if [ "$1" = "ctdb" ] ; then
# configuration file.
debug ()
{
- if [ ${CTDB_SCRIPT_DEBUGLEVEL:-2} -ge 4 ] ; then
+ if [ "${CTDB_SCRIPT_DEBUGLEVEL:-2}" -ge 4 ] ; then
# If there are arguments then echo them. Otherwise expect to
# use stdin, which allows us to pass lots of debug using a
# here document.
*)
# Handle all syslog:* variants here too. There's no tool to do
# the lossy things, so just use logger.
- logger -t "ctdbd: ${_tag}" $*
+ logger -t "ctdbd: ${_tag}" "$*"
;;
esac
}
$_nice /usr/sbin/service "$_service_name" "$_op"
elif [ -x /bin/systemctl ]; then
$_nice /bin/systemctl "$_op" "$_service_name"
- elif [ -x $CTDB_SYS_ETCDIR/init.d/$_service_name ]; then
- $_nice $CTDB_SYS_ETCDIR/init.d/$_service_name "$_op"
- elif [ -x $CTDB_SYS_ETCDIR/rc.d/init.d/$_service_name ]; then
- $_nice $CTDB_SYS_ETCDIR/rc.d/init.d/$_service_name "$_op"
+ elif [ -x "${CTDB_SYS_ETCDIR}/init.d/${_service_name}" ]; then
+ $_nice "${CTDB_SYS_ETCDIR}/init.d/${_service_name}" "$_op"
+ elif [ -x "${CTDB_SYS_ETCDIR}/rc.d/init.d/${_service_name}" ]; then
+ $_nice "${CTDB_SYS_ETCDIR}/rc.d/init.d/${_service_name}" "$_op"
fi
}
return
}
- _remaining=$(get_tcp_connections_for_ip $_ip | wc -l)
+ _remaining=$(get_tcp_connections_for_ip "$_ip" | wc -l)
if [ $_remaining -eq 0 ] ; then
echo "Killed $_killcount TCP connections to released IP $_ip"
while read dest src; do
echo "Tickle TCP connection $src $dest"
- $CTDB tickle $src $dest >/dev/null 2>&1 || _failed=true
+ $CTDB tickle "$src" "$dest" >/dev/null 2>&1 || _failed=true
echo "Tickle TCP connection $dest $src"
- $CTDB tickle $dest $src >/dev/null 2>&1 || _failed=true
+ $CTDB tickle "$dest" "$src" >/dev/null 2>&1 || _failed=true
done
if $_failed ; then
{
_addr="${1%/*}" # Remove optional maskbits
- set -- $(ip_maskbits_iface $_addr)
+ set -- $(ip_maskbits_iface "$_addr")
if [ -n "$1" ] ; then
_maskbits="$1"
_iface="$2"
echo "Removing public address $_addr/$_maskbits from device $_iface"
- delete_ip_from_iface $_iface $_addr $_maskbits >/dev/null 2>&1
+ delete_ip_from_iface "$_iface" "$_addr" "$_maskbits" >/dev/null 2>&1
fi
}
ctdb_get_pnn
# What public IPs do I hold?
- _ips=$($CTDB -X ip | awk -F'|' -v pnn=$pnn '$3 == pnn {print $2}')
+ _ips=$($CTDB -X ip | awk -F'|' -v pnn="$pnn" '$3 == pnn {print $2}')
# IPs and port as ss filters
_ip_filter=""
# Record our current tickles in a temporary file
_my_tickles="${tickledir}/${_port}.tickles.$$"
for _i in $_ips ; do
- $CTDB -X gettickles $_i $_port |
+ $CTDB -X gettickles "$_i" "$_port" |
awk -F'|' 'NR > 1 { printf "%s:%s %s:%s\n", $2, $3, $4, $5 }'
done |
sort >"$_my_tickles"
# Add tickles for connections that we haven't already got tickles for
comm -23 "$_my_connections" "$_my_tickles" |
while read _src _dst ; do
- $CTDB addtickle $_src $_dst
+ $CTDB addtickle "$_src" "$_dst"
done
# Remove tickles for connections that are no longer there
comm -13 "$_my_connections" "$_my_tickles" |
while read _src _dst ; do
- $CTDB deltickle $_src $_dst
+ $CTDB deltickle "$_src" "$_dst"
done
rm -f "$_my_connections" "$_my_tickles"
. "$CTDB_RC_LOCAL"
}
-[ -x $CTDB_BASE/rc.local ] && {
- . $CTDB_BASE/rc.local
+[ -x "${CTDB_BASE}/rc.local" ] && {
+ . "${CTDB_BASE}/rc.local"
}
-[ -d $CTDB_BASE/rc.local.d ] && {
- for i in $CTDB_BASE/rc.local.d/* ; do
+[ -d "${CTDB_BASE}/rc.local.d" ] && {
+ for i in "${CTDB_BASE}/rc.local.d"/* ; do
[ -x "$i" ] && . "$i"
done
}
usage ()
{
- _c=$(basename $0)
+ _c=$(basename "$0")
cat <<EOF
usage: $_c { shutdown | startup }
$_c { stop | start } { nfs | nlockmgr }
# This is script is invoked from ctdb when certain events happen. See
# /etc/ctdb/notify.d/README for more details.
-d=$(dirname $0)
+d=$(dirname "$0")
nd="${d}/notify.d"
ok=true
ctdb_get_pnn
ctdb_ips=$($CTDB ip | tail -n +2)
sed_expr=$(echo "$ctdb_ips" |
- awk -v pnn=$pnn 'pnn == $2 { \
+ awk -v pnn="$pnn" 'pnn == $2 { \
ip = $1; gsub(/\./, "\\.", ip); \
printf "/statd-state@%s@/p\n", ip }')
if cat $files | sed -n "$sed_expr" | $CTDB ptrans "ctdb.tdb" ; then
# but only for the server-IPs that are hosted on this node.
ctdb_all_ips=$($CTDB ip all | tail -n +2)
sed_expr=$(echo "$ctdb_all_ips" |
- awk -v pnn=$pnn 'pnn == $2 { \
+ awk -v pnn="$pnn" 'pnn == $2 { \
ip = $1; gsub(/\./, "\\.", ip); \
printf "s/^key.*=.*statd-state@\\(%s\\)@\\([^\"]*\\).*/\\1 \\2/p\n", ip }')
# Reset stateval for each serverip
[ "$sip" = "$prev" ] || stateval="$state_even"
# Send notifies for server shutdown
- "$smnotify" --client=$cip --ip=$sip --server=$sip --stateval=$stateval
- "$smnotify" --client=$cip --ip=$sip --server=$NFS_HOSTNAME --stateval=$stateval
+ "$smnotify" --client="$cip" --ip="$sip" \
+ --server="$sip" --stateval="$stateval"
+ "$smnotify" --client="$cip" --ip="$sip" \
+ --server="$NFS_HOSTNAME" --stateval="$stateval"
# Send notifies for server startup
stateval=$(($stateval + 1))
- "$smnotify" --client=$cip --ip=$sip --server=$sip --stateval=$stateval
- "$smnotify" --client=$cip --ip=$sip --server=$NFS_HOSTNAME --stateval=$stateval
+ "$smnotify" --client="$cip" --ip="$sip" \
+ --server="$sip" --stateval="$stateval"
+ "$smnotify" --client="$cip" --ip="$sip" \
+ --server="$NFS_HOSTNAME" --stateval="$stateval"
done
echo "$items" | $CTDB ptrans "ctdb.tdb"
# hosted on this node and created since the last "update").
# There's nothing else we can do with them at this stage.
echo "$ctdb_all_ips" |
- awk -v pnn=$pnn 'pnn != $2 { print $1 }' |
+ awk -v pnn="$pnn" 'pnn != $2 { print $1 }' |
while read sip ; do
rm -f "statd-state@${sip}@"*
done