github.com/spg/deis@v1.7.3/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  HOSTNAME=`hostname`
    10  
    11  function etcd_set_default {
    12    set +e
    13    ERROR="$(etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 2>&1 >/dev/null)"
    14    if [[ $? -ne 0 && $(echo $ERROR | grep -ive "key already exists") ]]; then
    15      echo "etcd_set_default: an etcd error occurred ($ERROR)"
    16      echo "aborting..."
    17      exit 1
    18    fi
    19    set -e
    20  }
    21  
    22  # set some defaults in etcd - these are templated in ceph.conf
    23  # These defaults are sane for 3 hosts, and may need to be tweaked for larger clusters.
    24  etcd_set_default delayStart 15
    25  etcd_set_default size 3 # maintain 3 copies of all data
    26  etcd_set_default minSize 1 # since we have 3 copies of data, the cluster can operate with just one host up
    27  etcd_set_default pgNum 64 # this gives us a reasonable number of placement groups per host, assuming 3 hosts and 12 pools
    28  
    29  # New clusters use 768 PGs per host (12 pools * 64 PGs per pool = 768 PGs per OSD)
    30  # However, upgraded clusters may still use 128 PGs per pool, so we set this to 1536 PGs per host to suppress the
    31  # "too many placement groups per host" warning
    32  etcd_set_default maxPGsPerOSDWarning 1536
    33  
    34  if ! etcdctl --no-sync -C $ETCD get ${ETCD_PATH}/monSetupComplete >/dev/null 2>&1 ; then
    35    echo "store-monitor: Ceph hasn't yet been deployed. Trying to deploy..."
    36    # let's rock and roll. we need to obtain a lock so we can ensure only one machine is trying to deploy the cluster
    37    if etcdctl --no-sync -C $ETCD mk ${ETCD_PATH}/monSetupLock $HOSTNAME >/dev/null 2>&1 \
    38    || [[ `etcdctl --no-sync -C $ETCD get ${ETCD_PATH}/monSetupLock` == "$HOSTNAME" ]] ; then
    39      echo "store-monitor: obtained the lock to proceed with setting up."
    40  
    41      # Generate administrator key
    42      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'
    43  
    44      # Generate the mon. key
    45      ceph-authtool /etc/ceph/ceph.mon.keyring --create-keyring --gen-key -n mon. --cap mon 'allow *'
    46  
    47      fsid=$(uuidgen)
    48      etcdctl --no-sync -C $ETCD set ${ETCD_PATH}/fsid ${fsid} >/dev/null
    49  
    50      # Generate initial monitor map
    51      monmaptool --create --add ${HOSTNAME} ${HOST} --fsid ${fsid} /etc/ceph/monmap
    52  
    53      etcdctl --no-sync -C $ETCD set ${ETCD_PATH}/monKeyring < /etc/ceph/ceph.mon.keyring >/dev/null
    54      etcdctl --no-sync -C $ETCD set ${ETCD_PATH}/adminKeyring < /etc/ceph/ceph.client.admin.keyring >/dev/null
    55  
    56      # mark setup as complete
    57      echo "store-monitor: setup complete."
    58      etcdctl --no-sync -C $ETCD set ${ETCD_PATH}/monSetupComplete youBetcha >/dev/null
    59    else
    60      until etcdctl --no-sync -C $ETCD get ${ETCD_PATH}/monSetupComplete >/dev/null 2>&1 ; do
    61        echo "store-monitor: waiting for another monitor to complete setup..."
    62        sleep 5
    63      done
    64    fi
    65  fi
    66  
    67  until confd -onetime -node $ETCD --confdir /app --log-level error; do
    68    echo "store-monitor: waiting for confd to write initial templates..."
    69    sleep 5
    70  done
    71  
    72  # If we don't have a monitor keyring, this is a new monitor
    73  if [ ! -e /var/lib/ceph/mon/ceph-${HOSTNAME}/keyring ]; then
    74    if [ ! -f /etc/ceph/monmap ]; then
    75      ceph mon getmap -o /etc/ceph/monmap
    76    fi
    77  
    78    # Import the client.admin keyring and the monitor keyring into a new, temporary one
    79    ceph-authtool /tmp/ceph.mon.keyring --create-keyring --import-keyring /etc/ceph/ceph.client.admin.keyring
    80    ceph-authtool /tmp/ceph.mon.keyring --import-keyring /etc/ceph/ceph.mon.keyring
    81  
    82    # Make the monitor directory
    83    mkdir -p /var/lib/ceph/mon/ceph-${HOSTNAME}
    84  
    85    # Prepare the monitor daemon's directory with the map and keyring
    86    ceph-mon --mkfs -i ${HOSTNAME} --monmap /etc/ceph/monmap --keyring /tmp/ceph.mon.keyring
    87  
    88    # Clean up the temporary key
    89    rm /tmp/ceph.mon.keyring
    90  fi
    91  
    92  exec /usr/bin/ceph-mon -d -i ${HOSTNAME} --public-addr ${HOST}:6789