Skip to content

Commit

Permalink
Avoid permission problems at container creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kloadut committed Jan 7, 2014
1 parent 85ea169 commit 4f90e2d
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions commands
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ case "$1" in
exit 1
fi
# Check if an existing DB volume exists
if [[ -d "/var/lib/docker/vfs/dir/postgresql-$APP" ]]; then
VOLUME="/var/lib/docker/vfs/dir/postgresql-$APP:/opt/postgresql"
if [[ -f "$DOKKU_ROOT/.postgresql/volume_$APP" ]]; then
VOLUME="`cat $DOKKU_ROOT/.postgresql/volume_$APP`:/opt/postgresql"
echo
echo "-----> Reusing postgresql/$APP database"
else
Expand All @@ -54,15 +54,13 @@ case "$1" in
ID=$(docker run -v $VOLUME -p 5432 -d $DB_IMAGE /usr/bin/start_pgsql.sh $DB_PASSWORD)
sleep 4
# Rename persistent volume
if [[ ! -d "/var/lib/docker/vfs/dir/postgresql-$APP" ]]; then
if [[ ! -f "$DOKKU_ROOT/.postgresql/volume_$APP" ]]; then
VOLUME_PATH=$(docker inspect $ID | grep /var/lib/docker/vfs/dir/ | awk '{print $2}' | sed -e's/"//g')
if [[ -z $VOLUME_PATH ]]; then
echo "Your docker version is too old, please update it"
exit 1
fi
mv $VOLUME_PATH "/var/lib/docker/vfs/dir/postgresql-$APP"
ln -s "/var/lib/docker/vfs/dir/postgresql-$APP" $VOLUME_PATH
sleep 1
echo $VOLUME_PATH > "$DOKKU_ROOT/.postgresql/volume_$APP"
fi
# Write port for further usage
PORT=$(docker port $ID 5432 | sed 's/0.0.0.0://')
Expand All @@ -78,7 +76,6 @@ case "$1" in
postgresql:delete)
DB_IMAGE=postgresql/$APP
ID=$(docker ps -a | grep "$DB_IMAGE":latest | awk '{print $1}')
VOLUME_PATH=$(docker inspect $ID | grep /var/lib/docker/vfs/dir/ | awk '{print $2}' | sed -e's/"//g')
# Stop the container
if [[ ! -z $ID ]]; then
docker kill $ID
Expand All @@ -92,9 +89,9 @@ case "$1" in
docker rmi $IMAGE
fi
# Remove persistent volume
if [[ -d "/var/lib/docker/vfs/dir/postgresql-$APP" ]]; then
rm -rf "/var/lib/docker/vfs/dir/postgresql-$APP"
rm -f $VOLUME_PATH
if [[ -f "$DOKKU_ROOT/.postgresql/volume_$APP" ]]; then
rm -rf $(cat $DOKKU_ROOT/.postgresql/volume_$APP) || :
rm -f "$DOKKU_ROOT/.postgresql/volume_$APP"
fi
# Remove container port storage
if [[ -f "$DOKKU_ROOT/.postgresql/port_$APP" ]]; then
Expand Down

0 comments on commit 4f90e2d

Please sign in to comment.