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