2017-01-29 13:33:33 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-09-14 10:43:02 -05:00
|
|
|
function getMountPoint()
|
|
|
|
{
|
|
|
|
echo $1 | python -c "import sys, json, os; mnts = [x for x in json.load(sys.stdin)[0]['Mounts'] if x['Destination'] == '/usr/share/sonic/hwsku']; print '' if len(mnts) == 0 else os.path.basename(mnts[0]['Source'])" 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
function postStartAction()
|
|
|
|
{
|
2018-02-26 13:23:29 -06:00
|
|
|
{%- if docker_container_name == "database" %}
|
2018-01-18 21:55:11 -06:00
|
|
|
until [[ $(/usr/bin/docker exec database redis-cli ping | grep -c PONG) -gt 0 ]]; do
|
|
|
|
sleep 1;
|
2017-09-14 10:43:02 -05:00
|
|
|
done
|
2018-02-26 13:23:29 -06:00
|
|
|
{%- elif docker_container_name == "swss" %}
|
|
|
|
docker exec swss rm -f /ready # remove cruft
|
|
|
|
if [[ -d /host/fast-reboot ]];
|
|
|
|
then
|
|
|
|
test -e /host/fast-reboot/fdb.json && docker cp /host/fast-reboot/fdb.json swss:/
|
|
|
|
test -e /host/fast-reboot/arp.json && docker cp /host/fast-reboot/arp.json swss:/
|
|
|
|
test -e /host/fast-reboot/default_routes.json && docker cp /host/fast-reboot/default_routes.json swss:/
|
|
|
|
rm -fr /host/fast-reboot
|
|
|
|
fi
|
|
|
|
docker exec swss touch /ready # signal swssconfig.sh to go
|
|
|
|
{%- elif docker_container_name == "snmp" %}
|
2017-12-19 18:02:26 -06:00
|
|
|
docker exec -i database redis-cli -n 6 HSET 'DEVICE_METADATA|localhost' chassis_serial_number $(decode-syseeprom -s)
|
2018-02-26 13:23:29 -06:00
|
|
|
{%- else %}
|
2018-02-26 19:42:20 -06:00
|
|
|
: # nothing
|
2017-12-19 18:02:26 -06:00
|
|
|
{%- endif %}
|
2017-09-14 10:43:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
# Obtain our platform as we will mount directories with these names in each docker
|
2018-02-20 16:38:13 -06:00
|
|
|
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
|
2017-09-14 10:43:02 -05:00
|
|
|
|
|
|
|
{%- if docker_container_name == "database" %}
|
|
|
|
# Don't mount HWSKU in {{docker_container_name}} container.
|
|
|
|
HWSKU=""
|
|
|
|
{%- else %}
|
|
|
|
# Obtain our HWSKU as we will mount directories with these names in each docker
|
2017-09-12 16:13:27 -05:00
|
|
|
HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'`
|
|
|
|
{%- endif %}
|
2017-02-27 02:13:36 -06:00
|
|
|
|
2017-01-29 13:33:33 -06:00
|
|
|
start() {
|
2017-09-14 10:43:02 -05:00
|
|
|
DOCKERCHECK=`docker inspect --type container {{docker_container_name}} 2>/dev/null`
|
2017-01-29 13:33:33 -06:00
|
|
|
if [ "$?" -eq "0" ]; then
|
2017-09-14 10:43:02 -05:00
|
|
|
DOCKERMOUNT=`getMountPoint "$DOCKERCHECK"`
|
|
|
|
if [ "$DOCKERMOUNT" == "$HWSKU" ]; then
|
|
|
|
echo "Starting existing {{docker_container_name}} container with HWSKU $HWSKU"
|
|
|
|
docker start {{docker_container_name}}
|
|
|
|
postStartAction
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# docker created with a different HWSKU, remove and recreate
|
|
|
|
echo "Removing obsolete {{docker_container_name}} container with HWSKU $DOCKERMOUNT"
|
|
|
|
docker rm {{docker_container_name}}
|
|
|
|
fi
|
2017-03-23 14:18:52 -05:00
|
|
|
|
2017-09-14 10:43:02 -05:00
|
|
|
{%- if docker_container_name == "database" %}
|
|
|
|
echo "Starting new {{docker_container_name}} container"
|
|
|
|
{%- else %}
|
|
|
|
echo "Starting new {{docker_container_name}} container with HWSKU $HWSKU"
|
|
|
|
{%- endif %}
|
|
|
|
docker run -d {{docker_image_run_opt}} \
|
2017-05-05 19:44:36 -05:00
|
|
|
{%- if '--log-driver=json-file' in docker_image_run_opt or '--log-driver' not in docker_image_run_opt %}
|
2017-09-14 10:43:02 -05:00
|
|
|
--log-opt max-size=2M --log-opt max-file=5 \
|
2018-04-02 22:24:59 -05:00
|
|
|
{%- endif %}
|
|
|
|
{%- if docker_container_name == "syncd" and sonic_asic_platform == "mellanox" %}
|
|
|
|
-e SX_SNIFFER_ENABLE \
|
|
|
|
-e SX_SNIFFER_TARGET \
|
|
|
|
-e PRM_SNIFFER \
|
|
|
|
-e PRM_SNIFFER_FILE_PATH \
|
|
|
|
-v /var/log/mellanox/sniffer:/var/log/mellanox/sniffer:rw \
|
2017-05-05 19:44:36 -05:00
|
|
|
{%- endif %}
|
2017-09-14 10:43:02 -05:00
|
|
|
-v /var/run/redis:/var/run/redis:rw \
|
|
|
|
-v /usr/share/sonic/device/$PLATFORM:/usr/share/sonic/platform:ro \
|
2017-09-12 16:13:27 -05:00
|
|
|
{%- if docker_container_name != "database" %}
|
2017-09-14 10:43:02 -05:00
|
|
|
-v /usr/share/sonic/device/$PLATFORM/$HWSKU:/usr/share/sonic/hwsku:ro \
|
2017-09-12 16:13:27 -05:00
|
|
|
{%- endif %}
|
2018-01-17 01:20:13 -06:00
|
|
|
--tmpfs /tmp \
|
|
|
|
--tmpfs /var/tmp \
|
2017-09-14 10:43:02 -05:00
|
|
|
--name={{docker_container_name}} {{docker_image_name}}:latest
|
|
|
|
|
|
|
|
postStartAction
|
2017-01-29 13:33:33 -06:00
|
|
|
}
|
|
|
|
|
[oneimage]: Fix race condition in systemd container services (#421)
When Type=simple, systemd will consider the service activated immediately
after specified in ExecStart process is started. If there is downstream
service depending on the state prepared in ExecStart, there will be race condition.
For example, issue #390. In this case, database.service calls database.sh, which
calls docker run or docker start -a to start database container. However, systemd
considers database.service successfully started at the time database.sh begins,
not after docker run finishes. As database.service is consider started, bgp.service
can be started. The redis database, which bgp service depends on, might or might not
have been started at this time point.
To fix this issue (and still keeping the functionality to monitor docker status with
systemd), we split the ExecStart process into an ExecStartPre part and an ExecStart
part. docker run is splitted into docker run -d then docker attach , while docker start
-a is splitted into docker start and then docker attach. In this way, we make sure
the downstream services are blocked until container is successfully started.
2017-03-22 15:04:48 -05:00
|
|
|
attach() {
|
|
|
|
docker attach --no-stdin {{docker_container_name}}
|
|
|
|
}
|
|
|
|
|
2017-01-29 13:33:33 -06:00
|
|
|
stop() {
|
|
|
|
docker stop {{docker_container_name}}
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
[oneimage]: Fix race condition in systemd container services (#421)
When Type=simple, systemd will consider the service activated immediately
after specified in ExecStart process is started. If there is downstream
service depending on the state prepared in ExecStart, there will be race condition.
For example, issue #390. In this case, database.service calls database.sh, which
calls docker run or docker start -a to start database container. However, systemd
considers database.service successfully started at the time database.sh begins,
not after docker run finishes. As database.service is consider started, bgp.service
can be started. The redis database, which bgp service depends on, might or might not
have been started at this time point.
To fix this issue (and still keeping the functionality to monitor docker status with
systemd), we split the ExecStart process into an ExecStartPre part and an ExecStart
part. docker run is splitted into docker run -d then docker attach , while docker start
-a is splitted into docker start and then docker attach. In this way, we make sure
the downstream services are blocked until container is successfully started.
2017-03-22 15:04:48 -05:00
|
|
|
start|stop|attach)
|
2017-01-29 13:33:33 -06:00
|
|
|
$1
|
|
|
|
;;
|
|
|
|
*)
|
[oneimage]: Fix race condition in systemd container services (#421)
When Type=simple, systemd will consider the service activated immediately
after specified in ExecStart process is started. If there is downstream
service depending on the state prepared in ExecStart, there will be race condition.
For example, issue #390. In this case, database.service calls database.sh, which
calls docker run or docker start -a to start database container. However, systemd
considers database.service successfully started at the time database.sh begins,
not after docker run finishes. As database.service is consider started, bgp.service
can be started. The redis database, which bgp service depends on, might or might not
have been started at this time point.
To fix this issue (and still keeping the functionality to monitor docker status with
systemd), we split the ExecStart process into an ExecStartPre part and an ExecStart
part. docker run is splitted into docker run -d then docker attach , while docker start
-a is splitted into docker start and then docker attach. In this way, we make sure
the downstream services are blocked until container is successfully started.
2017-03-22 15:04:48 -05:00
|
|
|
echo "Usage: $0 {start|stop|attach}"
|
2017-01-29 13:33:33 -06:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|