This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
sonic-buildimage/files/build_templates/docker_image_ctl.j2
Taoyu Li c9cc7aea41 [configdb] Migrate minigraph configurations to DB (#942)
Modify minigraph parser output format so it fit DB schema
Modify configuration templates to fit new schema
Systemd services dependencies are modified so database starts before any configuration consumer
2017-09-12 14:13:27 -07:00

53 lines
1.5 KiB
Django/Jinja

#!/bin/bash
# Obtain our platform and HWSKU as we will mount directories with these names in each docker
PLATFORM=`sonic-cfggen -v platform`
{%- if docker_container_name != "database" %}
HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'`
{%- endif %}
start() {
docker inspect --type container {{docker_container_name}} &>/dev/null
if [ "$?" -eq "0" ]; then
docker start {{docker_container_name}}
else
docker run -d {{docker_image_run_opt}} \
{%- if '--log-driver=json-file' in docker_image_run_opt or '--log-driver' not in docker_image_run_opt %}
--log-opt max-size=2M --log-opt max-file=5 \
{%- endif %}
-v /var/run/redis:/var/run/redis:rw \
-v /usr/share/sonic/device/$PLATFORM:/usr/share/sonic/platform:ro \
{%- if docker_container_name != "database" %}
-v /usr/share/sonic/device/$PLATFORM/$HWSKU:/usr/share/sonic/hwsku:ro \
{%- endif %}
--name={{docker_container_name}} {{docker_image_name}}:latest
fi
{%- if docker_container_name == "database" %}
while true; do
if [[ "$(docker exec -i database redis-cli ping)" =~ PONG.* ]]; then
break
fi
sleep 1
done
{%- endif %}
}
attach() {
docker attach --no-stdin {{docker_container_name}}
}
stop() {
docker stop {{docker_container_name}}
}
case "$1" in
start|stop|attach)
$1
;;
*)
echo "Usage: $0 {start|stop|attach}"
exit 1
;;
esac