HOWTO: Creating An Automated Staging Server using CVS

By | March 22, 2007

It’s easy to create an automated staging server for content that doesn’t need to be compiled (like most web content.) The trick is that CVS has a very flexible logging system. All you need to do is have your CVS server send an email on each check in and have the staging server take that email and check out the files that changed.

CVS Automated Staging Process

The Bonsai project helpfully wrote a nice perl script which emails check in information in a machine readable format. To use it:

  1. Check out the CVSROOT module on your CVS server
  2. Copy the perl script into that directory
  3. Add the line: ALL $CVSROOT/CVSROOT/ -r /cvs to CVSROOT/loginfo
    1. where /cvs is whatever your cvs path is and is your staging server
  4. Add the script, and check in the file and the change to loginfo.

It’s simple to make the staging server respond to these emails.

  1. Edit your /etc/aliases file and add: cvs-watch: "|cvs-robot"
  2. Check out your CVS module in the appropriate place
  3. Create /etc/smrsh/cvs-robot

So what goes in the cvs-robot script?

#!/bin/shexport CVSROOT=''cd /var

touch /tmp/checkin-errors.log

grep 'www' | grep '. HEAD .' | cut -d" " -f3- | xargs -r cvs update -P -d &> /tmp/checkin-errors.log

This file is only an example. You’ll obviously have a different CVSROOT, and you’ll likely have checked out into a different place than /var. Your module might not be ‘www’ and your branch might not be HEAD. Edit as appropriate.


So what doesn’t work? Well, if you add a new directory, this script fails. I’m not sure why. You’ll need to log onto stage1 and do an update manually to get new directories. Luckily, adding a directory is usually rare.

The update is checked out using the root account. I’m not sure what the security concerns are about doing that, and it’s possible you may have permissions issues. You can create a simple wrapper script that calls the real update command:

#!/bin/shsudo -u apache /etc/smrsh/cvs-robot-real

Leave a Reply

Your email address will not be published. Required fields are marked *