RE: Perl can't find my libraries when run via the subversion post-commit script
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
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
Perl can't find my libraries when run via the subversion post-commit script
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. The problem is most likely a perl issue, but since the problem only occurs when my script is run via the subversion post-commit operation I'm hoping that someone else has run into this issue with subversion hooks executing a perl script and can enlighten me as to what I'm missing here. It acts like perl is compiling the 'use' statements BEFORE it compiles the BEGIN section-which comes first. Here is the error reported by the commit operation when it runs the post-commit script (which calls my svn-post-commit.pl script): 'post-commit' hook failed with error output: Can't locate Log.pm in @INC (@INC contains: lib ../lib /root/perl5/lib /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /var/svn/repos/cirrus/hooks/svn-post-commit.pl line 96. BEGIN failed--compilation aborted at /var/svn/repos/cirrus/hooks/svn-post-commit.pl line 96. My script adds the path '/root/perl5/lib' to the @INC array in the BEGIN section and my 'use Log' statement is in the main body after the BEGIN section. I've tried several different methods for trying to get perl to find my libraries to no avail (including exporting the PERL5LIB EV in the post-commit script before calling my script and using the 'require' function-but this creates a whole new set of problems with libraries included by the libraries and I don't want to have to hard code paths to libraries in all my modules). And I don't want to place our libraries in one of the perl library paths-which perl seems to have no trouble finding libraries installed with it package (e.g., File::Basename, Net::SMTP, etc.). post-commit script called by subversion commit: REPOS=$1 REV=$2 /var/svn/repos/cirrus/hooks/svn-post-commit.pl $REPOS $REV Snippet of my svn-post-commit.pl perl script called via the post-commit script: use strict; use warnings; use File::Basename; use Getopt::Long; use Net::SMTP; BEGIN { use lib /root/perl5/lib; use lib ../lib; use lib lib; } use Log; use Singleton; use Timestamp; System information: Server info: CentOS 2.6.18-164.6.1.el5 x86_64 x86_64 x86_64 GNU/Linux Subversion v1.4.2 Perl v5.8.8 Client Info: Subversion Client: TortoiseSVN 1.6.7, Build 18415 - 64 Bit , 2010/01/22 17:55:06 Commit operation was performed from my Windows 7 machine, but the subversion repository and hook scripts are on a Linux server. Any help would be greatly appreciated!