Loomio

Installation on Docker - database "loomio_production" does not exist

Stuart North PublicSeen by 115

Hi Everyone, I am trying to install Loomio following the instructions at https://github.com/loomio/loomio-deploy.
After a few false starts (completely new to Docker) I've managed to get this far;
Fresh install of Ubuntu 18.04
Install of Docker via Snap (including the instructions on setting new groups from here https://askubuntu.com/questions/907110/docker-snap-cannot-connect-to-the-docker-daemon-is-the-docker-daemon-running-o. I've also done the installation using a standard install of Docker https://docs.docker.com/install/linux/docker-ce/ubuntu/

Installed docker-compose & set permissions.
Cloned the github repo, tried various methods. Using 'sudo su' and just 'sudo', into /root/loomio-deploy and into /home/user/loomio-deploy

Skipped swap space (server has 16GB), and I get error using the script anyway;
dd: failed to open '/swapfile': Text file busy
mkswap: error: /swapfile is mounted; will not make swapspace
swapon: /swapfile: swapon failed: Device or resource busy

Set up env with no errors, configured SMTP
Initialised the database: 'docker-compose run app rake db:setup'. Some errors reported "PG::ConnectionBad: FATAL: database "loomio_production" does not exist"
Setup crontab no problems.
Started services: 'docker-compose up -d'.
When I try connect to the webservice on the host using localhost or using fqdn set up in /etc/hosts I get "500 Internal Server Error".
Obvious errors in docker-compose logs -d;
loomio-db | FATAL: database "loomio_production" does not exist
loomio-worker | rake aborted!
loomio-worker | ActiveRecord::NoDatabaseError: FATAL: database "loomio_production" does not exist

Any ideas what is causing the database to report missing?
Kind regards,
Stuart

Robert Guthrie

Hi @stuartnorth - try docker-compose run app rake db:create or if that fails then I'd be keen to know about it.

Something like docker exec -ti loomio-db su - postgres -c 'createdb loomio_production' might work, but I worry it may have a permission error.

Let me know.

Stuart North

Hi @robertguthrie I have to run docker compose as sudo. I get a lot of output from 'sudo docker-compose run app rake db:create'
https://pastebin.com/8v9MvhaK
And I'm still getting the same errors in the logs;
loomio-db | FATAL: database "loomio_production" does not exist
loomio-app | rake aborted!
loomio-app | ActiveRecord::NoDatabaseError: FATAL: database "loomio_production" does not exist

I get no errors from running the command "docker exec -ti loomio-db su - postgres -c 'createdb loomio_production'"
but I'm getting tons of new errors in the logs now https://pastebin.com/TvZkc6vi

loomio-worker | Warning: method update already defined
loomio-worker | [Worker(host:d0e053ee4ed8 pid:7)] Starting job worker
loomio-worker | 2019-02-27T20:00:34+0000: [Worker(host:d0e053ee4ed8 pid:7)] Starting job worker
loomio-db | ERROR: relation "delayed_jobs" does not exist at character 566
loomio-db | STATEMENT: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
loomio-db | pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
loomio-db | c.collname, col_description(a.attrelid, a.attnum) AS comment
loomio-db | FROM pg_attribute a
loomio-db | LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
loomio-db | LEFT JOIN pg_type t ON a.atttypid = t.oid
loomio-db | LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
loomio-db | WHERE a.attrelid = '"delayed_jobs"'::regclass
loomio-db | AND a.attnum > 0 AND NOT a.attisdropped
loomio-db | ORDER BY a.attnum
loomio-db |

loomio-worker | [Worker(host:d0e053ee4ed8 pid:7)] Error while reserving job: PG::UndefinedTable: ERROR: relation "delayed_jobs" does not exist
loomio-worker | LINE 8: WHERE a.attrelid = '"delayed_jobs"'::regclass
loomio-worker | ^
loomio-worker | : SELECT a.attname, format_type(a.atttypid, a.atttypmod),
loomio-worker | pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
loomio-worker | c.collname, col_description(a.attrelid, a.attnum) AS comment
loomio-worker | FROM pg_attribute a
loomio-worker | LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
loomio-worker | LEFT JOIN pg_type t ON a.atttypid = t.oid
loomio-worker | LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation
loomio-worker | WHERE a.attrelid = '"delayed_jobs"'::regclass
loomio-worker | AND a.attnum > 0 AND NOT a.attisdropped
loomio-worker | ORDER BY a.attnum
loomio-worker | 2019-02-27T20:00:34+0000: [Worker(host:d0e053ee4ed8 pid:7)] Error while reserving job: PG::UndefinedTable: ERROR: relation "delayed_jobs" does not exist
etc

Robert Guthrie

no errors on createdb means you created the database. Re run the db:setup command to fix those relation missing errors.

Robert Guthrie

If dashboard page is blank please open javascript console and read any browser errors

Naomi

Hi, I'm facing this same problem. Whether I do:

docker-compose run app rake db:create

or

docker-compose run app rake db:setup

The result is the same for each:

ActiveRecord::NoDatabaseError: FATAL: database "loomio_production" does not exist

Robert Guthrie

try

docker-compose run app createdb loomio_production
docker-compose run app rake db:setup

If that does not work you'll need to sudo to postgres user to createdb.

Let me know if it works and I'll update the docs either way.

Naomi

Thankyou @robertguthrie but I'm not having much luck. I am new to Docker, so perhaps it's something trivial.

root@vultr:~/loomio-deploy# docker-compose run app createdb loomio_production
Starting loomio-db    ... done
Starting loomio-redis ... done
Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"createdb\": executable file not found in $PATH": unknown

Naomi

Is this what you meant by "su to postgres and createdb"? Because that also has not helped...

postgres@vultr:~/loomio$ createdb loomio_production
postgres@vultr:~/loomio$ exit
exit
root@vultr:~/loomio-deploy# docker-compose run app rake db:setup
Starting loomio-db ... done
Starting loomio-redis ... done
rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  database "loomio_production" does not exist

Naomi

For completeness:

root@vultr:~/loomio-deploy# docker-compose run app db:create
Starting loomio-db ... done
Starting loomio-redis ... done
Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"db:create\": executable file not found in $PATH": unknown

Naomi

BTW this is a different server than the original one I tried it on. It's a fresh VPS with Ubuntu 18.10.

Naomi

A friend pointed out that instead of run app db:create it should be run app rake db:create. I tried that, and got the "database does not exist" message as usual...

Naomi

SUCCESS!! Another friend advised that by "su to postgres" you meant inside the docker thingy rather than in the OS, and that I should run:

docker exec -ti loomio-db su - postgres -c 'createdb loomio_production'

which I did and it worked, i.e. I did the rake db:setup after that and I could see it creating tables etc. On to the next obstacle now!

Robert Guthrie

OH WOW!! GREAT WORK. I'll update the docs.

Robert Guthrie

Sorry I wasn't able to offer more support during this time. I'm so pleased you've cracked it though. Well done.