I am developing a server app. I have a remote machine with Debian that I use for testing. Currently I update the server manually when each new svn version comes out. It is just a testing server and traffic on it is free for me. I created a simple script that downloads the latest svn (HEAD) revision and recompiles my server.

I wonder if it is possible to create a .sh script (Debian compatible) that a normal user (not SU) would be able to start with something like nohup ./superScript.sh >& /dev/null & and which would once a minute look into some SVN, find out current version and, if there was an update, run commands like:

kill `ps aux | grep -F 'ServerAPP' | grep -v -F 'grep' | awk '{ print $2 }'` 
cd server/install-dir/
export LD_LIBRARY_PATH=./:~/server/install-dir/lib_boost:~/server/install-dir/lib_openSSL
nohup ./ServerAPP >& /dev/null &

that would kill the currently running app, run some auto-update script we already have in the user's home (~) and run it again.

Is it possible to create such a script and how do I do it?

3 Answers 3


Well, any script can be written, but I think at first about slightly different methodology of monitoring and update (I hate every-minutes connects to repo)

  1. Push notification from repo to server instead of pulling repo from server, if you can manage repository (post-commit hook in repository can do almost anything)
  2. On "commit happened" event server run script, which
    • svn up code to local working copy
    • svn export code from WC to some location
    • ... perform all other steps

If you can't use repository hooks, add svn up | grep + some code in user's crontab.

Grep for svn up is needed in order to differentiate update with data from data-less update.

Real update (example)

>svn up
Updating '.':
U    index.html
Updated to revision 9012.

Empty update

>svn up
Updating '.':
At revision 9012.

Letter in front of affected object show action

A  Added
D  Deleted
U  Updated
C  Conflict
G  Merged
E  Existed
R  Replaced
  • Push notification from repo to server - haha - quite hard to get push from google code...=(
    – myWallJSON
    Jan 19, 2012 at 18:31
  • So as far as I see every-minutes connects to repo is my only and so best and most simple option=)
    – myWallJSON
    Jan 19, 2012 at 18:40
  • 1
    @myWallJSON Can't see big problem here, GC have hooks Jan 19, 2012 at 18:41

You could combine all these commands into one .sh file, like this:

kill `ps aux | grep -F 'ServerAPP' | grep -v -F 'grep' | awk '{ print $2 }'` 
export LD_LIBRARY_PATH=./:~/server/install-dir/lib_boost:~/server/install-dir/lib_openSSL
nohup /full/path/to/ServerAPP >& /dev/null &

Paste it all into file yourname.sh and make executable:

chmod +x yourname.sh

Also it's possible to checkout right from script svn co url://, and you'll be able to automate whole process.

  • Yep - I have kill etc in one .sh file - the thing I wonder is how to create that automation loop=)
    – myWallJSON
    Jan 19, 2012 at 17:40
  • Sorry for misunderstanding. You could use svn hooks as described in documentation: svnbook.red-bean.com/en/1.1/ch05s02.html Use script that will ssh into your dev machine after commit happened and run your automated script. Jan 20, 2012 at 5:44

To answer your question about a normal user, if your program (assuming a network based server) uses unprivileged ports (above 1000), then the user can run it without su/sudo.

Take a different take on it.

if ./server_automated_net_setup.sh; then
    kill `ps x --no-header --format=pid,cmd | awk '!/awk/&&/ServerAPP/{print $1}'` 2>&-
    cd $HOME/server/install-dir
    nohup env LD_LIBRARY_PATH=./:$HOME/server/install-dir/lib_boost:$HOME/server/install-dir/lib_openSSL ./ServerAPP >& /dev/null &

You would need to change your server_automated_net_setup.sh to return success (0) if something was updated and rebuilt, and failure (1) if nothing changed.

Then call this script from cron every period. If you have every minute, there may be too much disk thrashing between updating and rebuilding the software. There is also nothing preventing you from calling the script yourself.

For the server_automated_net_setup.sh, I'd do something close to:

if [ -n `svn status -qu $wcdir | awk '/^........\*/'` ]; then
        gmake -C $wcdir svn-update rebuild deploy
    echo $?
    exit 1

The gmake would perform the svn+update before a partial build and copying the artifact to the installation directory (deploy).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .