openvehicles / Open-Vehicle-Server

Repository for Open Vehicles server code
28 stars 25 forks source link

DBD::MariaDB::db STORE failed: Unknown attribute mysql_auto_reconnect #29

Open enoch85 opened 3 weeks ago

enoch85 commented 3 weeks ago

Running MariaDB instead of MySQL (on Alpine) results in this error when the server starts.

DBD::MariaDB::db STORE failed: Unknown attribute mysql_auto_reconnect at plugins/system/OVMS/Server/DbDBI.pm line 88.

The line in question is this one: https://github.com/openvehicles/Open-Vehicle-Server/blob/aecc751be4d26e71a23b1767f36d33555f96c9f6/v3/server/plugins/system/OVMS/Server/DbDBI.pm#L88

Maybe it would be possible to add an if statement, for running both MariaDB and MySQL? In MariaDB there is this: https://mariadb.com/kb/en/mariadb_reconnect/

enoch85 commented 3 weeks ago

Hmm, there doesn't seem to be a similar option in MariaDB, only in MySQL: https://metacpan.org/pod/DBD::mysql#mysql_auto_reconnect

markwj commented 3 weeks ago

Is there a reason you can’t just use the MySQL client to talk to mariadb? That is what I do. The two are interchangeable (mostly).

enoch85 commented 3 weeks ago

It seems like Alpine (3.21) forces MariaDB even though I specifically enter mysql - even search paths and everything.

My end goal here was (is) to write a full documentation on how to install the server in a small, lightweight and hardened way. Alpine is known for that.

I got everything running as I want now with a few modifications to the code base, and reconnect doesn't seem to exist I'm afraid.

I can read code but never worked with pm before.

markwj commented 3 weeks ago

The server is written in Perl code.

How are you installing the Perl prerequisite packages (like the dbd client, anyevent, etc)? From CPAN or from some package manager.

For the dbd, there is a difference between a) the client library, b) the Perl wrapper round the client library, and c) the server.

markwj commented 3 weeks ago

Maybe this is relevant:

https://github.com/perl5-dbi/DBD-mysql/issues/218

But it seems to indicate this was fixed back in 2018. What version of the Perl client library are you using?

enoch85 commented 3 weeks ago

I'm happy to give you SSH access to the server so that you can inspect yourself. It's just in a testing phase as of now just to get the documentation up to date (which I plan to commit once I'm satisfied and issues like these are sorted). Once testing is done, I will trash it and start over from the documentation I wrote, just to double check all steps are correct.

Please send your public SSH-key and IP adress to mailto at danielhansson.nu if you want. If not I will have to check when I get home later tonight.

enoch85 commented 3 weeks ago

No email yet, so I figure you want me to write here instead.

ovms:~# perl --version

This is perl 5, version 40, subversion 1 (v5.40.1) built for x86_64-linux-thread-multi

As for CPAN, I use this https://pkgs.alpinelinux.org/package/edge/community/x86/perl-app-cpanminus and install with:

cpanm Config::IniFiles
cpanm Digest::MD5
cpanm Digest::HMAC
cpanm Crypt::RC4::XS
cpanm MIME::Base64
cpanm DBI
cpanm DBD::MariaDB --force
cpanm EV
cpanm AnyEvent
cpanm AnyEvent::HTTP
cpanm AnyEvent::HTTPD
cpanm HTTP::Parser::XS
cpanm Data::UUID
cpanm Email::MIME
cpanm Email::Sender::Simple
cpanm Net::SSLeay --force
cpanm JSON::XS
cpanm Protocol::WebSocket
cpanm Time::Piece
cpanm EV

...and this is the output for version

ovms:~# cpanm --version
cpanm (App::cpanminus) version 1.7048 (/usr/bin/cpanm)
perl version 5.040001 (/usr/bin/perl)

  %Config:
    archname=x86_64-linux-thread-multi
    installsitelib=/usr/local/share/perl5/site_perl
    installsitebin=/usr/local/bin
    installman1dir=/usr/share/man/man1
    installman3dir=/usr/share/man/man3
    sitearchexp=/usr/local/lib/perl5/site_perl
    sitelibexp=/usr/local/share/perl5/site_perl
    vendorarch=/usr/lib/perl5/vendor_perl
    vendorlibexp=/usr/share/perl5/vendor_perl
    archlibexp=/usr/lib/perl5/core_perl
    privlibexp=/usr/share/perl5/core_perl
  %ENV:
  @INC:
    FatPacked::139743882301496=HASH(0x7f18a876d038)
    /usr/local/lib/perl5/site_perl
    /usr/local/share/perl5/site_perl
    /usr/lib/perl5/vendor_perl
    /usr/share/perl5/vendor_perl
    /usr/lib/perl5/core_perl
    /usr/share/perl5/core_perl

https://github.com/perl5-dbi/DBD-mysql/issues/218

Yeah I read that too, but it got late yesterday, so I never got around investigating too much.

I'm pretty sure changing to a "wider" distro like Ubuntu or Debian would solve the issues here, but why choose the easy path? :)

enoch85 commented 3 weeks ago

Well, I have it up and running on a non-root user on Alpine now at least.

2025-01-26 02:06:44.564929 +0100 info  OVMS::Server::ApiHttp: - - - register callback url '/mqapi/auth' for OVMS::Server::ApiHttpMqapi
2025-01-26 02:06:44.565022 +0100 info  OVMS::Server::ApiHttp: - - - register callback url '/mqapi/superuser' for OVMS::Server::ApiHttpMqapi
2025-01-26 02:06:44.565084 +0100 info  OVMS::Server::ApiHttp: - - - register callback url '/mqapi/acl' for OVMS::Server::ApiHttpMqapi
2025-01-26 02:06:44.565200 +0100 info  OVMS::Server::ApiHttp: - - - starting HTTP server listener on port tcp/6868
2025-01-26 02:06:44.566190 +0100 info  OVMS::Server::ApiHttp: - - - starting HTTPS server listener on port tcp/6869
2025-01-26 02:06:44.568146 +0100 info  OVMS::Server::ApiV2: - - - starting V2 server listener on port tcp/6867
2025-01-26 02:06:44.568373 +0100 info  OVMS::Server::ApiV2: - - - starting V2 SSL server listener on port tcp/6870
2025-01-26 02:07:43.929749 +0100 info  OVMS::Server::AuthDrupal: - - - Periodic Drupal maintenance
DBD::MariaDB::db do failed: Table 'openvehicles.users' doesn't exist at plugins/system/OVMS/Server/DbDBI.pm line 195.
DBD::MariaDB::db do failed: Table 'openvehicles.users' doesn't exist at plugins/system/OVMS/Server/DbDBI.pm line 195.
DBD::MariaDB::db do failed: Table 'openvehicles.users' doesn't exist at plugins/system/OVMS/Server/DbDBI.pm line 195.
2025-01-26 02:08:08.497066 +0100 info  OVMS::Server::ApiHttp: http - - 10.4.99.2:48938 connect(ssl)
2025-01-26 02:08:08.519575 +0100 info  OVMS::Server::ApiHttp: http - - 10.1.1.2:48938 quota 120
2025-01-26 02:08:08.519829 +0100 info  OVMS::Server::ApiHttp: http - - 10.1.1.2:48938 - GET /
2025-01-26 02:08:08.520854 +0100 info  OVMS::Server::ApiHttp: http - - 10.1.1.2:48938 disconnect(ssl)
2025-01-26 02:08:17.416286 +0100 info  OVMS::Server::ApiHttp: http - - 10.1.1.2:36458 connect(ssl)
2025-01-26 02:08:17.449671 +0100 info  OVMS::Server::ApiHttp: http - - 10.1.1.2:36458 quota 119
2025-01-26 02:08:17.452574 +0100 info  OVMS::Server::ApiHttp: http - - 10.1.1.2:36458 disconnect(ssl)
2025-01-26 02:08:42.632702 +0100 info  OVMS::Server::ApiHttp: http - - 10.1.1.2:55752 connect(ssl)
2025-01-26 02:08:42.641508 +0100 info  OVMS::Server::ApiHttp: http - - 10.1.1.2:55752 quota 118
2025-01-26 02:08:42.642420 +0100 info  OVMS::Server::ApiHttp: http - - 10.1.1.2:55752 disconnect(ssl)
2025-01-26 02:08:43.920182 +0100 info  OVMS::Server::AuthDrupal: - - - Periodic Drupal maintenance

Now I need to figure out on how to proceed from here.

  1. Make it a service
  2. Connect my actual OVMS box (not arrived yet)
  3. Perfect my setup
  4. Post a PR in /docs with what I ended up with (if you are welcoming?)
  5. Get my head around Drupal and what sense that makes
markwj commented 2 weeks ago

I think your problem is here:

cpanm DBD::MariaDB --force

As per: https://docs.openvehicles.com/en/latest/server/installation.html

we are coded for DBD::mysql. So you want:

cpanm DBD::mysql

That should hopefully resolve your 'Unknown attribute mysql_auto_reconnect' issues.

Regarding your proceeding, happy to work with you on PRs to improve the documentation on this. One problem though is with so many distributions, it is hard to be too specific.

P.S. I'd forget about Drupal if I were you. Unless you want a registration website, etc. What would be more useful is a small auth plugin to read registered owners, users, vehicles, etc from a config file (Config::IniFiles format as per the rest of the system). That could then be used by those just wanting to run their own server just for their own cars.

P.P.S. But bear in mind that this whole raw protocol / MP / v2 protocol thing is hopefully not too long for this world. MQTT make s much more sense in the modern world.

enoch85 commented 2 weeks ago

cpanm DBD::mysql

Yes, I just copy pasted from the current documentation, and used mysql at first, but that resulted in other errors since Alpine forces MariaDB. Even running mysql something something creates a warning that mariadb should be used. Anyway, It's working without auto_reconnect afaik. Haven't tested in production yet though. A dream come through would be to run PostgreSQL. Just saying. :)

it is hard to be too specific.

Sure, I get that. But maybe we could aim for at lest one copy paste documentation? :)

v2 protocol thing is hopefully not too long for this world

Yup, I realized that. That's why I invested like 20 hours in finding a good MQTT Broker last day. I plan on using the "dexter server", but will still do a write up on what you need to get it working. Maybe some graphical schematic on how everything works.

Regarding this issue, feel free to close it.