Thursday, January 12, 2012

Rsync (or any other cygwin daemon) as a Windows service

Today I was asked to quickly put together a script to replicate files/directories from a central server to a number of XP clients. This would be dead simple if it was not for Windows.
The customer originally thought of robocopy/xcopy but I dont' really trust them: error reporting is kinda difficult to read and copying over cifs is slow and unreliable. So I set out to build it on top of rsync, but to do that I had to find a way to get rsync installed as a service on all the clients.

Turns out it's quite easy. I started from a clean cygwin install to which I added rsync and cygrunsrv. The latter is the native cygwin tool that can be use to run any tradition *nix daemon as a native Windows service.
Even a basic install like this will be in the order of 50MB or so which is too large for quick deployments. I then started trimming all the stuff that was not essential to the rsync service.

At the end of the trimming process I was left with a mere 10MB, which after being compressed in a nice nsis setup (source here) went down to 5MB. That should be small enough.

This is the complete list of files that I kept from the original cygwin install. I deleted all uneeded programs (like awk, groff, etc), man pages, static libraries, header files, timezones and even language translations (except a few basic ones). Please note that the rsyncd.conf was created by me with the settings needed on this specific occasion: