[Catalyst] Plugin::Session lazy start

2012-05-23 Thread Dag-Erling Smørgrav
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 - d...@des.no

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


Re: [Catalyst] Plugin::Session lazy start

2012-05-23 Thread Dag-Erling Smørgrav
Will Crawford billcrawford1...@gmail.com writes:
 Dag-Erling Smørgrav d...@des.no 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 - d...@des.no

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


Re: [Catalyst] Plugin::Session lazy start

2012-05-23 Thread Ashley Pond V
On Wed, May 23, 2012 at 1:58 AM, Dag-Erling Smørgrav d...@des.no 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@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Plugin::Session lazy start

2012-05-23 Thread Alexander Hartmaier
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 d...@des.no 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@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 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@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Plugin::Session lazy start

2012-05-23 Thread Dag-Erling Smørgrav
Dag-Erling Smørgrav d...@des.no 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 - d...@des.no

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


Re: [Catalyst] Plugin::Session lazy start

2012-05-23 Thread Dag-Erling Smørgrav
Alexander Hartmaier alexander.hartma...@t-systems.at writes:
 Because I've just read perlvar: $REAL_USER_ID or $UID instead of $.

assuming use English

DES
-- 
Dag-Erling Smørgrav - d...@des.no

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


Re: [Catalyst] Plugin::Session lazy start

2012-05-23 Thread Ashley Pond V
On Wed, May 23, 2012 at 7:42 AM, Alexander Hartmaier
alexander.hartma...@t-systems.at 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@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/