|
|
d03ac3 |
#!/bin/bash
|
|
|
d03ac3 |
|
|
|
d03ac3 |
# Copyright (C) 2016 Red Hat, Inc.
|
|
|
d03ac3 |
#
|
|
|
d03ac3 |
# This program is free software: you can redistribute it and/or modify
|
|
|
d03ac3 |
# it under the terms of the GNU General Public License as published by
|
|
|
d03ac3 |
# the Free Software Foundation, either version 3 of the License, or
|
|
|
d03ac3 |
# (at your option) any later version.
|
|
|
d03ac3 |
#
|
|
|
d03ac3 |
# This program is distributed in the hope that it will be useful,
|
|
|
d03ac3 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
d03ac3 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
d03ac3 |
# GNU General Public License for more details.
|
|
|
d03ac3 |
#
|
|
|
d03ac3 |
# You should have received a copy of the GNU General Public License
|
|
|
d03ac3 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
d03ac3 |
|
|
|
d03ac3 |
set -euo pipefail
|
|
|
d03ac3 |
IFS=$'\n\t'
|
|
|
d03ac3 |
|
|
|
d03ac3 |
# This is a small wrapper script that automatically fetches
|
|
|
d03ac3 |
# the storage options from the docker-storage sysconfig file
|
|
|
d03ac3 |
# and passes them to the migrator.
|
|
|
d03ac3 |
#
|
|
|
d03ac3 |
# The script supports both in-container runs and direct
|
|
|
d03ac3 |
# invocation.
|
|
|
d03ac3 |
|
|
|
d03ac3 |
MIGRATOR=/usr/bin/v1.10-migrator-local
|
|
|
d03ac3 |
STORAGE_FILE=/etc/sysconfig/docker-storage
|
|
|
d03ac3 |
GRAPH=/var/lib/docker
|
|
|
d03ac3 |
|
|
|
d03ac3 |
main() {
|
|
|
d03ac3 |
|
|
|
d03ac3 |
# are we in a container?
|
|
|
d03ac3 |
if [[ -n ${container-} ]]; then
|
|
|
d03ac3 |
|
|
|
d03ac3 |
if [[ ! -d /host ]]; then
|
|
|
d03ac3 |
echo "ERROR: Running inside a container, but /host not mounted." >&2
|
|
|
d03ac3 |
exit 1
|
|
|
d03ac3 |
fi
|
|
|
d03ac3 |
|
|
|
d03ac3 |
cp "$MIGRATOR" /host/tmp
|
|
|
d03ac3 |
MIGRATOR="chroot /host /tmp/$(basename $MIGRATOR)"
|
|
|
d03ac3 |
STORAGE_FILE=/host${STORAGE_FILE}
|
|
|
d03ac3 |
fi
|
|
|
d03ac3 |
|
|
|
d03ac3 |
if [ ! -d "$GRAPH" ]; then
|
|
|
d03ac3 |
echo "ERROR: Cannot find docker root dir at \"$GRAPH\"." >&2
|
|
|
d03ac3 |
exit 1
|
|
|
d03ac3 |
fi
|
|
|
d03ac3 |
|
|
|
d03ac3 |
# load storage opts if we can find the file
|
|
|
d03ac3 |
local storage_opts=
|
|
|
d03ac3 |
if [ -r "$STORAGE_FILE" ] && grep -q -E '^DOCKER_STORAGE_OPTIONS\s*=' "$STORAGE_FILE"; then
|
|
|
d03ac3 |
storage_opts=$(sed -n -e 's/^DOCKER_STORAGE_OPTIONS\s*=\s*// p' "$STORAGE_FILE")
|
|
|
d03ac3 |
storage_opts=${storage_opts#\"}
|
|
|
d03ac3 |
storage_opts=${storage_opts%\"}
|
|
|
d03ac3 |
fi
|
|
|
d03ac3 |
|
|
|
d03ac3 |
CMD="$MIGRATOR --graph $GRAPH $storage_opts"
|
|
|
d03ac3 |
echo "RUNNING: $CMD"
|
|
|
d03ac3 |
eval $CMD
|
|
|
d03ac3 |
}
|
|
|
d03ac3 |
|
|
|
d03ac3 |
main "$@"
|