开发者

How do I sync a Git-Svn clone through cron?

For reference, I'm running CentOS 5.5 on the server.

I'm working on a distributed project with several other developers, and we're using Git to manage our repositories. Everything's hosted live on Gitorious and working beautifully. However, we need a branch in our repository to stay synchronized with an external Subversion repo - kind of like a "vendor branch" within Git. Reason is: we're building several things based on this existing open source project (WordPress) and want our working copy to inherit any bugfixes they publish in their own repo.

开发者_如何学JAVA

I've got things set up so that we have a separate branch called "wordpress" that can be kept in sync with the live Subversion repo. To do so, it's as simple as:

git checkout wordpress
git svn rebase
git gc
git push origin wordpress

These commands will:

  1. Make sure we're on the WordPress branch
  2. Re-sync the branch with the live Svn repo
  3. Run garbage collection (otherwise the repository progressively gets unmanageably large)
  4. Push the updated branch to our hosted repository on Gitorious

It's easy enough to run these four commands whenever WordPress trunk updates, but that's annoying and a hassle. I'd love to set this up as a cron job, but I can't seem to figure out how!

I've written a script called wordpress.sh and placed it in the /etc/ folder on the server:

#!/bin/bash
cd /var/www/git/wordpress
git checkout wordpress
git svn rebase
git gc
git push origin wordpress

The script runs just fine. I can SSH into my server, log in as root, and type . /etc/wordpress.sh and everything works just fine. But how can I set this up so that cron does things for me?

I've tried manually adding it to crontab (unsuccessfully), using the Webadmin interface in CentOS to add it as an hourly script (unsuccessfully), and now I'm at a loss! My system logs claim that it's firing (log below):

Feb  4 07:00:01 ---- crond[27745]: (root) CMD (/etc/wordpress.sh    #WordPress mirror)
Feb  4 07:01:01 ---- crond[27773]: (root) CMD (run-parts /etc/cron.hourly)
Feb  4 08:00:01 ---- crond[29095]: (root) CMD (/etc/wordpress.sh    #WordPress mirror)
Feb  4 08:01:01 ---- crond[29142]: (root) CMD (run-parts /etc/cron.hourly)
Feb  4 09:00:01 ---- crond[29708]: (root) CMD (/etc/wordpress.sh    #WordPress mirror)
Feb  4 09:01:01 ---- crond[29718]: (root) CMD (run-parts /etc/cron.hourly)
Feb  4 10:00:01 ---- crond[30328]: (root) CMD (/etc/wordpress.sh    #WordPress mirror)
Feb  4 10:01:01 ---- crond[30337]: (root) CMD (run-parts /etc/cron.hourly)

But nothing actually happens unless I log in and run the script manually. Ideas?


Cron runs with another environment than a login shell so a likely error is that git is not in the path. The easiest is usually to use the full path of every command in a crontab (/usr/bin/git or wherever your git is installed).

Errors in scripts run by cron is usually mailed to the user, so try to look in root's mailbox.


Do you run your sites as root? Do you manually run the script as root? I hope you don't.

Now look at cron output: it runs your script from root account, and it probably fails to find the repository. Add it to your account's crontab, not root's.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜