souramoo / commentoplusplus

Commento with out of the box patches and updates to add useful features and fixes. Also with one-click deploy to Heroku so you can get up and running fast.
MIT License
391 stars 63 forks source link

Comentoplusplus cannot initialize database properly #18

Closed FrancisTurner closed 3 years ago

FrancisTurner commented 3 years ago

I have been building ARM versions of commento (plus plus) to run on my Raspberry Pi.

I built the original commento by doing git clone, make prod etc. and it works fine. I built commentoplusplus the same way and I can run it just fine replacing the original commento in a place where the original has set up the database and registered the first user If I use commentoplusplus to setup the database and register the first user it fails.

By doing repeated dropdb/createdb I have been able to reproduce this at will.

This is commento working

/var/log/syslog:Mar  2 11:27:26 micronetia commento[16699]: 2021/03/02 11:27:26 [INFO] version.go:13 versionPrint(): starting Commento v1.8.0-rc1-8-g84bfd64
/var/log/syslog:Mar  2 11:27:26 micronetia commento[16699]: 2021/03/02 11:27:26 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://commento:redacted@127.0.0.1:5432/commento?sslmode=disable
/var/log/syslog:Mar  2 11:27:26 micronetia commento[16699]: 2021/03/02 11:27:26 [INFO] database_migrate.go:47 migrateFromDir(): 0 migrations already installed, looking for more
/var/log/syslog:Mar  2 11:27:27 micronetia commento[16699]: 2021/03/02 11:27:27 [INFO] database_migrate.go:89 migrateFromDir(): 29 new migrations completed (29 total)
/var/log/syslog:Mar  2 11:27:27 micronetia commento[16699]: 2021/03/02 11:27:27 [WARNING] smtp_configure.go:17 smtpConfigure(): smtp not configured, no emails will be sent
/var/log/syslog:Mar  2 11:27:27 micronetia commento[16699]: 2021/03/02 11:27:27 [INFO] smtp_templates.go:43 smtpTemplatesLoad(): loading templates: [confirm-hex reset-hex domain-export domain-export-error]
/var/log/syslog:Mar  2 11:27:27 micronetia commento[16699]: 2021/03/02 11:27:27 [INFO] sigint.go:22 sigintCleanupSetup(): setting up SIGINT cleanup
/var/log/syslog:Mar  2 11:27:27 micronetia commento[16699]: 2021/03/02 11:27:27 [INFO] router.go:32 routesServe(): starting server on 127.0.0.1:8081

This is commentoplusplus not working

/var/log/syslog:Mar  2 11:31:37 micronetia commento[16755]: 2021/03/02 11:31:37 [INFO] version.go:13 versionPrint(): starting Commento v1.8.4-14-ga020fd6
/var/log/syslog:Mar  2 11:31:37 micronetia commento[16755]: 2021/03/02 11:31:37 [INFO] database_connect.go:20 dbConnect(): opening connection to postgres: postgres://commento:redacted@127.0.0.1:5432/commento?sslmode=disable
/var/log/syslog:Mar  2 11:31:37 micronetia commento[16755]: 2021/03/02 11:31:37 [INFO] database_migrate.go:47 migrateFromDir(): 0 migrations already installed, looking for more
/var/log/syslog:Mar  2 11:31:37 micronetia commento[16755]: 2021/03/02 11:31:37 [ERROR] database_migrate_email_notifications.go:18 migrateEmails(): cannot get comments: pq: relation "commenters" does not exist
/var/log/syslog:Mar  2 11:31:37 micronetia commento[16755]: 2021/03/02 11:31:37 [ERROR] database_migrate.go:78 migrateFromDir(): cannot execute Go migration associated with SQL /home/commento/commento-server/db/20190213033530-email-notifications.sql: Encountered error applying database migration.
/var/log/syslog:Mar  2 11:31:37 micronetia commento[16755]: fatal error: Encountered error applying database migration.
/var/log/syslog:Mar  2 11:31:37 micronetia systemd[1]: commento.service: Main process exited, code=exited, status=1/FAILURE
/var/log/syslog:Mar  2 11:31:37 micronetia systemd[1]: commento.service: Failed with result 'exit-code'.
FrancisTurner commented 3 years ago

Note that if I continually restart commentoplusplus it will eventually run anyway and I can attempt to sign up a user. However that doesn't actually work and gives an error. I can probably provide the additional syslog errors but there doesn't seem to be much point because I'm sure the errors are related to the initial database initialization failing

FrancisTurner commented 3 years ago

And when I try the devel build it works....

souramoo commented 3 years ago

Thanks for the bug report! The errors you're getting appear to be due to the database not being set up by commentoplusplus correctly. The database setup happens by loading in all the migrations in the db/ folder one by one, which creates the appropriate tables, upgrades the database structure from previous commento versions, etc.

From the sound of things, since the make devel build works, it's unlikely to be an issue with the code. What is more likely from the logs is that the folder full of migrations at build/prod/db is incomplete for some reason (filesystem error?) and so the initialisation never quite finishes properly.

Can you please report back the results of ls -la build/prod/db and ls -la build/devel/db?

FrancisTurner commented 3 years ago

prod.txt dev.txt prod.txt is ls -la build/prod/db dev.txt is ls -la build/devel/db

The prod files are all 0 length, which is undoubtedly the problem. I'll try a rebuild and I plan to mix and match binaries and directories today and see the prod binary works with everything else from devel. I'll let you know. The devel binary and scripts etc. seems to be working just fine for me now but I assume it's better to deploy the prod binary in production

souramoo commented 3 years ago

Ah I see the issue, for some reason the file sizes for all of the database schemas are indeed 0 in the build/prod/db folder!

It looks like for some reason the file copy command partially failed? If you copy the schemas over manually it should hopefully fix this issue (or run a make clean && make prod!) Also I think microSD card write failures are quite common in raspberry Pis (I've certainly had a fair few from overuse) so please do check that yours hasn't been worn out!

The devel build process should work just fine but I would highly recommend using the prod build process if you are deploying as it should be getting rid of debug code, run faster and minify the JavaScript :)