RE: Perl can't find my libraries when run via the subversion post-commit script

2010-03-05 Thread Craig Thayer
Thanks Chris!  I wish I would have known about SVN::Notify::Mirror before I 
wrote my Perl script--guess I should spend more time searching CPAN first.  ;)

It appears to have a great deal of capability from what I gleaned from skimming 
the documentation. I may play around with it later when I have some more time, 
but for now I have my post-commit script working for our current needs and I 
need to get back to doing some real work.  %^)

Thanks again for all your help.  I really appreciate it.

Craig

-Original Message-
From: Chris Shelton [mailto:cshel...@shelton-family.net] 
Sent: Friday, March 05, 2010 10:21 AM
To: Craig Thayer
Cc: users@subversion.apache.org
Subject: Re: Perl can't find my libraries when run via the subversion 
post-commit script

Craig,

On Fri, Mar 5, 2010 at 9:52 AM, Craig Thayer ctha...@sensorlogic.com wrote:
 Thanks again David.

 The reason for the post-commit hook is to pull certain files out of 
 Subversion and write them to our server. For example, if 
 tools/perl/trunk/lib/foo.pm is updated we want it to be copied to 
 /usr/lib/perl5/site_perl/foo.pm automatically upon commit.

 I am using the svnlook command in the script now to get the 'changed' and 
 'info' data from the commit operation to determine if any file changed or 
 added is one that we need on our server (i.e., we're attempting to automate 
 our manual process of fetching key Subversion files and psftp'ing them to the 
 server).  The files are a mix of text and binary files.

 I was unaware that svnlook had a 'cat' operation, but I'm concerned that if 
 it fails in any way it will overwrite and trash the target file with its 
 error output the same way that 'svn cat' did.

 However, I will try it since svnlook doesn't need the credentials to extract 
 the file.

If you are able to let the web server user to create working copies,
you may want to consider using the SVN::Notify::Mirror perl module:
http://search.cpan.org/~jpeacock/SVN-Notify-Mirror-0.038/lib/SVN/Notify/Mirror.pm

I've been using this module to automate a svn update on our test web
server, which runs from a set of working copies from our repository.
The SVN::Notify module also supports the creation of very configurable
post-commit email messages.  Once I worked through the syntax of the
config file, this approach has worked well, with only a few rare
hiccups.

chris


Re: Perl can't find my libraries when run via the subversion post-commit script

2010-03-04 Thread David Weintraub
Did you log in as the user that runs the Subversion server (usually
the Apache user apache or wwwrun or some other user depending upon
the installation) and try your script? That way, you can verify that
this is not a permission issue.

I also wonder if you might be causing issues with putting the use
lib inside a BEGIN statement. This isn't necessary with use lib as
the manpage on the pragma states that these are ALMOST equivalent:

use lib /foo/bar;
BEGIN {unshift @INC, /foo/bar;}

The differences are subtle. The use lib won't execute if /foo/bar
doesn't exist. It'l also automatically include in the @INC array
before /foo/bar, the  /foo/$archname/bar, /foo/$version/bar and
/foo/$archname/$version/bar directories (if they exist).

See http://perldoc.perl.org/lib.html.

On Thu, Mar 4, 2010 at 12:20 PM, Craig Thayer ctha...@sensorlogic.com wrote:
 David,

 Thank you for your reply.

 Yes, I have tested the script on the Subversion server and it runs just fine. 
  And I agree it is obvious that Perl is including the directories to my 
 libraries (so the use lib statements are working as designed as you stated).  
 However, it is Perl that is complaining that it can't find my libraries even 
 though they are clearly in the @INC path.  I have never run into this 
 situation before and I believe it has to do with the fact that the Subversion 
 hook is running with no environment defined, but why it makes Perl not able 
 to find my libs ONLY when it runs as a Subversion hook I haven't a clue.

 I have temporarily resolved the problem by moving my libraries to the 
 /usr/lib/perl5/site_perl path (which I didn't want to do) which is predefined 
 by my Perl installation in @INC.  The script now runs via the Subversion hook 
 and finds my libraries just fine.  I would, however, like to understand what 
 causes Perl to not recognize my added paths to @INC when it runs as a 
 Subversion hook.

 Craig

 -Original Message-
 From: David Weintraub [mailto:qazw...@gmail.com]
 Sent: Wednesday, March 03, 2010 9:57 PM
 To: Craig Thayer
 Cc: users@subversion.apache.org
 Subject: Re: Perl can't find my libraries when run via the subversion 
 post-commit script

 On Wed, Mar 3, 2010 at 3:15 PM, Craig Thayer ctha...@sensorlogic.com wrote:
 I am at a loss as to why my perl script cannot find my libraries when
 invoked by the subversion post-commit script.  My script runs just fine when
 invoked manually in a terminal window.  I'm aware that the subversion
 post-commit script runs with no environment defined, but the error I'm
 getting (below) makes no sense since the module perl claims it can't find
 (Log.pm) is, in fact, in the '/root/perl5/lib' directory which is clearly
 listed in the @INC array.

 Have you tried logging into the server as the user that runs
 Subversion and tried running the Perl script as that user (and not as
 part of the hook)? You might find the error when you try to execute as
 the user that is running the Subversion server.

 It is obvious that the Perl program is including the directories you
 want to include in the @INC array, so the problem is not in the use
 lib statements.

 I wonder if there is a permission issue going on -- especially since
 these are not standard Perl directories.

 --
 David Weintraub
 qazw...@gmail.com




-- 
David Weintraub
qazw...@gmail.com


Re: Perl can't find my libraries when run via the subversion post-commit script

2010-03-04 Thread Kris Deugau

Craig Thayer wrote:

David,

Thank you for your reply.

Yes, I have tested the script on the Subversion server and it runs just fine.


As root, or as the user the repo is accessed as?

/root isn't usually accessible by any user *other* than root in my 
experience, and most of the documentation assumes that svnserve or 
Apache (and therefore, all of your hook scripts) are running as one of:

- dedicated svn user
- Apache runtime user
- various non-root users if using svn+ssh with system users


 And I agree it is obvious that Perl is including the directories to my 
libraries (so the use lib statements are working as designed as you stated).  
However, it is Perl that is complaining that it can't find my libraries even 
though they are clearly in the @INC path.  I have never run into this situation 
before and I believe it has to do with the fact that the Subversion hook is 
running with no environment defined, but why it makes Perl not able to find my 
libs ONLY when it runs as a Subversion hook I haven't a clue.


I tried a quick test creating an empty module in /root:

===
package Testme;

our $foobar = foo!;
===

then ran

perl -e 'use lib /root; use Testme;'

as root and as non-root.

Running as root succeeded, non-root failed with Can't locate Testme.pm 
in @INC


I suspect you'd still have the issue even if you hardcoded the absolute 
path;  Perl can't find the module because it can't read the directory 
it's in.



I have temporarily resolved the problem by moving my libraries to the 
/usr/lib/perl5/site_perl path (which I didn't want to do) which is predefined 
by my Perl installation in @INC.  The script now runs via the Subversion hook 
and finds my libraries just fine.  I would, however, like to understand what 
causes Perl to not recognize my added paths to @INC when it runs as a 
Subversion hook.


perl -V should show you the standard include paths;  custom local 
modules intended for general use should usually go somewhere under 
/usr/local/lib, and I've usually seen custom modules for specific uses 
get bundled into /usr/share/app or /usr/lib/app, along with a 
matching use lib in the executables.


-kgd


RE: Perl can't find my libraries when run via the subversion post-commit script

2010-03-04 Thread Craig Thayer
Bingo!  That was it.  Thank you Chris and David.  David, I'm sorry I didn't try 
executing the script as the user the hook script runs as (which is apache BTW) 
as I already had a workaround.  But when Chris mentioned that the /root 
directory is typically setup with root access only the light finally went on in 
my head.  So I tried it and, sure enough, that is  why Perl couldn't find my 
libraries.

I guess I'll just leave my libraries where I put them for the workaround.

Thanks again guys for your help.  I really appreciate it.

Craig

-Original Message-
From: Chris Shelton [mailto:cshel...@shelton-family.net] 
Sent: Thursday, March 04, 2010 12:13 PM
To: Craig Thayer
Cc: users@subversion.apache.org
Subject: Re: Perl can't find my libraries when run via the subversion 
post-commit script

Craig,

On Thu, Mar 4, 2010 at 12:20 PM, Craig Thayer ctha...@sensorlogic.com wrote:

 Yes, I have tested the script on the Subversion server and it runs just fine. 
  And I agree it is obvious that Perl is including the directories to my 
 libraries (so the use lib statements are working as designed as you stated).  
 However, it is Perl that is complaining that it can't find my libraries even 
 though they are clearly in the @INC path.  I have never run into this 
 situation before and I believe it has to do with the fact that the Subversion 
 hook is running with no environment defined, but why it makes Perl not able 
 to find my libs ONLY when it runs as a Subversion hook I haven't a clue.

Did you run the script as the user that runs Subversion as David
suggested?  This user is generally apache, nobody, www-data or such on
unix type systems.  The /root directory is typically setup with root
user only access, which would prevent a script running as a non-root
user from being able to access files in /root/perl5/lib.

chris