github.com/gust1n/deis@v0.13.1-0.20141009230754-43ff4d95947b/store/monitor/bin/boot (about) 1 #!/bin/bash 2 # Borrows heavily from Seán C. McCord's https://github.com/Ulexus/docker-ceph repository 3 4 set -e 5 6 ETCD_PORT=${ETCD_PORT:-4001} 7 ETCD="$HOST:$ETCD_PORT" 8 ETCD_PATH=${ETCD_PATH:-/deis/store} 9 NUM_STORES=${NUM_STORES:-3} 10 PG_NUM=${PG_NUM:-128} # default for 3 OSDs 11 HOSTNAME=`hostname` 12 13 function etcd_set_default { 14 etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1 || true 15 } 16 17 if ! etcdctl --no-sync -C $ETCD get ${ETCD_PATH}/monSetupComplete >/dev/null 2>&1 ; then 18 echo "store-monitor: Ceph hasn't yet been deployed. Trying to deploy..." 19 # let's rock and roll. we need to obtain a lock so we can ensure only one machine is trying to deploy the cluster 20 if etcdctl --no-sync -C $ETCD mk ${ETCD_PATH}/monSetupLock $HOSTNAME >/dev/null 2>&1 \ 21 || [[ `etcdctl --no-sync -C $ETCD get ${ETCD_PATH}/monSetupLock` == "$HOSTNAME" ]] ; then 22 echo "store-monitor: obtained the lock to proceed with setting up." 23 24 # set some defaults in etcd if they're not passed in as environment variables 25 # these are templated in ceph.conf 26 etcd_set_default size ${NUM_STORES} 27 etcd_set_default minSize 1 28 etcd_set_default pgNum ${PG_NUM} 29 30 # Generate administrator key 31 ceph-authtool /etc/ceph/ceph.client.admin.keyring --create-keyring --gen-key -n client.admin --set-uid=0 --cap mon 'allow *' --cap osd 'allow *' --cap mds 'allow' 32 33 # Generate the mon. key 34 ceph-authtool /etc/ceph/ceph.mon.keyring --create-keyring --gen-key -n mon. --cap mon 'allow *' 35 36 fsid=$(uuidgen) 37 etcdctl --no-sync -C $ETCD set ${ETCD_PATH}/fsid ${fsid} >/dev/null 38 39 # Generate initial monitor map 40 monmaptool --create --add ${HOSTNAME} ${HOST} --fsid ${fsid} /etc/ceph/monmap 41 42 etcdctl --no-sync -C $ETCD set ${ETCD_PATH}/monKeyring < /etc/ceph/ceph.mon.keyring >/dev/null 43 etcdctl --no-sync -C $ETCD set ${ETCD_PATH}/adminKeyring < /etc/ceph/ceph.client.admin.keyring >/dev/null 44 45 # mark setup as complete 46 echo "store-monitor: setup complete." 47 etcdctl --no-sync -C $ETCD set ${ETCD_PATH}/monSetupComplete youBetcha >/dev/null 48 else 49 until etcdctl --no-sync -C $ETCD get ${ETCD_PATH}/monSetupComplete >/dev/null 2>&1 ; do 50 echo "store-monitor: waiting for another monitor to complete setup..." 51 sleep 5 52 done 53 fi 54 fi 55 56 until confd -onetime -node $ETCD -config-file /app/confd.toml >/dev/null 2>&1; do 57 echo "store-monitor: waiting for confd to write initial templates..." 58 sleep 5 59 done 60 61 # If we don't have a monitor keyring, this is a new monitor 62 if [ ! -e /var/lib/ceph/mon/ceph-${HOSTNAME}/keyring ]; then 63 if [ ! -f /etc/ceph/monmap ]; then 64 ceph mon getmap -o /etc/ceph/monmap 65 fi 66 67 # Import the client.admin keyring and the monitor keyring into a new, temporary one 68 ceph-authtool /tmp/ceph.mon.keyring --create-keyring --import-keyring /etc/ceph/ceph.client.admin.keyring 69 ceph-authtool /tmp/ceph.mon.keyring --import-keyring /etc/ceph/ceph.mon.keyring 70 71 # Make the monitor directory 72 mkdir -p /var/lib/ceph/mon/ceph-${HOSTNAME} 73 74 # Prepare the monitor daemon's directory with the map and keyring 75 ceph-mon --mkfs -i ${HOSTNAME} --monmap /etc/ceph/monmap --keyring /tmp/ceph.mon.keyring 76 77 # Clean up the temporary key 78 rm /tmp/ceph.mon.keyring 79 fi 80 81 exec /usr/bin/ceph-mon -d -i ${HOSTNAME} --public-addr ${HOST}:6789