5 not_implemented_exit_code=1
12 A fake CTDB stub that prints items depending on the variables
13 FAKE_CTDB_PNN (default 0) depending on command-line options.
20 echo "${prog}: command \"$1\" not implemented in stub" >&2
21 exit $not_implemented_exit_code
24 # Don't set $POSIXLY_CORRECT here.
25 _temp=$(getopt -n "$prog" -o "Yvh" -l help -- "$@") || \
31 machine_readable=false
35 -Y) machine_readable=true ; shift ;;
36 -v) verbose=true ; shift ;;
38 -h|--help|*) usage ;; # * shouldn't happen, so this is reasonable.
46 # Make sure tickles file exists.
47 tickles_file="$CTDB_VARDIR/fake-ctdb/tickles"
48 mkdir -p $(dirname "$tickles_file")
54 pstore_dir="$CTDB_VARDIR/fake-ctdb/pstore/$1"
55 mkdir -p "$pstore_dir"
58 # For testing backward compatibility...
59 for i in $CTDB_NOT_IMPLEMENTED ; do
60 if [ "$i" = "$1" ] ; then
67 # NOTE: all nodes share the same public addresses file.
69 # This is completely stateless and IPs move unnecessarily.
70 _f="${CTDB_PUBLIC_ADDRESSES:-${CTDB_BASE}/public_addresses}"
71 if [ -f "$_f" ] ; then
73 echo ":Public IP:Node:ActiveInterface:AvailableInterfaces:ConfiguredInterfaces:"
76 echo ":Public IP:Node:"
78 # Here IPs are distributed across nodes in a stupid way...
80 while read _ip _ifaces ; do
84 # Find a node that is up... but don't loop forever.
86 while [ -f "${FAKE_CTDB_NODES_DOWN}/${_n}" ] ; do
88 if [ _n -eq $FAKE_CTDB_NUMNODES ] ; then
91 if [ $_n -eq $_orig ] ; then
92 _n=-1 # Never down! :-)
96 # If more than 1 interface, assume all
97 # addresses are on the 1st.
98 _first_iface="${_ifaces%%,*}"
99 # Only show interface if address is on
102 if [ "PNN:$_n" = $(ctdb -Y pnn) ]; then
103 _my_iface="$_first_iface"
105 echo ":${_ip}:${_n}:${_my_iface}:${_first_iface}:${_ifaces}:"
107 echo ":${_ip}:${_n}:"
115 echo "PNN:${FAKE_CTDB_PNN:-0}"
119 echo ":source ip:port:destination ip:port:"
120 while read src dst ; do
121 echo ":${src}:${dst}:"
122 done <"$tickles_file"
126 echo "$2 $3" >>"$tickles_file"
130 _t=$(grep -F -v "$2 $3" "$tickles_file")
131 echo "$_t" >"$tickles_file"
135 cat "$4" >"${pstore_dir}/$3"
139 cat "${pstore_dir}/$3" >"$4" 2>/dev/null
143 echo ":Name:LinkStatus:References:"
144 _f="${CTDB_PUBLIC_ADDRESSES:-${CTDB_BASE}/public_addresses}"
145 if [ -r "$_f" ] ; then
146 while read _ip _iface ; do
151 # For now assume _iface contains only 1.
152 if [ -f "{FAKE_CTDB_IFACES_DOWN}/${_iface}" ] ; then
155 # Nobody looks at references
156 echo ":${_iface}:${_status}:0"
163 # Existence of file means CTDB thinks interface is down.
164 _f="${FAKE_CTDB_IFACES_DOWN}/$2"
169 echo "ctdb setifacelink: unsupported interface status $3"
174 case "${CTDB_DEBUGLEVEL:-0}" in
188 :${_t}:${CTDB_DEBUGLEVEL}:
192 for _i in $FAKE_TCP_LISTEN ; do
193 if [ "$2" = "${_i##*:}" ] ; then
201 $machine_readable || not_implemented "$1, without -Y"
202 [ "$2" != "all" ] || not_implemented "scriptstatus all"
203 # For now just assume everything is good.
206 echo ":Type:Name:Code:Status:Start:End:Error Output...:"
207 for _i in "$CTDB_BASE/events.d/"*.* ; do
208 _b="${_i##*/}" # basename
211 if [ ! -x "$_i" ] ; then
215 echo ":${2:-monitor}:${_b}:${_code}:${_status}:${_d1}:${_d2}::"