Monthly Archives: February 2012

How to create a Subversion post-commit hook that runs in the background

Recently I needed to do something in a post-commit Subversion hook that can take a long time, and unless the hook runs in the background, the repository would be unavailable until the hook completes.

The solution:

  1. Create a separate script to perform the time-consuming task, the way you always create a script. The hook script (hooks/post-commit) will be like a wrapper, calling the main script.
  2. In hooks/post-commit, start the main script in the background, and redirect all its output to /dev/null
For example hooks/post-commit will look like this:
./time-consuming-script.sh $* >/dev/null 2>/dev/null &
The catch here was redirecting error output (2>/dev/null). Without that, the process was not fully in the background.

By the another (small) catch is that the post-commit template file (hooks/post-commit.tmpl) should not exist, or have size 0, otherwise the real hook script is ignored.

Updates on bashoneliners.com

  • Now you can post comments on one-liners
  • Comments are shown collapsed by default
  • Dangerous operations (delete one-liner, question) have more prominent (red) buttons
  • Show more of the user interface even when not logged in, as a demo
  • Clarified, adjusted, simplified the texts here and there, posting tips

Updates on bashoneliners.com

  • Migrated to Bootstrap 2 from Twitter. Thanks to that the site is now readable on mobile devices, with fluid flowing text.
  • Revised and improved the formatting of all pages.
  • Added ‘Accept this answer’ button to proposed answers.
  • Now your can preview Explanations and Limitations fields when posting or editing a one-liner.
  • Added ‘Post an alternative one-liner’ button, so if you know a better one-liner, you can post it and relate it to the original one.

Not my most relaxing weekend, but hopefully it was worth it!