dokku / dokku-postgres

a postgres plugin for dokku
MIT License
490 stars 97 forks source link

Can't create after destroying same <name> #17

Closed ohardy closed 9 years ago

ohardy commented 9 years ago
$ sudo dokku postgres:destroy gitlab
 !    WARNING: Potentially Destructive Action
 !    This command will destroy gitlab Postgres service.
 !    To proceed, type "gitlab"

> gitlab
-----> Deleting gitlab
       No container exists for gitlab
       Removing data
=====> Postgres container deleted: gitlab
$ sudo dokku postgres:create gitlab
-----> Starting container
Error response from daemon: Conflict. The name "dokku.postgres.gitlab" is already in use by container 9bcf4fe90412. You have to delete (or rename) that container to be able to reuse that name.
josegonzalez commented 9 years ago

I think you may have manually stopped the container before attempting to destroy it. If so, you're going to have to manually remove the docker container.

ohardy commented 9 years ago

I didn't

josegonzalez commented 9 years ago

If you're on IRC, I might be able to help there for the next few minutes.

It sounds like either the container ID file didn't exist in the service directory OR the container id wasn't in the output of docker ps -aq --no-trunc CID. That check happens here. Can you gist the output of docker ps -a?

Flink commented 9 years ago

well there’s something weird indeed. Your output is

-----> Deleting gitlab
       No container exists for gitlab

where you should have

-----> Deleting gitlab
-----> Stopping container
=====> Container stopped
       Removing container

What is your docker version? Those services expect 1.8+. And what is your version of dokku?

I can’t reproduce this error using dokku master, docker 1.8 and master of this service.

josegonzalez commented 9 years ago

Bump :)

josegonzalez commented 9 years ago

Can you replicate this with latest master? I think we had a bug previously with how we handled files on disk.

ohardy commented 9 years ago

Yep ;) :

$ sudo dokku postgres:create test3
-----> Starting container
       Waiting for container to be ready
       Creating container database
=====> Postgres container created: test3
       DSN: postgres://postgres:61010b870786592682308e3f4582aff4@172.17.0.69:5432/test3

$ sudo dokku postgres:destroy test3
 !    WARNING: Potentially Destructive Action
 !    This command will destroy test3 Postgres service.
 !    To proceed, type "test3"

> test3
-----> Deleting test3
       No container exists for test3
       Removing data
rm: cannot remove ‘/var/lib/dokku/services/postgres/test3/data’: Device or resource busy

$ sudo dokku postgres:create test3
Postgres service test3 already exists
agungyuliaji commented 9 years ago

same problem here, but with different error when deleting database

$ dokku postgres:destroy testing
 !     WARNING: Potentially Destructive Action
 !     This command will destroy testing Postgres service.
 !     To proceed, type "testing"

> testing
-----> Deleting testing
-----> Stopping container
=====> Container stopped
       Removing container
       Removing data
rm: cannot remove '/var/lib/dokku/services/postgres/testing/data': Permission denied
josegonzalez commented 9 years ago

@agungyuliaji can you run:

DOKKU_TRACE=1 dokku postgres:destroy testing

After having created a database?

Flink commented 9 years ago

I had the issue the other day, I will make a PR to fix this (we need to delete the content from inside a container so we are root). As for the original problem I think this is related to docker 1.6 but I’m not sure. I think I’ll revamp the part where we delete the container too (by using its name instead of its id).

Flink commented 9 years ago

https://github.com/dokku/dokku-postgres/pull/34 should fix this issue

agungyuliaji commented 9 years ago

@josegonzalez Yes, after created a database

root@paas:~# dokku postgres:create testing
-----> Starting container
       Waiting for container to be ready
       Creating container database
=====> Postgres container created: testing
       DSN: postgres://postgres:2d9d1a3efdbe068ac6dcbd7b97ca8997@dokku-postgres-testing:5432/testing
root@paas:~# DOKKU_TRACE=1 dokku postgres:destroy testing
+ [[ -f /home/dokku/dokkurc ]]
+ [[ -d /home/dokku/.dokkurc ]]
+ [[ -n 1 ]]
+ set -x
+ parse_args postgres:destroy testing
+ for arg in '"$@"'
+ case "$arg" in
+ for arg in '"$@"'
+ case "$arg" in
+ return 0
+ args=("$@")
+ [[ postgres:destroy =~ ^--.* ]]
+ has_tty
++ /usr/bin/tty
+ [[ /dev/pts/0 == \n\o\t\ \a\ \t\t\y ]]
+ return 0
++ id -un
+ [[ root != \d\o\k\k\u ]]
+ [[ postgres:destroy != plugin:*install* ]]
+ [[ postgres:destroy != \p\l\u\g\i\n\:\u\p\d\a\t\e ]]
+ [[ postgres:destroy != nginx:*-logs ]]
+ sudo -u dokku -E -H /usr/local/bin/dokku postgres:destroy testing
+ [[ -f /home/dokku/dokkurc ]]
+ [[ -d /home/dokku/.dokkurc ]]
+ [[ -n 1 ]]
+ set -x
+ parse_args postgres:destroy testing
+ for arg in '"$@"'
+ case "$arg" in
+ for arg in '"$@"'
+ case "$arg" in
+ return 0
+ args=("$@")
+ [[ postgres:destroy =~ ^--.* ]]
+ has_tty
++ /usr/bin/tty
+ [[ /dev/pts/0 == \n\o\t\ \a\ \t\t\y ]]
+ return 0
++ id -un
+ [[ dokku != \d\o\k\k\u ]]
+ [[ -n '' ]]
+ case "$1" in
+ implemented=0
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/00_dokku-standard/commands postgres:destroy testing
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/20_events/commands postgres:destroy testing
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/apps/commands postgres:destroy testing
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/backup/commands postgres:destroy testing
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/certs/commands postgres:destroy testing
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/config/commands postgres:destroy testing
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/docker-options/commands postgres:destroy testing
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/domains/commands postgres:destroy testing
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/enter/commands postgres:destroy testing
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/git/commands postgres:destroy testing
+ source /var/lib/dokku/core-plugins/available/common/functions
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
+ case "$1" in
+ exit 10
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/logs/commands postgres:destroy testing
+ source /var/lib/dokku/core-plugins/available/common/functions
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
+ source /var/lib/dokku/plugins/available/config/functions
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
++ source /var/lib/dokku/core-plugins/available/common/functions
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
+ source /var/lib/dokku/plugins/available/nginx-vhosts/functions
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
++ source /var/lib/dokku/core-plugins/available/common/functions
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
++ source /var/lib/dokku/plugins/available/certs/functions
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
+++ source /var/lib/dokku/core-plugins/available/common/functions
++++ set -eo pipefail
++++ [[ -n 1 ]]
++++ set -x
++ source /var/lib/dokku/plugins/available/config/functions
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
+++ source /var/lib/dokku/core-plugins/available/common/functions
++++ set -eo pipefail
++++ [[ -n 1 ]]
++++ set -x
++ source /var/lib/dokku/plugins/available/domains/functions
+++ set -eo pipefail
+++ [[ -n 1 ]]
+++ set -x
+++ source /var/lib/dokku/core-plugins/available/common/functions
++++ set -eo pipefail
++++ [[ -n 1 ]]
++++ set -x
+ case "$1" in
+ exit 10
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/mysql/commands postgres:destroy testing
+ PLUGIN_BASE_PATH=/var/lib/dokku/plugins
+ [[ -n 1 ]]
+ PLUGIN_BASE_PATH=/var/lib/dokku/plugins/enabled
+ source /var/lib/dokku/plugins/enabled/common/functions
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
++ dirname /var/lib/dokku/plugins/enabled/mysql/commands
+ source /var/lib/dokku/plugins/enabled/mysql/functions
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
+++ dirname /var/lib/dokku/plugins/enabled/mysql/commands
++ source /var/lib/dokku/plugins/enabled/mysql/config
+++ export MYSQL_IMAGE=mysql
+++ MYSQL_IMAGE=mysql
+++ export MYSQL_IMAGE_VERSION=5.6.26
+++ MYSQL_IMAGE_VERSION=5.6.26
+++ export MYSQL_ROOT=/var/lib/dokku/services/mysql
+++ MYSQL_ROOT=/var/lib/dokku/services/mysql
+++ export PLUGIN_COMMAND_PREFIX=mysql
+++ PLUGIN_COMMAND_PREFIX=mysql
+++ export PLUGIN_DATA_ROOT=/var/lib/dokku/services/mysql
+++ PLUGIN_DATA_ROOT=/var/lib/dokku/services/mysql
+++ PLUGIN_DATASTORE_PORTS=(3306)
+++ export PLUGIN_DATASTORE_PORTS
+++ export PLUGIN_DEFAULT_ALIAS=DATABASE
+++ PLUGIN_DEFAULT_ALIAS=DATABASE
+++ export PLUGIN_ALT_ALIAS=DOKKU_MYSQL
+++ PLUGIN_ALT_ALIAS=DOKKU_MYSQL
+++ export PLUGIN_IMAGE=mysql
+++ PLUGIN_IMAGE=mysql
+++ export PLUGIN_IMAGE_VERSION=5.6.26
+++ PLUGIN_IMAGE_VERSION=5.6.26
+++ export PLUGIN_SCHEME=mysql
+++ PLUGIN_SCHEME=mysql
+++ export PLUGIN_SERVICE=MySQL
+++ PLUGIN_SERVICE=MySQL
++ dirname /var/lib/dokku/plugins/enabled/mysql/commands
+ source /var/lib/dokku/plugins/enabled/mysql/config
++ export MYSQL_IMAGE=mysql
++ MYSQL_IMAGE=mysql
++ export MYSQL_IMAGE_VERSION=5.6.26
++ MYSQL_IMAGE_VERSION=5.6.26
++ export MYSQL_ROOT=/var/lib/dokku/services/mysql
++ MYSQL_ROOT=/var/lib/dokku/services/mysql
++ export PLUGIN_COMMAND_PREFIX=mysql
++ PLUGIN_COMMAND_PREFIX=mysql
++ export PLUGIN_DATA_ROOT=/var/lib/dokku/services/mysql
++ PLUGIN_DATA_ROOT=/var/lib/dokku/services/mysql
++ PLUGIN_DATASTORE_PORTS=(3306)
++ export PLUGIN_DATASTORE_PORTS
++ export PLUGIN_DEFAULT_ALIAS=DATABASE
++ PLUGIN_DEFAULT_ALIAS=DATABASE
++ export PLUGIN_ALT_ALIAS=DOKKU_MYSQL
++ PLUGIN_ALT_ALIAS=DOKKU_MYSQL
++ export PLUGIN_IMAGE=mysql
++ PLUGIN_IMAGE=mysql
++ export PLUGIN_IMAGE_VERSION=5.6.26
++ PLUGIN_IMAGE_VERSION=5.6.26
++ export PLUGIN_SCHEME=mysql
++ PLUGIN_SCHEME=mysql
++ export PLUGIN_SERVICE=MySQL
++ PLUGIN_SERVICE=MySQL
+ [[ postgres:destroy == mysql:* ]]
+ case "$1" in
+ exit 10
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/nginx-vhosts/commands postgres:destroy testing
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/plugin/commands postgres:destroy testing
+ exit_code=10
+ set -e
+ [[ 10 -eq 10 ]]
+ continue
+ for script in '$PLUGIN_ENABLED_PATH/*/commands'
+ set +e
+ /var/lib/dokku/plugins/enabled/postgres/commands postgres:destroy testing
+ PLUGIN_BASE_PATH=/var/lib/dokku/plugins
+ [[ -n 1 ]]
+ PLUGIN_BASE_PATH=/var/lib/dokku/plugins/enabled
+ source /var/lib/dokku/plugins/enabled/common/functions
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
++ dirname /var/lib/dokku/plugins/enabled/postgres/commands
+ source /var/lib/dokku/plugins/enabled/postgres/functions
++ set -eo pipefail
++ [[ -n 1 ]]
++ set -x
+++ dirname /var/lib/dokku/plugins/enabled/postgres/commands
++ source /var/lib/dokku/plugins/enabled/postgres/config
+++ export POSTGRES_IMAGE=postgres
+++ POSTGRES_IMAGE=postgres
+++ export POSTGRES_IMAGE_VERSION=9.4.4
+++ POSTGRES_IMAGE_VERSION=9.4.4
+++ export POSTGRES_ROOT=/var/lib/dokku/services/postgres
+++ POSTGRES_ROOT=/var/lib/dokku/services/postgres
+++ export PLUGIN_COMMAND_PREFIX=postgres
+++ PLUGIN_COMMAND_PREFIX=postgres
+++ export PLUGIN_DATA_ROOT=/var/lib/dokku/services/postgres
+++ PLUGIN_DATA_ROOT=/var/lib/dokku/services/postgres
+++ PLUGIN_DATASTORE_PORTS=(5432)
+++ export PLUGIN_DATASTORE_PORTS
+++ export PLUGIN_DEFAULT_ALIAS=DATABASE
+++ PLUGIN_DEFAULT_ALIAS=DATABASE
+++ export PLUGIN_ALT_ALIAS=DOKKU_POSTGRES
+++ PLUGIN_ALT_ALIAS=DOKKU_POSTGRES
+++ export PLUGIN_IMAGE=postgres
+++ PLUGIN_IMAGE=postgres
+++ export PLUGIN_IMAGE_VERSION=9.4.4
+++ PLUGIN_IMAGE_VERSION=9.4.4
+++ export PLUGIN_SCHEME=postgres
+++ PLUGIN_SCHEME=postgres
+++ export PLUGIN_SERVICE=Postgres
+++ PLUGIN_SERVICE=Postgres
++ dirname /var/lib/dokku/plugins/enabled/postgres/commands
+ source /var/lib/dokku/plugins/enabled/postgres/config
++ export POSTGRES_IMAGE=postgres
++ POSTGRES_IMAGE=postgres
++ export POSTGRES_IMAGE_VERSION=9.4.4
++ POSTGRES_IMAGE_VERSION=9.4.4
++ export POSTGRES_ROOT=/var/lib/dokku/services/postgres
++ POSTGRES_ROOT=/var/lib/dokku/services/postgres
++ export PLUGIN_COMMAND_PREFIX=postgres
++ PLUGIN_COMMAND_PREFIX=postgres
++ export PLUGIN_DATA_ROOT=/var/lib/dokku/services/postgres
++ PLUGIN_DATA_ROOT=/var/lib/dokku/services/postgres
++ PLUGIN_DATASTORE_PORTS=(5432)
++ export PLUGIN_DATASTORE_PORTS
++ export PLUGIN_DEFAULT_ALIAS=DATABASE
++ PLUGIN_DEFAULT_ALIAS=DATABASE
++ export PLUGIN_ALT_ALIAS=DOKKU_POSTGRES
++ PLUGIN_ALT_ALIAS=DOKKU_POSTGRES
++ export PLUGIN_IMAGE=postgres
++ PLUGIN_IMAGE=postgres
++ export PLUGIN_IMAGE_VERSION=9.4.4
++ PLUGIN_IMAGE_VERSION=9.4.4
++ export PLUGIN_SCHEME=postgres
++ PLUGIN_SCHEME=postgres
++ export PLUGIN_SERVICE=Postgres
++ PLUGIN_SERVICE=Postgres
+ [[ postgres:destroy == postgres:* ]]
+ [[ ! -d /var/lib/dokku/services/postgres ]]
+ case "$1" in
+ [[ -z testing ]]
+ verify_service_name testing
+ local SERVICE=testing
+ [[ ! -n testing ]]
+ [[ ! -d /var/lib/dokku/services/postgres/testing ]]
+ return 0
+ SERVICE=testing
+ SERVICE_ROOT=/var/lib/dokku/services/postgres/testing
+ LINKS_FILE=/var/lib/dokku/services/postgres/testing/LINKS
+ [[ -s /var/lib/dokku/services/postgres/testing/LINKS ]]
+ [[ '' == \f\o\r\c\e ]]
+ [[ -z '' ]]
+ dokku_log_warn 'WARNING: Potentially Destructive Action'
+ echo ' !     WARNING: Potentially Destructive Action'
 !     WARNING: Potentially Destructive Action
+ dokku_log_warn 'This command will destroy testing Postgres service.'
+ echo ' !     This command will destroy testing Postgres service.'
 !     This command will destroy testing Postgres service.
+ dokku_log_warn 'To proceed, type "testing"'
+ echo ' !     To proceed, type "testing"'
 !     To proceed, type "testing"
+ echo ''

+ read -p '> ' service_name
> testing
+ [[ testing != \t\e\s\t\i\n\g ]]
+ dokku_log_info1 'Deleting testing'
+ echo '-----> Deleting testing'
-----> Deleting testing
+ [[ -f /var/lib/dokku/services/postgres/testing/ID ]]
+ docker ps -aq --no-trunc
++ cat /var/lib/dokku/services/postgres/testing/ID
+ grep -q 2211e94b187a6b9ce849103f2516c363609e32226b6546807143c23a962b28b2
++ cat /var/lib/dokku/services/postgres/testing/ID
+ ID=2211e94b187a6b9ce849103f2516c363609e32226b6546807143c23a962b28b2
+ service_stop testing
+ local SERVICE=testing
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/testing
++ get_service_name testing
++ local SERVICE=testing
++ echo dokku.postgres.testing
+ local SERVICE_NAME=dokku.postgres.testing
++ awk '{print $1}'
++ grep dokku.postgres.testing
++ docker ps -f status=running
+ local ID=2211e94b187a
+ [[ -z 2211e94b187a ]]
+ [[ -n 2211e94b187a ]]
+ dokku_log_info1_quiet 'Stopping container'
+ [[ -z '' ]]
+ echo '-----> Stopping container'
-----> Stopping container
+ docker stop dokku.postgres.testing
+ service_port_pause testing
+ local SERVICE=testing
+ local SERVICE_ROOT=/var/lib/dokku/services/postgres/testing
++ get_service_name testing
++ local SERVICE=testing
++ echo dokku.postgres.testing
+ local EXPOSED_NAME=dokku.postgres.testing.ambassador
+ local PORT_FILE=/var/lib/dokku/services/postgres/testing/PORT
+ local LOG_FAIL=
+ [[ '' == \t\r\u\e ]]
+ [[ ! -f /var/lib/dokku/services/postgres/testing/PORT ]]
+ return 0
+ dokku_log_info2 'Container stopped'
+ echo '=====> Container stopped'
=====> Container stopped
+ sleep 1
+ dokku_log_verbose_quiet 'Removing container'
+ [[ -z '' ]]
+ echo '       Removing container'
       Removing container
+ docker rm -v 2211e94b187a6b9ce849103f2516c363609e32226b6546807143c23a962b28b2
+ sleep 1
+ dokku_log_verbose_quiet 'Removing data'
+ [[ -z '' ]]
+ echo '       Removing data'
       Removing data
+ rm -rf /var/lib/dokku/services/postgres/testing
rm: cannot remove '/var/lib/dokku/services/postgres/testing/data': Permission denied
+ exit_code=1
+ set -e
+ [[ 1 -eq 10 ]]
+ implemented=1
+ [[ 1 -ne 0 ]]
+ exit 1
Flink commented 9 years ago

@agungyuliaji @ohardy Could you try with latest master? This issue should be fixed now.

agungyuliaji commented 9 years ago

Thank you @Flink, now its work :smile: