3 CCONF="$BINDIR/ceph-conf"
5 default_conf=$ETCDIR"/ceph.conf"
12 if [ -x "$ETCDIR/fetch_config" ] && [ "$conf" = "$default_conf" ]; then
13 conf="/tmp/fetched.ceph.conf.$$"
14 echo "[$ETCDIR/fetch_config $conf]"
15 if $ETCDIR/fetch_config $conf && [ -e $conf ]; then true ; else
16 echo "$0: failed to fetch config with '$ETCDIR/fetch_config $conf'"
21 # make sure ceph.conf exists
22 if [ ! -e $conf ]; then
23 if [ "$conf" = "$default_conf" ]; then
24 echo "$0: ceph conf $conf not found; system is not configured."
27 echo "$0: ceph conf $conf not found!"
35 # what host is this daemon assigned to?
36 host=`$CCONF -c $conf -n $type.$id host`
37 if [ "$host" = "localhost" ]; then
38 echo "$0: use a proper short hostname (hostname -s), not 'localhost', in $conf section $type.$id; skipping entry"
41 if expr match "$host" '.*\.' > /dev/null 2>&1; then
42 echo "$0: $conf section $type.$id"
43 echo "contains host=$host, which contains dots; this is probably wrong"
44 echo "It must match the result of hostname -s"
49 get_conf user "" "user"
51 #echo host for $name is $host, i am $hostname
54 if [ -e "/var/lib/ceph/$type/$cluster-$id/upstart" ]; then
58 # sysvinit managed instance in standard location?
59 if [ -e "/var/lib/ceph/$type/$cluster-$id/sysvinit" ]; then
61 echo "=== $type.$id === "
65 # ignore all sections without 'host' defined
66 if [ -z "$host" ]; then
70 if [ "$host" != "$hostname" ]; then
71 # skip, unless we're starting remote daemons too
72 if [ $allhosts -eq 0 ]; then
76 # we'll need to ssh into that host
77 if [ -z "$user" ]; then
82 rootssh="ssh root@$host"
83 get_conf sshdir "$sshdir" "ssh path"
86 echo "=== $type.$id === "
92 if [ -z "$ssh" ]; then
93 [ $verbose -eq 1 ] && echo "--- $host# $1"
96 if [ "$whoami" = "$user" ] || [ -z "$user" ]; then
97 bash -c "$1" || { [ -z "$3" ] && echo "failed: '$1'" && exit 1; }
99 sudo su $user -c "$1" || { [ -z "$3" ] && echo "failed: '$1'" && exit 1; }
102 [ $verbose -eq 1 ] && echo "--- $ssh $2 \"if [ ! -d $sshdir ]; then mkdir -p $sshdir; fi; cd $sshdir ; ulimit -c unlimited ; $1\""
103 $ssh $2 "if [ ! -d $sshdir ]; then mkdir -p $sshdir; fi; cd $sshdir ; ulimit -c unlimited ; $1" || { [ -z "$3" ] && echo "failed: '$ssh $1'" && exit 1; }
109 if [ -z "$ssh" ]; then
110 [ $verbose -eq 1 ] && echo "--- $host# $1"
113 if [ "$whoami" = "$user" ] || [ -z "$user" ]; then
114 bash -c "$1" || { [ -z "$3" ] && echo "failed: '$1'" && ERR=1 && return 1; }
116 sudo su $user -c "$1" || { [ -z "$3" ] && echo "failed: '$1'" && ERR=1 && return 1; }
119 [ $verbose -eq 1 ] && echo "--- $ssh $2 \"if [ ! -d $sshdir ]; then mkdir -p $sshdir; fi; cd $sshdir ; ulimit -c unlimited ; $1\""
120 $ssh $2 "if [ ! -d $sshdir ]; then mkdir -p $sshdir; fi; cd $sshdir ; ulimit -c unlimited ; $1" || { [ -z "$3" ] && echo "failed: '$ssh $1'" && ERR=1 && return 1; }
126 if [ -z "$ssh" ]; then
127 [ $verbose -eq 1 ] && echo "--- $host# $1"
130 if [ "$whoami" = "root" ]; then
131 bash -c "$1" || { echo "failed: '$1'" ; exit 1; }
133 sudo bash -c "$1" || { echo "failed: '$1'" ; exit 1; }
136 [ $verbose -eq 1 ] && echo "--- $rootssh $2 \"if [ ! -d $sshdir ]; then mkdir -p $sshdir; fi ; cd $sshdir ; ulimit -c unlimited ; $1\""
137 $rootssh $2 "if [ ! -d $sshdir ]; then mkdir -p $sshdir; fi ; cd $sshdir; ulimit -c unlimited ; $1" || { echo "failed: '$rootssh $1'" ; exit 1; }
141 do_root_cmd_okfail() {
143 if [ -z "$ssh" ]; then
144 [ $verbose -eq 1 ] && echo "--- $host# $1"
147 if [ "$whoami" = "root" ]; then
148 bash -c "$1" || { [ -z "$3" ] && echo "failed: '$1'" && ERR=1 && return 1; }
150 sudo bash -c "$1" || { [ -z "$3" ] && echo "failed: '$1'" && ERR=1 && return 1; }
153 [ $verbose -eq 1 ] && echo "--- $rootssh $2 \"if [ ! -d $sshdir ]; then mkdir -p $sshdir; fi; cd $sshdir ; ulimit -c unlimited ; $1\""
154 $rootssh $2 "if [ ! -d $sshdir ]; then mkdir -p $sshdir; fi; cd $sshdir ; ulimit -c unlimited ; $1" || { [ -z "$3" ] && echo "failed: '$rootssh $1'" && ERR=1 && return 1; }
159 get_local_daemon_list() {
161 if [ -d "/var/lib/ceph/$type" ]; then
162 for p in `find -L /var/lib/ceph/$type -mindepth 1 -maxdepth 1 -type d`; do
164 if [ -e "/var/lib/ceph/$type/$i/sysvinit" ]; then
165 id=`echo $i | sed 's/[^-]*-//'`
166 local="$local $type.$id"
172 get_local_name_list() {
173 # enumerate local directories
175 get_local_daemon_list "mon"
176 get_local_daemon_list "osd"
177 get_local_daemon_list "mds"
178 get_local_daemon_list "mgr"
184 # extract list of monitors, mdss, osds, mgrs defined in startup.conf
185 allconf="$local "`$CCONF -c $conf -l mon | egrep -v '^mon$' || true ; \
186 $CCONF -c $conf -l mds | egrep -v '^mds$' || true ; \
187 $CCONF -c $conf -l mgr | egrep -v '^mgr$' || true ; \
188 $CCONF -c $conf -l osd | egrep -v '^osd$' || true`
190 if [ -z "$orig" ]; then
197 type=`echo $f | cut -c 1-3` # e.g. 'mon', if $item is 'mon1'
198 id=`echo $f | cut -c 4- | sed 's/\\.//'`
200 mon | osd | mds | mgr)
201 for d in $allconf; do
202 if echo $d | grep -q ^$type; then
208 if ! echo " " $allconf $local " " | egrep -q "( $type$id | $type.$id )"; then
209 echo "$0: $type.$id not found ($conf defines" $allconf", /var/lib/ceph defines" $local")"
225 [ "$verbose" -eq 1 ] && echo "$CCONF -c $conf -n $type.$id \"$key\""
226 eval "$var=\"`$CCONF -c $conf -n $type.$id \"$key\" || printf \"$def\"`\""
228 [ "$verbose" -eq 1 ] && echo "$CCONF -c $conf -s $1 \"$key\""
229 eval "$var=\"`$CCONF -c $conf -s $1 \"$key\" || eval printf \"$def\"`\""
237 [ "$val" = "0" ] && export $1=0
238 [ "$val" = "false" ] && export $1=0
239 [ "$val" = "1" ] && export $1=1
240 [ "$val" = "true" ] && export $1=1