Unix/Ubuntu

우분투 서버에 트랙 설치... 이번엔 apache + trac + mercurial

ForceCore 2009. 11. 9. 17:16
우분투 9.04 기준으로 작성하였다.

서버 사양.
프로젝트 한개당 한 개의 htpasswd를 공유하는 trac과 mercurial 저장소. trac/mercurial 서버 역할을 하는 것은 아파치로서 다른 데몬을 init.d에 등록하지 않아도 된다. (그러나 아파치 설정은 수정해야지 됨 ㄱ-;;)
필요한 패키지는 잘 모르겠다? mercurial 패키지와 trac, trac-mercurial 패키지를 잘 설치하면 잘 되는 듯 하다? 이미 오래전에 부분부분 깔아놓은 부분이 있어서 잘 모른다.

hgweb cgi 로 mercurial을 서빙 해주겠다. hgwebdir 로 돌리는 상황을 다룬 문서는 많은데, 이런 경우 프로젝트별로 htpasswd 를 다르게 두기가 좀 힘들다. trac도 apache 설정을 이용해 적절히 돌릴 것이다.


파트1
디렉토리 준비.

http://mercurial.selenic.com/wiki/HgWebDirStepByStep
hgweb만 하는건 교재가 좀 없다?

프로젝트 이름이 kara 라고 하면.

/export/hg/kara/cgi
/export/hg/kara/data

이런 폴더를 만들었다.

cgi폴더에는
/usr/share/doc/mercurial/examples/hgweb.cgi
를 복사해 두었다.

권한은 아래와 같다:
chown -R root:root cgi
chmod 755 cgi/hgweb.cgi
chown www-data:root -R data
data안에는 뭐가 있는고 하니 프로젝트의 머큐리얼 데이터가 있다. data/.hg 이런 식이다.

근데 아파치로 돌리기 전에, hgweb.cgi를 수정해야지 된다.
application = hgweb("/export/hg/kara/data", "kara")
hgweb 설정 한 줄만 바꾸면 될 것이다?


파트2
이제 아파치를 설정하면 되는데...

/etc/apache2/conf.d
여기다가 설정 파일을 만들자.

/etc/apache2/conf.d/hgweb 이란 파일.
내용은
ScriptAliasMatch ^/hg/kara(.*) /export/hg/kara/cgi/hgweb.cgi$1
<Directory /export/hg/kara/cgi>
    Options ExecCGI FollowSymLinks
    AllowOverride None
</Directory>
이런 식임. 다른 저장소가 추가되면 또 적절히 설정하면 되겠죠. 아파치 재시작. 그러면
http://lab.xxx.ac.kr/hg/kara
여기로 접속하면 browsing을 할 수 있을 것이다... 만 그렇다고 아무나 읽고 쓰면 곤란하지.

# cd /export/hg/kara
# htpasswd -cm .htpasswd user1 (파일이 존재하지 않는 때에만 c를 붙여서 파일을 생성하게함)
# htpasswd -m .htpasswd user2
# ...
# chown root:root .htpasswd
# chmod 644 .htpasswd
이렇게 유저 생성울 해준다.

hgweb 파일도 다시 수정:
ScriptAliasMatch ^/hg/kara(.*) /export/hg/kara/cgi/hgweb.cgi$1
<Directory /export/hg/kara/cgi>
    Options ExecCGI FollowSymLinks
    AllowOverride None

    AuthType Basic
    AuthName "Kara Repository"
    AuthUserFile /export/hg/kara/.htpasswd
    Require valid-user
</Directory>
그리고 아파치 재시작.... 인증 잘 된다. 이쯤에선 hg 명령어로 pull, push가 될 것이다. 주의할 점은, 비번으로 인증되기만 한 사용자면 pull/push 모두 가능하다는 점이다. 인증 받은 사용자들 중에서도 특정 사용자만 push, pull이 가능하게 하려면

/export/hg/kara/data/.hg/hgrc
[web]
allow_push = frodo, sam
파일에 id를 적절히 적어주면 된다.


파트3
이제 아파치로 kara를 서폿 하는 게 남았다.
VirtualHost 따위(?) 안 쓸거임.

http://trac.edgewall.org/wiki/TracModPython
이 문서를 컨닝하는 것이 좋을 듯.

우분투에선 mod_python 은 아파치에 기본으로 로드되어 있다.

아파치로 돌리는데 필요한 htdocs와 cgi-bin 을 생성해야지 된다. 아래 명령어를 쓰면 만들 수 있다.
# mkdir -p /export/hg/kara/trac (trac으로 쓸 디렉토리 생성)
# trac-admin /export/hg/kara/trac initenv (trac 새로 생성)
# trac-admin /export/hg/kara/trac deploy /tmp/deploy (cg-bin, htdocs가 만들어짐)
# mv /tmp/deploy/* /export/hg/kara/trac (만들어진 곳을 트랙으로 옮겨온다)
# rmdir /tmp/deploy (껍데기는 안 먹어)
# chown root:root -R trac
이제 해당 데이터를 아파치로 돌려보자?

/etc/apache2/conf.d/trac 파일을 생성하고 내용을...
가장 간단한 설정이라고 한다.
<Location /trac/kara>
    SetHandler mod_python
    PythonInterpreter main_interpreter
    PythonHandler trac.web.modpython_frontend
    PythonOption TracEnv /export/hg/kara/trac
    PythonOption TracUriRoot /trac/kara
</Location>
# location에 적은 문구랑 TracUriRoot 랑 똑같이 설정해야지 됨.
이렇게 적어넣었다. 아파치를 재시작 한 뒤
http://lab.xxx.ac.kr/trac/kara 에 접속...
/export/hg/kara/trac/db/trac.db 에 write할 권한이 없다고 에러가 난다. -0-;; 반응이 있으니 희망적이군.
# chown www-data /export/hg/kara/trac/db/trac.db

이런 식으로 write할 수 있게 하면 되겠지... 근데 쓸 수 있는 권한을 줘도 권한 타령을 한다.
# chown www-data /export/hg/kara/trac/db
이것도 해줘야 하기 때문임.

kara repository type을 hg 로 했는데
Warning: Can't synchronize with the repository (Unsupported version control system "hg". Check that the Python support libraries for "hg" are correctly installed.)
이렇게 불평함. 패키지를 덜 깔았나. trac-mercurial 패키지를 설치했지만 그것만으론 불충분하다.

http://daybreaker.springnote.com/pages/3085204
/export/hg/kara/trac/conf/trac.ini를 수정.
[components]
tracext.hg.* = enabled

[hg]
show_rev = yes
node_format = short
이걸 추가했음... 되는듯. 물론 아래에 적힌 항목도 적절히 설정해야지 된다.
[trac]
repository_dir = /export/hg/kara/data
repository_type = hg
이렇게.

근데 트랙 페이지도 아무나 봐선 좀 곤란하지.
/etc/apache2/conf.d/trac 에 아래 내용을 추가한다:
<Location /trac/kara/login>
    AuthType Basic
    AuthName "Kara"
    AuthUserFile /export/hg/kara/.htpasswd
    Require valid-user
</Location>
아파치 재시작. 음... 로그인 하란 말은 뜨는군. 근데 그 뒤에가 에러다.
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
이런 에러다. -0-;;; 에러 로그를 보지 뭐.
[Mon Nov 09 20:29:44 2009] [error] [client xxx.xxx.xxx.xxx] IOError: [Errno 13] Permission denied: u'/export/hg/kara/trac/log/trac.log'
간단하군. 로그 폴더는 아파치도 쓸 수 있게 해주자.
# cd /export/hg/kara/trac
# chown www-data -R log
# chown www-data -R attachments (첨부파일을 업노동 할 수 있으려면 이것도 해줘야...)
이렇게 변경.

trac.ini에 아래 사항도 추가함:
[attachment]
max_size = 20971520
render_unsafe_content = true
첨부파일 용량과...  render_unsafe_content 이건 좀 주의해서 사용해야지 된다. 안 그러면 서버가 털린다. 안전한 서버 외엔 써선 안 되는 옵션이다. html이나 php같은것이 첨부되었어도 브라우저로 보여주는지를 뜻하기 때문이다(!). false로 하면 그냥 다운로드만 가능하게 할 것이다. max_size를 위와 똑같이 하면 정확히 20MB가 될 것이다.