简体   繁体   English

如何通过svn提交后钩子运行svn更新

[英]how to run svn update via svn post-commit hook

Goal: update /var/www with latest on svn commit. 目标:用最新的svn commit更新/var/www

ubuntu server 10.10, latest apache2, latest svn, location: /var/svn/[projectname] ubuntu服务器10.10,最新的apache2,最新的svn,位置: /var/svn/[projectname]

To do this I created a simple post-commit script: 为此,我创建了一个简单的提交后脚本:

#!/bin/bash

#tests if www-data user runs this script on commit (which it does)
touch /tmp/test.log

#works when run from the command line (sudo ./post-commit) but not when run by www-data
sudo /usr/bin/svn update /var/www

To fix the issue of the second command not working as www-data I tried... 要解决第二个命令不能作为www-data工作的问题,我尝试...

Editing: sudo visudo and added (at the end): www-data ALL=(ALL) NOPASSWD:ALL 编辑: sudo visudo并添加(最后): www-data ALL=(ALL) NOPASSWD:ALL

Chowning: /var/www to www-data:www-data 变名: /var/wwwwww-data:www-data

Chmoding: all of /var/www to 777 Chmoding:将所有/var/www改为777

Still no luck... any ideas? 还是没有运气...有什么想法吗?

What if you run this: 如果运行此命令怎么办:

  su - www-data -c '/usr/bin/svn update /var/www'

(The sudo is not needed if /var/www/ is 777 and owned by www-data..) (如果/ var / www /为777并且由www-data拥有,则不需要sudo。)

As the root user? 作为root用户? (then it suid() s as www-data and run the command). (然后将suid()作为www-data并运行命令)。 It should give more information on what does actually fail. 它应该提供有关实际失败的更多信息。

Or, you could try logging the svn update output from your post-commit hook: 或者,您可以尝试从提交后钩子记录svn update输出:

/usr/bin/svn update /var/www &> /tmp/my-svn-update.log

I think that these two tests should give you more informations on what happened. 我认为这两个测试应该为您提供有关发生情况的更多信息。

SIDE NOTE: I'm not sure you really want to take the risk of having www-data able to run any command as the root user.. If you absolutely need to have it run svn as root (I don't see the point there, but it could be), just use this in your /etc/sudoers: 旁注:我不确定您是否真的冒着使www-data能够以root用户身份运行任何命令的风险。如果您绝对需要让它以root用户身份运行svn(我不明白这一点在那里,但可能是),只需在/ etc / sudoers中使用它即可:

www-data ALL=NOPASSWD: /usr/bin/svn

I went first with the logging mechanism you suggested and that helped fix it! 我首先采用了您建议的日志记录机制,这有助于解决该问题! Thank you! 谢谢!

The outputted error had something to do with an filename in the repro which couldn't be converted to UTF-8. 输出的错误与repro中的文件名有关,该文件名无法转换为UTF-8。 I deleted the file and it worked. 我删除了文件,它正常工作。 But why it worked when calling post-commit directly... I've no clue. 但是为什么直接调用后提交时它可以工作...我不知道。

BTW, I was mistaken about it being bash (it was sh) so I had to change &> to 2> 顺便说一句,我被误认为是bash(是sh),所以我不得不将&>更改为2>

Also, I deleted the checked out files, reset the permissions and owner back to normal on /var/www and then checked them out again. 另外,我删除了检出的文件,将权限和所有者重置为/ var / www的正常状态,然后再次检出它们。

my final sudoers line: 我最后的sudoers行:

www-data ALL=NOPASSWD:/usr/bin/svn update /var/www

Thanks so much for the help! 非常感谢你的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM