views:

270

answers:

1

I have the following post-commit hook setup and running:

#!/bin/bash
/usr/bin/svn update /var/www/html/dev > /var/www/svnrepo/hooks/post-commit-log

I'm developing in Python/Django and whenever I make any changes to any ".py" file, I have to SSH in and "sudo /sbin/service httpd restart"... Is there a way to add this to the bottom of the post-commit file?

Some roadblocks I forsee and/or think:

-Fedora Core 8

Thanks! -Tom

+2  A: 

If the Apache process is listening on a port less than 1024, then it'll need to be root to stop and start itself. If you're listening to a port above 1024, then you could start it as a non-root user and then use the a post-commit hook to restart it.

You would also want to use /etc/init.d/httpd graceful instead of restart to not kill connections that are doing work, if graceful is available your Apache version.

Finally, the post-commit hook could start another sub-process in the background that sleeps a few seconds before restarting it to let the client completely finish. You have to make sure the hook script completely detaches itself from stderr. For example, this works as a post-commit hook with Subversion 1.6.1, the client will detach from the server and the sleep will still be running.

#!/bin/sh
/bin/sleep 60 2>/dev/null &

If you can wait one minute for the site to update, you could put in a cron run by root a script that runs "svn update" and if there was an update, bounces the server.

Blair Zajac