Explicitly defining location of config.yml (current hitch on path to running Dancer as a service)
Hi, I have a small app running on a server for restricted use, and want to have it as a standard service. Unfortunately DaemonTools is not available as an official rpm for Red Hat, so I can't use it. I installed Ubic and tried with that, but gave it up when I could not find a way to get it to work under HTTPS. As a last resort wrote a loader script which uses Systemd::Daemon and runs as a simple supervisor service which starts/reloads/stops the Dancer app. So far so good, but the app once started does not seem to pick up config.yml, and the database connection information in there - so the app is running but cant do anything. The problem seems to be that when started in this way it uses / as the working directory, and there is no way to tell plackup to look elsewhere for the config. I tried this and that, but failing so far. Happy to change the approach, but really hoping to be able to keep all dependencies of the finished product within perl and my perlbrew folder. Cheers, Nik
Hi, A quick update, to make sure no one wastes time answering my initial question... Location of the config file is not the issue - within my main app file (where the routes are defined), the config hash contains all of the configuration, and the config.yml location. In a plugin I wrote however a part of the configuration is missing - not even all of it. All that's left is for me to figure out why :) Nik On 15/09/16 13:55, Nik Mitev wrote:
Hi,
I have a small app running on a server for restricted use, and want to have it as a standard service. Unfortunately DaemonTools is not available as an official rpm for Red Hat, so I can't use it. I installed Ubic and tried with that, but gave it up when I could not find a way to get it to work under HTTPS.
As a last resort wrote a loader script which uses Systemd::Daemon and runs as a simple supervisor service which starts/reloads/stops the Dancer app. So far so good, but the app once started does not seem to pick up config.yml, and the database connection information in there - so the app is running but cant do anything. The problem seems to be that when started in this way it uses / as the working directory, and there is no way to tell plackup to look elsewhere for the config.
I tried this and that, but failing so far.
Happy to change the approach, but really hoping to be able to keep all dependencies of the finished product within perl and my perlbrew folder.
Cheers, Nik
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
On 09/16/2016 11:27 AM, Nik Mitev wrote:
Hi,
A quick update, to make sure no one wastes time answering my initial question... Location of the config file is not the issue - within my main app file (where the routes are defined), the config hash contains all of the configuration, and the config.yml location. In a plugin I wrote however a part of the configuration is missing - not even all of it. All that's left is for me to figure out why :)
Nik
Hello Nik, maybe you can share the code of the plugin - so we might spot the problem in there. Regards Racke
On 15/09/16 13:55, Nik Mitev wrote:
Hi,
I have a small app running on a server for restricted use, and want to have it as a standard service. Unfortunately DaemonTools is not available as an official rpm for Red Hat, so I can't use it. I installed Ubic and tried with that, but gave it up when I could not find a way to get it to work under HTTPS.
As a last resort wrote a loader script which uses Systemd::Daemon and runs as a simple supervisor service which starts/reloads/stops the Dancer app. So far so good, but the app once started does not seem to pick up config.yml, and the database connection information in there - so the app is running but cant do anything. The problem seems to be that when started in this way it uses / as the working directory, and there is no way to tell plackup to look elsewhere for the config.
I tried this and that, but failing so far.
Happy to change the approach, but really hoping to be able to keep all dependencies of the finished product within perl and my perlbrew folder.
Cheers, Nik
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- Ecommerce and Linux consulting + Perl and web application programming. Debian and Sympa administration.
On 16/09/16 10:31, Stefan Hornburg (Racke) wrote:
On 09/16/2016 11:27 AM, Nik Mitev wrote:
Hi,
A quick update, to make sure no one wastes time answering my initial question... Location of the config file is not the issue - within my main app file (where the routes are defined), the config hash contains all of the configuration, and the config.yml location. In a plugin I wrote however a part of the configuration is missing - not even all of it. All that's left is for me to figure out why :)
Nik Hello Nik,
maybe you can share the code of the plugin - so we might spot the problem in there.
I narrowed it down further (I think). Here is the beginning of the code: package Dancer2::Plugin::ESS2::Auth; use strict; ... snip use statements ... use Dancer2::Plugin; register ess2_check_user => sub { my $dsl = shift; my %db_info = %{$dsl->config->{'db_info'}}; ... snip ... }; .... more register statements ... register_plugin; 1; If I edit the above to my $dsl = shift; + print Dumper $dsl; I get all the information I would expect to be under the config key, e.g. 'config' => { 'plugins' => { 'ESS2::Auth' => { all the data from the plugin config }, }, 'db_info' => { the database connection settings }, etc ... }, Dumping $dsl->config however returns only the contents of $dsl->config->{'plugins'}->{'ESS2::Auth'} when I would expect it to return the 'plugins' key and the 'db_info' key and the rest of it. Thanks for any and all input :) Nik
On 09/16/2016 11:56 AM, Nik Mitev wrote:
On 16/09/16 10:31, Stefan Hornburg (Racke) wrote:
On 09/16/2016 11:27 AM, Nik Mitev wrote:
Hi,
A quick update, to make sure no one wastes time answering my initial question... Location of the config file is not the issue - within my main app file (where the routes are defined), the config hash contains all of the configuration, and the config.yml location. In a plugin I wrote however a part of the configuration is missing - not even all of it. All that's left is for me to figure out why :)
Nik Hello Nik,
maybe you can share the code of the plugin - so we might spot the problem in there.
I narrowed it down further (I think). Here is the beginning of the code:
package Dancer2::Plugin::ESS2::Auth; use strict; ... snip use statements ... use Dancer2::Plugin;
register ess2_check_user => sub { my $dsl = shift; my %db_info = %{$dsl->config->{'db_info'}};
... snip ... };
.... more register statements ... register_plugin; 1;
If I edit the above to
my $dsl = shift; + print Dumper $dsl;
I get all the information I would expect to be under the config key, e.g. 'config' => { 'plugins' => { 'ESS2::Auth' => {
all the data from the plugin config }, }, 'db_info' => { the database connection settings }, etc ... },
Dumping $dsl->config however returns only the contents of $dsl->config->{'plugins'}->{'ESS2::Auth'} when I would expect it to return the 'plugins' key and the 'db_info' key and the rest of it.
Thanks for any and all input :)
You need to ask for the plugin config, e.g. with plugin_setting keyword. A nicer way is to use an accessor in your plugin: https://metacpan.org/pod/Dancer2::Plugin#Getting-default-values-from-config-... Regards Racke -- Ecommerce and Linux consulting + Perl and web application programming. Debian and Sympa administration.
On 16/09/16 11:04, Stefan Hornburg (Racke) wrote:
You need to ask for the plugin config, e.g. with plugin_setting keyword. That is indeed a shorter way of getting the settings for the plugin, which I will use. I was after the db_info key however, and was getting the plugin settings instead. This gets resolved if I ask for $dsl->app->config->{'db_info'} instead of $dsl->config->{'db_info'}
Still not sure why $dsl->config->{'db_info'} returns the data for $dsl->config->{'plugins'}->{'ESS2::Auth'}
A nicer way is to use an accessor in your plugin:
https://metacpan.org/pod/Dancer2::Plugin#Getting-default-values-from-config-... I don't consider myself a perl pro and frankly don't quite understand the object-oriented side of it... still hoping I will not need to dig into it :) Is it unreasonable to think I can maintain a Dancer2 app well without learning object oriented perl?
Nik
On 09/16/2016 12:21 PM, Nik Mitev wrote:
On 16/09/16 11:04, Stefan Hornburg (Racke) wrote:
You need to ask for the plugin config, e.g. with plugin_setting keyword. That is indeed a shorter way of getting the settings for the plugin, which I will use. I was after the db_info key however, and was getting the plugin settings instead. This gets resolved if I ask for $dsl->app->config->{'db_info'} instead of $dsl->config->{'db_info'}
Still not sure why $dsl->config->{'db_info'} returns the data for $dsl->config->{'plugins'}->{'ESS2::Auth'}
Because the first parameter is the $plugin object and not a DSL object :-).
A nicer way is to use an accessor in your plugin:
https://metacpan.org/pod/Dancer2::Plugin#Getting-default-values-from-config-... I don't consider myself a perl pro and frankly don't quite understand the object-oriented side of it... still hoping I will not need to dig into it :) Is it unreasonable to think I can maintain a Dancer2 app well without learning object oriented perl?
Yes, you can up to a point but it isn't as beautiful. Regards Racke -- Ecommerce and Linux consulting + Perl and web application programming. Debian and Sympa administration.
On 16/09/16 11:27, Stefan Hornburg (Racke) wrote:
I was after the db_info key however, and was getting the plugin settings instead. This gets resolved if I ask for $dsl->app->config->{'db_info'} instead of $dsl->config->{'db_info'}
Still not sure why $dsl->config->{'db_info'} returns the data for $dsl->config->{'plugins'}->{'ESS2::Auth'} Because the first parameter is the $plugin object and not a DSL object :-). I am not sure I understand, sorry :) So effectively $dsl->config when used within a plugin has the same effect as $dsl->plugin_setting?
On 09/16/2016 12:38 PM, Nik Mitev wrote:
On 16/09/16 11:27, Stefan Hornburg (Racke) wrote:
I was after the db_info key however, and was getting the plugin settings instead. This gets resolved if I ask for $dsl->app->config->{'db_info'} instead of $dsl->config->{'db_info'}
Still not sure why $dsl->config->{'db_info'} returns the data for $dsl->config->{'plugins'}->{'ESS2::Auth'} Because the first parameter is the $plugin object and not a DSL object :-). I am not sure I understand, sorry :) So effectively $dsl->config when used within a plugin has the same effect as $dsl->plugin_setting?
register foobar => sub { my ($plugin, ...) = @_; ... } The first parameter here is the Dancer2::Plugin object which has a config method, and logically provides the plugin configuration. So if you are using $dsl variable name, that is confusing and not accurate. $plugin->app gives you App object, which also has a config method. This logically provides the app configuration. Regards Racke -- Ecommerce and Linux consulting + Perl and web application programming. Debian and Sympa administration.
participants (2)
-
Nik Mitev -
Stefan Hornburg (Racke)