WebFaction
Community site: login faq
0
1

This is the only problem I've had with webfaction so far. It seems that no matter what I put into for post-commit, I cannot get it to call trac-admin. I've stepped through and attempted to debug it, and when I run the command from SSH it works perfectly, yet SVN won't call it. I've added the group permissions to all the right files to my knowledge (all group perms for trac-admin and the directory it's in and everything) but still nothing.

I'm wondering if this is an issue with the permissions of whatever service runs the commands for post-commit (some offshoot of the apanche user).

Has anyone gotten this to work and if so, what did you do?

I'm running Trac 0.12.

asked 04 Feb '11, 02:30

netMASA
112
accept rate: 0%

edited 04 Feb '11, 03:43

I assume post-commit hooks that aren't using trac-admin are working fine.

Could you post the post-commit hook you're using?

(04 Feb '11, 02:52) David L ♦♦

Sure. I've used a bunch of different scripts and none of them have worked.

#!/bin/sh

#REPOS="$1"
#REV="$2"
PYTHON_EGG_CACHE=/home/username/webapps/trac/lib/python2.4 /home/username/webapps/trac/bin/trac-admin /home/username/webapps/trac changeset added "$1" "$2"

where username is the account name of my webfaction account. If I use touch in the hooks directory, I do produce files.

(04 Feb '11, 03:01) netMASA

Oh, I think I see the problem.

Post-commit hooks run as the 'apache' user on our servers so you'll need to grant the Apache user permissions on your trac-admin script:

setfacl -m u:apache:r-x $HOME/webapps/trac
(04 Feb '11, 03:08) David L ♦♦

I just got this. I ran the command on both the trac directory and on trac-admin from SSH

post-commit hook failed (exit code 1) with output: Traceback (most recent call last): File "/home/username/webapps/trac/bin/trac-admin", line 5, in ? from pkg_resources import load_entry_point File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 2479, in ? working_set.require(requires) pkg_resources.DistributionNotFound: Trac==0.12

(04 Feb '11, 03:19) netMASA

This only seems to work if I run it under my account. I wrote a quick php file to do the same thing, hoping I could get a result.

Instead what happened was that I could commit successfully but trac-admin never applied changes (and I couldn't get it to create a file, but whatever).

If I run a php script as myself, it works perfectly. What do I do?

(04 Feb '11, 04:14) netMASA

I just tried writing an executable. Of course it works perfectly when I run it, but it fails epicly if apanche tries to run it.

Basically, the post-commit would call the exec which would call php which calls python.

And even then, it still only works for me and no one else

(04 Feb '11, 05:15) netMASA

Hmm. Now I'm not entirely sure if this is going to be possible.

I've checked our support ticket history and I can't find anyone who managed to get trac-admin working from a post-commit hook.

I'm looking for any potential workarounds now but I suspect they won't be the most elegant solutions.

(04 Feb '11, 05:38) David L ♦♦

Any solutions yet?

(04 Feb '11, 09:13) netMASA
showing 5 of 8 show 3 more comments

This post is over a year old, but it pointed me to the correct solution. You need to do two things, set PYTHONPATH and set permissions. In your case define PYTHONPATH in front of your trac-admin call:

PYTHONPATH=/home/username/webapps/trac/lib/python2.4

and set the appropriate permissions on trac.db and its folder:

setfacl -m u:apache:rwx $HOME/webapps/trac/db
setfacl -m u:apache:rw $HOME/webapps/trac/db/trac.db
permanent link

answered 23 Aug '12, 07:32

doug
11
accept rate: 0%

Well, tried that too, didn't work for me.

(13 Feb '13, 21:12) gustavo_rubio

As many things in Linux, I'm not sure if this will work for you but it did for me. After several hours of debugging and trying lots of workarounds I've found the problem, at least for me: it is not permission-related, it is about the path.

This is the code in the trac-admin script:

#!/usr/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'Trac==1.0','console_scripts','trac-admin'
__requires__ = 'Trac==1.0'
import sys
sys.path.append('/home/user/webapps/trac/lib/python2.6')
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('Trac==1.0', 'console_scripts', 'trac-admin')()
    )

So the line requires is the faulty one, python environment tries to find the "Trac 1.0" package but that package is actually installed on your own trac path (eg: /home/user/webapps/trac/lib/python2.6) so the first thing I did was to add both PYTHONPATH and PYTHON_EGG_CACHE to the post-commit script, but for some odd reason it DID NOT worked...

So the fix was to do it in a hardcoded way, I know its not pretty but it works, add a line that appends your local path in the trac-admin file like so:

#!/usr/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'Trac==1.0','console_scripts','trac-admin'
__requires__ = 'Trac==1.0'
import sys
sys.path.append('/home/user/webapps/trac/lib/python2.6')
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('Trac==1.0', 'console_scripts', 'trac-admin')()
    )

If you see theres a new line: sys.path.append('path'), that made work my post-commits.

You also make sure that you have set the permissions both for the trac-admin script and for the post commit so that apache or whatever your webserver user is can execute both of those files.

permanent link

answered 14 Feb '13, 01:15

gustavo_rubio
11
accept rate: 0%

edited 14 Feb '13, 01:17

I was able to get this working without 'hacking' the trac-admin script.

I did a fair bit of trial and error. By redirecting stderr and stdout from the commands in the script to a log file, I was able to monitor what was happening when apache user runs the post commit script.

Here's the post commit script that worked for me:

#!/bin/sh
REPOS="$1"
TXN="$2"
TRAC=/home/<myusername>/webapps/<mytracappname>/

export PYTHON_EGG_CACHE="$TRAC/lib/python2.6"
export PYTHONPATH="$TRAC/lib/python2.6/"
/usr/bin/python2.6 $TRAC/bin/trac-admin $TRAC changeset added $REPOS $TXN

After doing this I also had a few simple permissions issues to resolve in the trac directory. I made sure that my trac/conf contents were fully readable and the directory was accessible to 'other' (chmod 755 for the dir and 644 for the file).

I also tried to set ACL permissions for my DB using setfacl -R -m u:apache rwx on the db directory. This did not work and trac kept reporting a "database timeout" error (which is weird for what should be a permission error). Again, you would not know about this error unless you were capturing stderr to a log file. In the end, I removed the extended acl and just made the whole directory wide open (that's not good!): chmod 777 -R trac/db

Hope this helps (someone)

permanent link

answered 25 Jun '13, 10:56

billh
12
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×41
×26
×3
×3
×1

question asked: 04 Feb '11, 02:30

question was seen: 6,079 times

last updated: 25 Jun '13, 10:56

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM