]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mkcephfs
authorSage Weil <sage@newdream.net>
Fri, 27 Feb 2009 23:11:19 +0000 (15:11 -0800)
committerSage Weil <sage@newdream.net>
Fri, 27 Feb 2009 23:11:49 +0000 (15:11 -0800)
Still need to add optional mkbtrfs + mount stuff.

debian/ceph-common.install
src/Makefile.am
src/mkcephfs [new file with mode: 0755]
src/mkcephfs.sh [deleted file]

index b9303a9e02b375686c424909db71c376bbac8e5d..51bf4f684dc1cb7b4e882578f334394144fbb3dc 100644 (file)
@@ -4,6 +4,7 @@ usr/bin/crushtool
 usr/bin/monmaptool
 usr/bin/osdmaptool
 usr/bin/csyn
-usr/sbin/mount.ceph
 usr/bin/crun
+usr/sbin/mount.ceph
+usr/sbin/mkcephfs
 usr/lib/ceph/ceph_common.sh
index 02beb29305e39fc74f0cc65f7b21adc74a7cd89b..01073385094f7520cfed83e213043df2beeb37a1 100644 (file)
@@ -52,7 +52,8 @@ bin_PROGRAMS = \
 sbin_PROGRAMS = \
        mount.ceph
 
-bin_SCRIPTS = crun ceph_init
+bin_SCRIPTS = crun
+sbin_SCRIPTS = mkcephfs
 
 testmsgr_SOURCES = testmsgr.cc msg/SimpleMessenger.cc
 testmsgr_LDADD = libcommon.a
@@ -165,7 +166,7 @@ noinst_LIBRARIES = \
 noinst_LIBRARIES += libcrush_so.a #libcephclient_so.a
 
 # extra bits
-EXTRA_DIST = dstart.sh dstop.sh mkcephfs.sh montest.sh restart.sh verify-mds-journal.sh vstart.sh \
+EXTRA_DIST = dstart.sh dstop.sh montest.sh restart.sh verify-mds-journal.sh vstart.sh \
             crun ceph_common.sh ceph_init ceph-daemons
 
 install-data-local:
diff --git a/src/mkcephfs b/src/mkcephfs
new file mode 100755 (executable)
index 0000000..9018fe5
--- /dev/null
@@ -0,0 +1,130 @@
+#!/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
diff --git a/src/mkcephfs.sh b/src/mkcephfs.sh
deleted file mode 100755 (executable)
index 7d42b44..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/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."
-