mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 17:26:28 +00:00
demo: Add formatting and mounting to etcd image
Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
parent
a3d20abdb6
commit
31a4156686
@ -1,6 +1,10 @@
|
||||
# A dockerfile to build an etcd container image from the upstream one
|
||||
# with a script as entry point
|
||||
FROM quay.io/coreos/etcd:v3.1.5
|
||||
|
||||
# sfdisk and jq re required to mount the disk
|
||||
RUN apk add --no-cache sfdisk jq
|
||||
|
||||
COPY ./etcd.sh /
|
||||
|
||||
ENTRYPOINT ["/etcd.sh"]
|
||||
|
@ -4,6 +4,39 @@
|
||||
set -x
|
||||
set -v
|
||||
|
||||
MOUNTPOINT=/var/etcd
|
||||
|
||||
mount_drive()
|
||||
{
|
||||
mkdir -p "$MOUNTPOINT"
|
||||
|
||||
# TODO fix for multiple disks, cdroms etc
|
||||
DEVS="$(find /dev -maxdepth 1 -type b ! -name 'loop*' ! -name 'nbd*' | grep -v '[0-9]$' | sed 's@.*/dev/@@' | sort)"
|
||||
|
||||
for DEV in $DEVS
|
||||
do
|
||||
DRIVE="/dev/${DEV}"
|
||||
|
||||
# see if it has a partition table
|
||||
if sfdisk -d "${DRIVE}" >/dev/null 2>/dev/null
|
||||
then
|
||||
# 83 is Linux partition identifier
|
||||
DATA=$(sfdisk -J "$DRIVE" | jq -e -r '.partitiontable.partitions | map(select(.type=="83")) | .[0].node')
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
mount "$DATA" "$MOUNTPOINT" && return
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo "WARNING: Failed to mount a persistent volume (is there one?)"
|
||||
|
||||
# not sure if we want to fatally bail here, in some debug situations it is ok
|
||||
# exit 1
|
||||
}
|
||||
|
||||
mount_drive
|
||||
|
||||
# Wait till we have an IP address
|
||||
IP=""
|
||||
while [ -z "$IP" ]; do
|
||||
@ -17,13 +50,20 @@ PREFIX=$(echo ${IP} | cut -d . -f 1,2,3)
|
||||
NAME=infra${NUM}
|
||||
|
||||
# This should come from Metadata
|
||||
INIT_CLUSTER=infra200=http://${PREFIX}.200:2380,infra201=http://${PREFIX}.201:2380,infra202=http://${PREFIX}.202:2380,infra203=http://${PREFIX}.203:2380,infra204=http://${PREFIX}.204:2380
|
||||
INIT_CLUSTER="infra200=http://${PREFIX}.200:2380,infra201=http://${PREFIX}.201:2380,infra202=http://${PREFIX}.202:2380,infra203=http://${PREFIX}.203:2380,infra204=http://${PREFIX}.204:2380"
|
||||
|
||||
# Try to start in *new* cluster mode
|
||||
# We currently have no easy way to determine if we join a cluster for
|
||||
# the first time or if we got restarted and need to join an existing
|
||||
# cluster. So we first try joining a *new* cluster. This fails if we
|
||||
# had already joined it previously. As a fallback we then try to join
|
||||
# an existing cluster.
|
||||
|
||||
# Try to join an new cluster
|
||||
/usr/local/bin/etcd \
|
||||
--name ${NAME} \
|
||||
--debug \
|
||||
--log-package-levels etcdmain=DEBUG,etcdserver=DEBUG \
|
||||
--data-dir $MOUNTPOINT \
|
||||
--initial-advertise-peer-urls http://${IP}:2380 \
|
||||
--listen-peer-urls http://${IP}:2380 \
|
||||
--listen-client-urls http://${IP}:2379,http://127.0.0.1:2379 \
|
||||
@ -34,11 +74,12 @@ INIT_CLUSTER=infra200=http://${PREFIX}.200:2380,infra201=http://${PREFIX}.201:23
|
||||
|
||||
[ $? -eq 0 ] && exit 0
|
||||
|
||||
# Joining the new cluster failed. Let's try joining an *existing* cluster
|
||||
# Try to join an existing cluster
|
||||
/usr/local/bin/etcd \
|
||||
--name ${NAME} \
|
||||
--debug \
|
||||
--log-package-levels etcdmain=DEBUG,etcdserver=DEBUG \
|
||||
--data-dir $MOUNTPOINT \
|
||||
--initial-advertise-peer-urls http://${IP}:2380 \
|
||||
--listen-peer-urls http://${IP}:2380 \
|
||||
--listen-client-urls http://${IP}:2379,http://127.0.0.1:2379 \
|
||||
|
Loading…
Reference in New Issue
Block a user