Bug 26625 - Add ability to configure mojolicious applications
Summary: Add ability to configure mojolicious applications
Status: Patch doesn't apply
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Julian Maurice
QA Contact: Testopia
URL:
Keywords:
Depends on: 20582
Blocks:
  Show dependency treegraph
 
Reported: 2020-10-07 08:27 UTC by Julian Maurice
Modified: 2024-02-09 17:03 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 26625: Add a mojolicious section in $KOHA_CONF (2.59 KB, patch)
2020-10-07 08:28 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 26625: (alternative) Use Config plugin in Mojolicious apps (2.22 KB, patch)
2020-10-08 06:44 UTC, Julian Maurice
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Julian Maurice 2020-10-07 08:27:32 UTC
This will allow to configure hypnotoad (and probably other things too in the future)
Comment 1 Julian Maurice 2020-10-07 08:28:59 UTC
Created attachment 111323 [details] [review]
Bug 26625: Add a mojolicious section in $KOHA_CONF

This allows to configure hypnotoad (listen address, number of workers,
...)

https://metacpan.org/pod/Mojo::Server::Hypnotoad#SETTINGS
Comment 2 Julian Maurice 2020-10-07 08:35:25 UTC
Test plan:
1. Do not apply the patch yet
2. Run `hypnotoad bin/opac` and see that it listens on "http://*:8080" (its default value)
3. Run `hypnotoad -s bin/opac` to stop it
4. Repeat steps 2-3 for intranet
5. Apply the patch
6. Copy the <mojolicious> section from etc/koha-conf.xml to your $KOHA_CONF
7. Change the value of //mojolicious/opac/config/hypnotoad/listen in your $KOHA_CONF to "http://*:8181"
8. Run `hypnotoad bin/opac` and see that it now listens on port 8181
9. Run `hypnotoad -s bin/opac` to stop it
10. Repeat steps 7-9 for intranet
Comment 3 Julian Maurice 2020-10-07 09:45:24 UTC
As an alternative, we could use the mojolicious Config plugin, but that would require having a separate configuration file for mojo. It might be a good idea, but really I don't know. It's a thing to consider while reviewing this patch.
Comment 4 Julian Maurice 2020-10-08 06:44:26 UTC
Created attachment 111365 [details] [review]
Bug 26625: (alternative) Use Config plugin in Mojolicious apps

This allows to have separate config files for each mojolicious app. They
can also both use the same config file.
The config file is Perl code, so the configuration can be dynamic

See https://docs.mojolicious.org/Mojolicious/Plugin/Config
Comment 5 David Cook 2020-10-09 00:19:11 UTC
(In reply to Julian Maurice from comment #3)
> As an alternative, we could use the mojolicious Config plugin, but that
> would require having a separate configuration file for mojo. It might be a
> good idea, but really I don't know. It's a thing to consider while reviewing
> this patch.

I am fond of Config plugins ( like Catalyst::Plugin::ConfigLoader ), although with Catalyst I had the issue where I wanted to access the config in the Catalyst config from outside Catalyst for arbitrary non-web config items. Not sure how that works with Mojolicious, but with Catalyst I had to use Config::JFDI.
Comment 6 David Cook 2020-10-09 00:21:54 UTC
But if there is something that is strictly relating to Mojolicious, I think having a separate config file sounds like a good idea.

Considering that koha-conf.xml is actually a corruption of a YAZ configuration file, I think we should really be looking at alternatives to putting more things in koha-conf.xml...
Comment 7 Julian Maurice 2020-10-09 07:34:05 UTC
(In reply to David Cook from comment #5)
> I am fond of Config plugins ( like Catalyst::Plugin::ConfigLoader ),
> although with Catalyst I had the issue where I wanted to access the config
> in the Catalyst config from outside Catalyst for arbitrary non-web config
> items. Not sure how that works with Mojolicious, but with Catalyst I had to
> use Config::JFDI.

The eval command can be used for that: `bin/intranet eval -v 'use JSON; to_json(app->config)`. Not the most efficient way to read a config file, but at least it doesn't depend on config file format.
Comment 8 David Nind 2023-10-22 19:31:05 UTC
I had a go at testing, as this has been sitting in the needs sign off queue for a while. 

FYI: I don't know what a "mojolicious app" is, or what the use case is, and how to use it 8-) (so I am probably not the right person to test it!).

Some notes from testing:

1. Steps 2 and 3: I get these messages:

kohadev-koha@kohadevbox:koha(master)$ hypnotoad bin/opac
Can't create listen socket: Address already in use at /usr/share/perl5/Mojo/IOLoop.pm line 124.

kohadev-koha@kohadevbox:koha(master)$ hypnotoad bin/intranet
Can't create listen socket: Address already in use at /usr/share/perl5/Mojo/IOLoop.pm line 124.


2. As expected (since it's been here a while), the first patch doesn't apply - the alternative patch still applies though:

kohadev-koha@kohadevbox:koha(bz26625)$ git bz apply 26625

Bug 26625 - Add ability to configure mojolicious applications

111323 - Bug 26625: Add a mojolicious section in $KOHA_CONF
111365 - Bug 26625: (alternative) Use Config plugin in Mojolicious apps

Apply? [(y)es, (n)o, (i)nteractive] i
Applying: Bug 26625: Add a mojolicious section in $KOHA_CONF
Using index info to reconstruct a base tree...
M	etc/koha-conf.xml
Falling back to patching base and 3-way merge...
Auto-merging etc/koha-conf.xml
CONFLICT (content): Merge conflict in etc/koha-conf.xml
error: Failed to merge in the changes.
Patch failed at 0001 Bug 26625: Add a mojolicious section in $KOHA_CONF