Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Plugin::Session lazy start

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


des at des

May 23, 2012, 1:58 AM

Post #1 of 9 (675 views)
Permalink
Plugin::Session lazy start

I have an application that uses sessions with a FastMmap store. This
application also includes a custom script (using Catalyst::ScriptRole)
used to perform certain administrative tasks from the command line.

The problem is that Catalyst tries to unlink and recreate the session
cache every time it starts (somewhere in the bowels of MyApp->setup(), I
imagine). This is obviously a bad idea if the application is running,
but it is a problem even if the application isn't running if the session
cache is owned by a different user (e.g. www) than the one that runs the
script (e.g. des).

Is there a way to have C::Plugin::Session (or C::P::S::Store::FastMmap)
initialize the cache on first use instead of at startup?

As an alternate solution, is there a way to have it use a different file
name every time it starts?

DES
--
Dag-Erling Smørgrav - des [at] des

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


billcrawford1970 at gmail

May 23, 2012, 2:43 AM

Post #2 of 9 (640 views)
Permalink
Re: Plugin::Session lazy start [In reply to]

On 23 May 2012 09:58, Dag-Erling Smørgrav <des [at] des> wrote:

> Is there a way to have C::Plugin::Session (or C::P::S::Store::FastMmap)
> initialize the cache on first use instead of at startup?

{ ..., unlink_on_exit => 0 } in your config.

> As an alternate solution, is there a way to have it use a different file
> name every time it starts?

Personally I go with having a relative path in the myapp_local.conf
that puts them all in a tmp/ subdirectory of where I'm running the
server, then an absolute path in myapp.conf for the real thing.

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


des at des

May 23, 2012, 5:12 AM

Post #3 of 9 (638 views)
Permalink
Re: Plugin::Session lazy start [In reply to]

Will Crawford <billcrawford1970 [at] gmail> writes:
> Dag-Erling Smørgrav <des [at] des> writes:
> > Is there a way to have C::Plugin::Session (or C::P::S::Store::FastMmap)
> > initialize the cache on first use instead of at startup?
> { ..., unlink_on_exit => 0 } in your config.

"delete the cache when you're done" is very different from "don't create
the cache until you actually need it".

> > As an alternate solution, is there a way to have it use a different file
> > name every time it starts?
> Personally I go with having a relative path in the myapp_local.conf
> that puts them all in a tmp/ subdirectory of where I'm running the
> server, then an absolute path in myapp.conf for the real thing.

The script runs with the exact same configuration as the application,
including myapp_local.conf. That's the whole point of using a Catalyst
script instead of a standalone program.

DES
--
Dag-Erling Smørgrav - des [at] des

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


apv at sedition

May 23, 2012, 6:54 AM

Post #4 of 9 (640 views)
Permalink
Re: Plugin::Session lazy start [In reply to]

On Wed, May 23, 2012 at 1:58 AM, Dag-Erling Smørgrav <des [at] des> wrote:
> As an alternate solution, is there a way to have it use a different file
> name every time it starts?

Here's a snippet to do that:

conf.yml
--
Plugin::Session:
storage: /tmp/some-prefix-__UID__.session

MyApp.pm
--
"Plugin::ConfigLoader" => {
substitutions => {
UID => sub { $< },
},
},

https://metacpan.org/module/Catalyst::Plugin::ConfigLoader

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


des at des

May 23, 2012, 7:35 AM

Post #5 of 9 (638 views)
Permalink
Re: Plugin::Session lazy start [In reply to]

Ashley Pond V <apv [at] sedition> writes:
> Dag-Erling Smørgrav <des [at] des> writes:
> > As an alternate solution, is there a way to have it use a different file
> > name every time it starts?
> Here's a snippet to do that: [...]

Thanks, that's a neat workaround (combined with unlink_on_exit).

DES
--
Dag-Erling Smørgrav - des [at] des

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


alexander.hartmaier at t-systems

May 23, 2012, 7:42 AM

Post #6 of 9 (637 views)
Permalink
Re: Plugin::Session lazy start [In reply to]

Because I've just read perlvar: $REAL_USER_ID or $UID instead of $<.

- Alex


Am 2012-05-23 15:54, schrieb Ashley Pond V:
> On Wed, May 23, 2012 at 1:58 AM, Dag-Erling Smørgrav <des [at] des> wrote:
>> As an alternate solution, is there a way to have it use a different file
>> name every time it starts?
> Here's a snippet to do that:
>
> conf.yml
> --
> Plugin::Session:
> storage: /tmp/some-prefix-__UID__.session
>
> MyApp.pm
> --
> "Plugin::ConfigLoader" => {
> substitutions => {
> UID => sub { $< },
> },
> },
>
> https://metacpan.org/module/Catalyst::Plugin::ConfigLoader
>
> _______________________________________________
> List: Catalyst [at] lists
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
> Dev site: http://dev.catalyst.perl.org/


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


des at des

May 23, 2012, 7:51 AM

Post #7 of 9 (640 views)
Permalink
Re: Plugin::Session lazy start [In reply to]

Dag-Erling Smørgrav <des [at] des> writes:
> Thanks, that's a neat workaround (combined with unlink_on_exit).

I was wrong about that last bit - unlink_on_exit automatically defaults
to a sane value (unlink the file if you created it, leave it alone if it
already existed). If anything, you'd want to set it to 0 so sessions
are persistent across server restarts.

BTW, this is not a perfect solution, since all processes owned by the
same user will now share a session cache. However, this should rarely
(if ever) be a problem.

DES
--
Dag-Erling Smørgrav - des [at] des

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


des at des

May 23, 2012, 7:54 AM

Post #8 of 9 (637 views)
Permalink
Re: Plugin::Session lazy start [In reply to]

Alexander Hartmaier <alexander.hartmaier [at] t-systems> writes:
> Because I've just read perlvar: $REAL_USER_ID or $UID instead of $<.

assuming "use English"

DES
--
Dag-Erling Smørgrav - des [at] des

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/


apv at sedition

May 23, 2012, 7:58 AM

Post #9 of 9 (637 views)
Permalink
Re: Plugin::Session lazy start [In reply to]

On Wed, May 23, 2012 at 7:42 AM, Alexander Hartmaier
<alexander.hartmaier [at] t-systems> wrote:
> Because I've just read perlvar: $REAL_USER_ID or $UID instead of $<.

I think this is generally excellent advice but I want to argue against
it in this case.

UID => sub { $< } is sufficiently semantic *and* edifying. E.g., Oh!
That's the special var for UID. It finally makes sense.

use English;
UID => sub { $UID } is redundant to point of being annoying and even
distracting (to me).

_______________________________________________
List: Catalyst [at] lists
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst [at] lists/
Dev site: http://dev.catalyst.perl.org/

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.