--- /dev/null
+#!/bin/sh
+
+# if we start up as ./mkfs.ceph, assume everything else is in the
+# current directory too.
+if [ `dirname $0` = "." ] && [ $PWD != "/etc/init.d" ]; then
+ BINDIR=.
+ LIBDIR=.
+ ETCDIR=.
+else
+ BINDIR=/usr/bin
+ LIBDIR=/usr/lib/ceph
+ ETCDIR=/etc/ceph
+fi
+
+CCONF="$BINDIR/cconf"
+conf=$ETCDIR"/cluster.conf"
+
+. $LIBDIR/ceph_common.sh
+
+usage_exit() {
+ echo "usage: $0 [--allhosts] [-c conffile.conf] [--clobber_old_data] [--mkbtrfs]"
+ exit
+}
+
+allhosts=0
+clobber=""
+mkbtrfs=0
+numosd=
+
+while [ $# -ge 1 ]; do
+case $1 in
+ --allhosts)
+ allhosts=1
+ ;;
+ --clobber_old_data)
+ clobber="--clobber"
+ ;;
+ --mkbtrfs)
+ mkbtrfs=1
+ ;;
+ --conf_file | -c)
+ [ "$2" == "" ] && usage_exit
+ shift
+ conf=$1
+ ;;
+ --numosd)
+ shift
+ numosd=$1
+ ;;
+ *)
+ echo unrecognized option \'$1\'
+ usage_exit
+ ;;
+esac
+shift
+done
+
+what=$*
+
+if [[ $what = "" ]]; 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$'`
+fi
+
+# get hostname, minus any domain
+hostname=`hostname | cut -d . -f 1`
+
+
+# create the monmap if we're doing mon0
+if [[ $what =~ "mon0" ]]; then
+ # first, make a list of monitors
+ mons=`$CCONF -c $conf -l mon | egrep -v '^mon$' | sort`
+ args=""
+ for mon in $mons; do
+ get_conf addr "" "mon addr" mon0 mon global
+ args=$args" --add $addr"
+ done
+
+ # build monmap
+ monmap="/tmp/monmap.$$"
+ $BINDIR/monmaptool --create --clobber $args --print $monmap || exit 1
+
+ # build osdmap
+ osdmap="/tmp/osdmap.$$"
+ if [[ $numosd = "" ]]; then
+ maxosd=`$CCONF -c $conf -l osd | egrep -v '^osd$' | tail -1 | cut -c 4-`
+ numosd=$(($maxosd + 1))
+ echo max osd in $conf is $maxosd, num osd is $numosd
+ fi
+ $BINDIR/osdmaptool --clobber --createsimple $numosd $osdmap || exit 1
+fi
+
+# create monitors, osds
+for name in $what; do
+ type=`echo $name | cut -c 1-3` # e.g. 'mon', if $name is 'mon1'
+ num=`echo $name | cut -c 4-`
+ sections="$name $type global"
+
+ # what host is this daemon assigned to?
+ host=`$CCONF -c $conf -s $name -s $type host`
+ ssh=""
+ if [[ $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
+ continue;
+ fi
+
+ # we'll need to ssh into that host
+ ssh="ssh root@$host"
+ fi
+ else
+ host=$hostname
+ fi
+
+ if [[ $type = "mon" ]]; then
+ get_conf mon_path "" "mon data" $sections
+ $BINDIR/mkmonfs $clobber $mon_path --mon $num --monmap $monmap --osdmap $osdmap || exit 1
+ fi
+
+ if [[ $type = "osd" ]]; then
+ get_conf osd_path "" "osd data" $sections
+ [[ $ssh != "" ]] && scp $monmap $host:$monmap
+ $ssh $BINDIR/cosd --monmap_file $monmap --mkfs_for_osd $num $osd_path || exit 1
+ fi
+
+done
+++ /dev/null
-#!/bin/sh
-
-# figure machine's ip
-HOSTNAME=`hostname`
-IP=`host $HOSTNAME | cut -d ' ' -f 4`
-[ "$CEPH_BIN" == "" ] && CEPH_BIN=.
-
-echo hostname $HOSTNAME
-echo "ip $IP"
-if [ `echo $IP | grep '^127\\.'` ]
-then
- echo
- echo "WARNING: hostname resolves to loopback; remote hosts will not be able to"
- echo " connect. either adjust /etc/hosts, or edit this script to use your"
- echo " machine's real IP."
- echo
-fi
-
-# build a fresh fs monmap, mon fs
-$CEPH_BIN/monmaptool --create --clobber --add $IP:6789 --print .ceph_monmap
-$CEPH_BIN/mkmonfs --clobber mondata/mon0 --mon 0 --monmap .ceph_monmap
-
-# shared args
-ARGS="-d --debug_ms 1"
-
-# start monitor
-$CEPH_BIN/cmon $ARGS mondata/mon0 --debug_mon 20 --debug_ms 1
-
-# build and inject an initial osd map
-$CEPH_BIN/osdmaptool --clobber --createsimple .ceph_monmap 4 --print .ceph_osdmap
-$CEPH_BIN/cmonctl osd setmap 2 -i .ceph_osdmap
-
-# stop monitor
-killall cmon
-#$CEPH_BIN/cmonctl stop
-
-echo "mkfs done."
-