ceph/src/ceph_common.sh

129 lines
2.6 KiB
Bash
Raw Normal View History

#!/bin/sh
2009-01-29 23:02:34 +00:00
CCONF="$BINDIR/cconf"
2009-03-11 23:21:50 +00:00
conf=$ETCDIR"/ceph.conf"
hostname=`hostname | cut -d . -f 1`
2009-03-11 23:21:50 +00:00
verify_conf() {
# make sure ceph.conf exists
if [ ! -e $conf ]; then
echo "$0: ceph conf $conf not found"
usage_exit
fi
}
check_host() {
# what host is this daemon assigned to?
2009-03-12 20:59:05 +00:00
host=`$CCONF -c $conf -i $id -t $type host`
ssh=""
dir=$PWD
if [ -n "$host" ]; then
#echo host for $name is $host, i am $hostname
if [ "$host" != "$hostname" ]; then
# skip, unless we're starting remote daemons too
if [ $allhosts -eq 0 ]; then
return 1
fi
# we'll need to ssh into that host
get_conf sshuser "" "user"
if [ -z "$sshuser" ]; then
ssh="ssh $host"
else
ssh="ssh $sshuser@$host"
fi
get_conf dir "$dir" "ssh path"
fi
else
host=$hostname
fi
echo -n "=== $name === "
return 0
}
do_cmd() {
if [ -z "$ssh" ]; then
[ $verbose -eq 1 ] && echo "--- $host# $1"
ulimit -c unlimited
bash -c "$1" || { echo "failed: '$1'" ; exit 1; }
else
[ $verbose -eq 1 ] && echo "--- $ssh $2 \"cd $dir ; ulimit -c unlimited ; $1\""
$ssh $2 "cd $dir ; ulimit -c unlimited ; $1" || { echo "failed: '$ssh $1'" ; exit 1; }
fi
}
get_name_list() {
orig=$1
if [ -z "$orig" ]; then
# extract list of monitors, mdss, osds defined in startup.conf
what=`$CCONF -c $conf -l mon | egrep -v '^mon$' ; \
$CCONF -c $conf -l mds | egrep -v '^mds$' ; \
$CCONF -c $conf -l osd | egrep -v '^osd$'`
return
fi
what=""
for f in "$orig"; do
type=`echo $f | cut -c 1-3` # e.g. 'mon', if $item is 'mon1'
bit=`$CCONF -c $conf -l $type | egrep -v "^$type$"`
case $f in
mon | osd | mds)
what="$what $bit"
;;
*)
2009-05-30 00:07:29 +00:00
if echo " " $bit " " | grep -v -q " $f "; then
echo "$0: $type '$f' not found ($conf defines "$bit")"
exit 1
fi
what="$what $f"
;;
esac
done
}
2009-01-29 23:02:34 +00:00
get_val() {
2009-02-27 23:46:10 +00:00
[ "$2" != "" ] && export $1=$2 || export $1=`$CCONF -c $conf "$3" "$4" "$5"`
2009-01-29 23:02:34 +00:00
}
get_val_bool() {
if [ "$2" != "" ]; then
export $1=$2
else
tmp=`$CCONF "$3" "$4" "$5"`
export $1=$5
[ "$tmp" = "0" ] && export $1=0
[ "$tmp" = "false" ] && export $1=0
[ "$tmp" = "1" ] && export $1=1
[ "$tmp" = "true" ] && export $1=1
2009-01-29 23:02:34 +00:00
fi
}
get_conf() {
var=$1
def=$2
key=$3
shift; shift; shift
[ $verbose -eq 1 ] && echo "$CCONF -c $conf -i $id -t $type $tmp \"$key\" \"$def\""
2009-03-11 22:23:46 +00:00
eval "$var=\"`$CCONF -c $conf -i $id -t $type $tmp \"$key\" \"$def\"`\""
2009-01-29 23:02:34 +00:00
}
get_conf_bool() {
get_conf "$@"
eval "val=$"$1
[ "$val" = "0" ] && export $1=0
[ "$val" = "false" ] && export $1=0
[ "$val" = "1" ] && export $1=1
[ "$val" = "true" ] && export $1=1
2009-01-29 23:02:34 +00:00
}