2017-02-08 05:00:53 +08:00
|
|
|
#!/bin/bash
|
|
|
|
# {{ ansible_managed }}
|
|
|
|
|
2018-07-17 00:09:33 +08:00
|
|
|
|
2018-09-29 00:07:08 +08:00
|
|
|
{% if osd_scenario != 'lvm' -%}
|
|
|
|
{% if disk_list.get('rc') == 0 -%}
|
2018-07-17 00:09:33 +08:00
|
|
|
#############
|
|
|
|
# VARIABLES #
|
|
|
|
#############
|
2017-12-18 23:43:37 +08:00
|
|
|
DOCKER_ENV=""
|
2017-06-26 21:40:30 +08:00
|
|
|
|
|
|
|
#############
|
|
|
|
# FUNCTIONS #
|
|
|
|
#############
|
2019-05-14 05:18:52 +08:00
|
|
|
function id_to_device () {
|
|
|
|
{% if dmcrypt | bool %}
|
2019-08-06 23:52:59 +08:00
|
|
|
docker run --rm --net=host --ulimit nofile=1024:4096 --ipc=host --pid=host --privileged=true -v /etc/ceph:/etc/ceph:z -v /var/lib/ceph/:/var/lib/ceph/:z -v /dev:/dev -v /etc/localtime:/etc/localtime:ro -e DEBUG=verbose -e CLUSTER={{ cluster }} {{ ceph_docker_registry }}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }} osd_ceph_disk_dmcrypt_data_map
|
2019-05-14 05:18:52 +08:00
|
|
|
{% endif %}
|
2019-08-06 23:52:59 +08:00
|
|
|
DATA_PART=$(docker run --rm --ulimit nofile=1024:4096 --privileged=true -v /dev/:/dev/ -v /etc/ceph:/etc/ceph:z --entrypoint ceph-disk {{ ceph_docker_registry }}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }} list | grep ", osd\.${1}," | awk '{ print $1 }')
|
2019-09-25 21:40:34 +08:00
|
|
|
if [[ "${DATA_PART}" =~ ^/dev/(cciss|nvme|loop) ]]; then
|
2019-05-14 05:18:52 +08:00
|
|
|
OSD_DEVICE=${DATA_PART:0:-2}
|
|
|
|
else
|
|
|
|
OSD_DEVICE=${DATA_PART:0:-1}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-09-21 21:02:16 +08:00
|
|
|
function expose_partitions () {
|
2019-05-14 05:18:52 +08:00
|
|
|
DOCKER_ENV=$(docker run --rm --net=host --privileged=true -v /dev/:/dev/ -v /etc/ceph:/etc/ceph:z -e CLUSTER={{ cluster }} -e OSD_DEVICE=${1} {{ ceph_docker_registry }}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }} disk_list)
|
2017-07-25 23:54:26 +08:00
|
|
|
}
|
2017-10-20 21:15:38 +08:00
|
|
|
{% else -%}
|
|
|
|
# NOTE(leseb): maintains backwards compatibility with old ceph-docker Jewel images
|
|
|
|
# Jewel images prior to https://github.com/ceph/ceph-docker/pull/797
|
|
|
|
REGEX="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
|
|
|
|
function expose_partitions {
|
2017-11-02 23:17:38 +08:00
|
|
|
if docker ps -a | grep -sq ceph-osd-prepare-{{ ansible_hostname }}-devdev${1}; then
|
|
|
|
if [[ ! -f {{ ceph_osd_docker_run_script_path }}/ceph-osd-prepare-{{ ansible_hostname }}-devdev${1}.log ]]; then
|
|
|
|
docker logs ceph-osd-prepare-{{ ansible_hostname }}-devdev${1} &> {{ ceph_osd_docker_run_script_path }}/ceph-osd-prepare-{{ ansible_hostname }}-devdev${1}.log
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if docker ps -a | grep -sq ceph-osd-prepare-{{ ansible_hostname }}-${1}; then
|
|
|
|
if [[ ! -f {{ ceph_osd_docker_run_script_path }}/ceph-osd-prepare-{{ ansible_hostname }}-${1}.log ]]; then
|
|
|
|
docker logs ceph-osd-prepare-{{ ansible_hostname }}-${1} &> {{ ceph_osd_docker_run_script_path }}/ceph-osd-prepare-{{ ansible_hostname }}-${1}.log
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
if [[ -f {{ ceph_osd_docker_run_script_path }}/ceph-osd-prepare-{{ ansible_hostname }}-devdev${1}.log ]]; then
|
|
|
|
part=$(grep "Journal is GPT partition" {{ ceph_osd_docker_run_script_path }}/ceph-osd-prepare-{{ ansible_hostname }}-devdev${1}.log | grep -Eo /dev/disk/by-partuuid/${REGEX} | uniq)
|
2017-12-18 23:43:37 +08:00
|
|
|
DOCKER_ENV="-e OSD_JOURNAL=$part"
|
2017-11-02 23:17:38 +08:00
|
|
|
fi
|
|
|
|
if [[ -f {{ ceph_osd_docker_run_script_path }}/ceph-osd-prepare-{{ ansible_hostname }}-${1}.log ]]; then
|
|
|
|
part=$(grep "Journal is GPT partition" {{ ceph_osd_docker_run_script_path }}/ceph-osd-prepare-{{ ansible_hostname }}-${1}.log | grep -Eo /dev/disk/by-partuuid/${REGEX} | uniq)
|
2017-12-18 23:43:37 +08:00
|
|
|
DOCKER_ENV="-e OSD_JOURNAL=$part"
|
|
|
|
fi
|
|
|
|
if [[ -z $DOCKER_ENV ]]; then
|
|
|
|
# NOTE(leseb): if we arrive here this probably means we just switched from non-containers to containers.
|
|
|
|
# This is tricky as we don't have any info on the type of OSD, this is 'only' a problem for non-collocated scenarios
|
|
|
|
# We can't assume that the 'ceph' is still present so calling Docker exec instead
|
|
|
|
part=$(docker run --privileged=true -v /dev:/dev --entrypoint /usr/sbin/ceph-disk {{ ceph_docker_registry}}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }} list /dev/${1} | awk '/journal / {print $1}')
|
|
|
|
DOCKER_ENV="-e OSD_JOURNAL=$part"
|
|
|
|
fi
|
|
|
|
# if empty, the previous command didn't find anything so we fail
|
|
|
|
if [[ -z $DOCKER_ENV ]]; then
|
|
|
|
echo "ERROR: could not discover ceph partitions"
|
|
|
|
exit 1
|
2017-10-20 21:15:38 +08:00
|
|
|
fi
|
|
|
|
}
|
2017-07-25 23:54:26 +08:00
|
|
|
|
2018-11-28 00:50:44 +08:00
|
|
|
{% endif -%}
|
|
|
|
|
2019-05-14 05:18:52 +08:00
|
|
|
id_to_device "$1"
|
|
|
|
expose_partitions "${OSD_DEVICE}"
|
2017-06-26 21:40:30 +08:00
|
|
|
|
2018-11-30 18:20:03 +08:00
|
|
|
# discover osd_objectstore for ceph-disk based osds
|
|
|
|
if [[ $DOCKER_ENV =~ "BLUESTORE" ]]; then
|
|
|
|
DOCKER_ENV="$DOCKER_ENV -e OSD_BLUESTORE=1"
|
|
|
|
elif [[ $DOCKER_ENV =~ "JOURNAL" ]]; then
|
|
|
|
DOCKER_ENV="$DOCKER_ENV -e OSD_FILESTORE=1"
|
|
|
|
fi
|
|
|
|
|
2018-09-29 00:07:08 +08:00
|
|
|
{% endif -%}
|
2018-07-17 00:09:33 +08:00
|
|
|
|
2017-06-26 21:40:30 +08:00
|
|
|
|
|
|
|
########
|
|
|
|
# MAIN #
|
|
|
|
########
|
2019-04-05 21:45:28 +08:00
|
|
|
{% set cpu_limit = ansible_processor_vcpus|int if ceph_osd_docker_cpu_limit|int > ansible_processor_vcpus|int else ceph_osd_docker_cpu_limit|int %}
|
2017-02-08 05:00:53 +08:00
|
|
|
|
2019-03-09 16:24:46 +08:00
|
|
|
{% if ceph_osd_numactl_opts != "" %}
|
|
|
|
numactl \
|
|
|
|
{{ ceph_osd_numactl_opts }} \
|
|
|
|
{% endif %}
|
2017-02-08 05:00:53 +08:00
|
|
|
/usr/bin/docker run \
|
|
|
|
--rm \
|
|
|
|
--net=host \
|
2017-06-26 21:40:30 +08:00
|
|
|
--privileged=true \
|
2017-07-25 23:54:26 +08:00
|
|
|
--pid=host \
|
2019-02-28 20:13:35 +08:00
|
|
|
--ipc=host \
|
2019-08-06 23:52:59 +08:00
|
|
|
--ulimit nofile=1024:4096 \
|
2019-02-25 22:19:44 +08:00
|
|
|
{% if osd_objectstore == 'filestore' -%}
|
2017-09-06 16:53:30 +08:00
|
|
|
--memory={{ ceph_osd_docker_memory_limit }} \
|
2019-02-25 22:19:44 +08:00
|
|
|
{% endif -%}
|
2018-10-06 06:53:40 +08:00
|
|
|
{% if ceph_docker_version.split('.')[0] is version_compare('13', '>=') -%}
|
2019-04-05 21:45:28 +08:00
|
|
|
--cpus={{ cpu_limit }} \
|
2017-09-06 16:53:30 +08:00
|
|
|
{% else -%}
|
2019-04-05 21:45:28 +08:00
|
|
|
--cpu-quota={{ cpu_limit * 100000 }} \
|
2017-09-06 16:53:30 +08:00
|
|
|
{% endif -%}
|
2017-12-12 05:17:22 +08:00
|
|
|
{% if ceph_osd_docker_cpuset_cpus is defined -%}
|
|
|
|
--cpuset-cpus='{{ ceph_osd_docker_cpuset_cpus }}' \
|
|
|
|
{% endif -%}
|
|
|
|
{% if ceph_osd_docker_cpuset_mems is defined -%}
|
|
|
|
--cpuset-mems='{{ ceph_osd_docker_cpuset_mems }}' \
|
|
|
|
{% endif -%}
|
2017-07-25 23:54:26 +08:00
|
|
|
-v /dev:/dev \
|
|
|
|
-v /etc/localtime:/etc/localtime:ro \
|
2018-04-17 21:32:53 +08:00
|
|
|
-v /var/lib/ceph:/var/lib/ceph:z \
|
|
|
|
-v /etc/ceph:/etc/ceph:z \
|
2018-04-12 21:52:30 +08:00
|
|
|
-v /var/run/ceph:/var/run/ceph:z \
|
2019-06-04 01:15:30 +08:00
|
|
|
-v /var/run/udev/:/var/run/udev/ \
|
2017-04-19 17:12:04 +08:00
|
|
|
{% if ansible_distribution == 'Ubuntu' -%}
|
|
|
|
--security-opt apparmor:unconfined \
|
|
|
|
{% endif -%}
|
2018-05-09 09:10:30 +08:00
|
|
|
{% if containerized_deployment_with_kv -%}
|
2017-07-25 23:54:26 +08:00
|
|
|
-e KV_TYPE={{ kv_type }} \
|
|
|
|
-e KV_IP={{ kv_endpoint }} \
|
|
|
|
-e KV_PORT={{ kv_port }} \
|
2017-02-08 05:00:53 +08:00
|
|
|
{% endif -%}
|
2018-11-30 18:20:03 +08:00
|
|
|
{% if dmcrypt -%}
|
2017-07-25 23:54:26 +08:00
|
|
|
-e OSD_DMCRYPT=1 \
|
2018-11-30 18:20:03 +08:00
|
|
|
{% else -%}
|
2017-07-25 23:54:26 +08:00
|
|
|
-e OSD_DMCRYPT=0 \
|
2017-02-08 05:00:53 +08:00
|
|
|
{% endif -%}
|
2017-07-25 23:54:26 +08:00
|
|
|
-e CLUSTER={{ cluster }} \
|
2017-10-23 21:57:24 +08:00
|
|
|
{% if (ceph_tcmalloc_max_total_thread_cache | int) > 0 and osd_objectstore == 'filestore' -%}
|
|
|
|
-e TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES={{ ceph_tcmalloc_max_total_thread_cache }} \
|
|
|
|
{% endif -%}
|
2018-07-09 22:58:35 +08:00
|
|
|
{% if osd_scenario == 'lvm' -%}
|
|
|
|
-v /run/lvm/lvmetad.socket:/run/lvm/lvmetad.socket \
|
|
|
|
-e CEPH_DAEMON=OSD_CEPH_VOLUME_ACTIVATE \
|
2018-09-29 00:07:08 +08:00
|
|
|
-e OSD_ID="$1" \
|
2018-07-09 22:58:35 +08:00
|
|
|
{% else -%}
|
2018-09-29 00:07:08 +08:00
|
|
|
$DOCKER_ENV \
|
2017-07-25 23:54:26 +08:00
|
|
|
-e CEPH_DAEMON=OSD_CEPH_DISK_ACTIVATE \
|
2019-05-14 05:18:52 +08:00
|
|
|
-e OSD_DEVICE="${OSD_DEVICE}" \
|
2018-07-09 22:58:35 +08:00
|
|
|
{% endif -%}
|
2019-05-14 05:18:52 +08:00
|
|
|
--name=ceph-osd-"$1" \
|
2017-02-08 05:00:53 +08:00
|
|
|
{{ ceph_osd_docker_extra_env }} \
|
|
|
|
{{ ceph_docker_registry }}/{{ ceph_docker_image }}:{{ ceph_docker_image_tag }}
|