Skip to main content

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:

.
./bin
./bin/afmtodit
./bin/apropos
./bin/ash.exe
./bin/awk
./bin/bash.exe
./bin/bashbug
./bin/bzcmp
./bin/bzdiff
./bin/bzegrep
./bin/bzfgrep
./bin/bzgrep
./bin/bzless
./bin/bzmore
./bin/chem
./bin/chroot.exe
./bin/copy-user-registry-fstab
./bin/cp.exe
./bin/cygattr-1.dll
./bin/cygbz2-1.dll
./bin/cygcheck.exe
./bin/cygdrop.exe
./bin/cygform-10.dll
./bin/cygformw-10.dll
./bin/cyggcc_s-1.dll
./bin/cyghistory7.dll
./bin/cygiconv-2.dll
./bin/cygintl-8.dll
./bin/cyglsa-config
./bin/cyglsa.dll
./bin/cyglsa64.dll
./bin/cyglzma-5.dll
./bin/cygmagic-1.dll
./bin/cygmenu-10.dll
./bin/cygmenuw-10.dll
./bin/cygmp-3.dll
./bin/cygncurses++-10.dll
./bin/cygncurses++w-10.dll
./bin/cygncursesw-10.dll
./bin/cygpanel-10.dll
./bin/cygpanelw-10.dll
./bin/cygpath.exe
./bin/cygpcre-0.dll
./bin/cygpcreposix-0.dll
./bin/cygpopt-0.dll
./bin/cygreadline7.dll
./bin/cygrunsrv.exe
./bin/cygserver-config
./bin/cygsigsegv-2.dll
./bin/cygstart.exe
./bin/cygtic-10.dll
./bin/cygticw-10.dll
./bin/cygwin-console-helper.exe
./bin/cygwin1.dll
./bin/cygz.dll
./bin/df.exe
./bin/env.exe
./bin/eqn2graph
./bin/gdiffmk
./bin/gettext.sh
./bin/grap2graph
./bin/groffer
./bin/grog
./bin/gunzip
./bin/gzexe
./bin/igawk
./bin/install-info.exe.manifest
./bin/install.exe.manifest
./bin/ipck
./bin/kill.exe
./bin/ls.exe
./bin/lzcat
./bin/lzcmp
./bin/lzdiff
./bin/lzegrep
./bin/lzfgrep
./bin/lzgrep
./bin/lzless
./bin/lzma
./bin/lzmore
./bin/man2dvi
./bin/manlint
./bin/manpath
./bin/md5sum.exe
./bin/mintty.exe
./bin/mkdir.exe
./bin/mmroff
./bin/neqn
./bin/nroff
./bin/pdfroff
./bin/pdftexi2dvi
./bin/peflagsall
./bin/pic2graph
./bin/pwd.exe
./bin/rebaseall
./bin/rm.exe
./bin/roff2dvi
./bin/roff2html
./bin/roff2pdf
./bin/roff2ps
./bin/roff2text
./bin/roff2x
./bin/rsync.exe
./bin/run.exe
./bin/sh.exe
./bin/sleep.exe
./bin/stty.exe
./bin/su.exe
./bin/tail.exe
./bin/texi2dvi
./bin/texi2pdf
./bin/touch.exe
./bin/uncompress
./bin/unlzma
./bin/unxz
./bin/updatedb
./bin/users.exe
./bin/vdir.exe
./bin/wc.exe
./bin/whatis
./bin/which.exe
./bin/xzcat
./bin/xzcmp
./bin/xzdiff
./bin/xzegrep
./bin/xzfgrep
./bin/xzgrep
./bin/xzless
./bin/xzmore
./bin/zcat
./bin/zcmp
./bin/zdiff
./bin/zegrep
./bin/zfgrep
./bin/zforce
./bin/zgrep
./bin/zless
./bin/zmore
./bin/znew
./bin/[.exe
./Cygwin.bat
./Cygwin.ico
./dev
./dev/fd
./dev/mqueue
./dev/shm
./dev/stderr
./dev/stdin
./dev/stdout
./etc
./etc/alternatives
./etc/alternatives/README
./etc/bash.bashrc
./etc/bash.bash_logout
./etc/defaults
./etc/defaults/etc
./etc/defaults/etc/bash.bashrc
./etc/defaults/etc/bash.bash_logout
./etc/defaults/etc/cygserver.conf
./etc/defaults/etc/DIR_COLORS
./etc/defaults/etc/man.conf
./etc/defaults/etc/profile
./etc/defaults/etc/profile.d
./etc/defaults/etc/profile.d/lang.csh
./etc/defaults/etc/profile.d/lang.sh
./etc/defaults/etc/skel
./etc/defaults/etc/skel/.bashrc
./etc/defaults/etc/skel/.bash_profile
./etc/defaults/etc/skel/.inputrc
./etc/defaults/etc/skel/.profile
./etc/DIR_COLORS
./etc/fstab
./etc/fstab.d
./etc/group
./etc/hosts
./etc/man.conf
./etc/mtab
./etc/networks
./etc/passwd
./etc/postinstall
./etc/postinstall/000-cygwin-post-install.sh.done
./etc/postinstall/base-files-mketc.sh.done
./etc/postinstall/base-files-profile.sh.done
./etc/postinstall/bash.sh.done
./etc/postinstall/coreutils.sh.done
./etc/postinstall/man.sh.done
./etc/postinstall/terminfo.sh.done
./etc/postinstall/update-info-dir.sh.done
./etc/preremove
./etc/preremove/base-files-manifest.lst
./etc/preremove/base-files.sh
./etc/preremove/coreutils-manifest.lst
./etc/preremove/coreutils.sh
./etc/preremove/man.sh
./etc/profile
./etc/profile.d
./etc/profile.d/lang.csh
./etc/profile.d/lang.sh
./etc/protocols
./etc/rsyncd.conf
./etc/services
./etc/setup
./etc/setup/alternatives.lst.gz
./etc/setup/base-cygwin.lst.gz
./etc/setup/base-files.lst.gz
./etc/setup/bash.lst.gz
./etc/setup/bzip2.lst.gz
./etc/setup/coreutils.lst.gz
./etc/setup/cygrunsrv.lst.gz
./etc/setup/cygutils.lst.gz
./etc/setup/cygwin-doc.lst.gz
./etc/setup/cygwin.lst.gz
./etc/setup/dash.lst.gz
./etc/setup/diffutils.lst.gz
./etc/setup/dos2unix.lst.gz
./etc/setup/editrights.lst.gz
./etc/setup/file.lst.gz
./etc/setup/findutils.lst.gz
./etc/setup/gawk.lst.gz
./etc/setup/gettext.lst.gz
./etc/setup/grep.lst.gz
./etc/setup/groff.lst.gz
./etc/setup/gzip.lst.gz
./etc/setup/installed.db
./etc/setup/ipc-utils.lst.gz
./etc/setup/less.lst.gz
./etc/setup/libattr1.lst.gz
./etc/setup/libbz2_1.lst.gz
./etc/setup/libgcc1.lst.gz
./etc/setup/libgmp3.lst.gz
./etc/setup/libiconv2.lst.gz
./etc/setup/libintl8.lst.gz
./etc/setup/liblzma5.lst.gz
./etc/setup/libncurses10.lst.gz
./etc/setup/libncursesw10.lst.gz
./etc/setup/libpcre0.lst.gz
./etc/setup/libpopt0.lst.gz
./etc/setup/libreadline7.lst.gz
./etc/setup/libsigsegv2.lst.gz
./etc/setup/libstdc++6.lst.gz
./etc/setup/login.lst.gz
./etc/setup/man.lst.gz
./etc/setup/mintty.lst.gz
./etc/setup/rebase.lst.gz
./etc/setup/rsync.lst.gz
./etc/setup/run.lst.gz
./etc/setup/sed.lst.gz
./etc/setup/setup.rc
./etc/setup/tar.lst.gz
./etc/setup/terminfo.lst.gz
./etc/setup/texinfo.lst.gz
./etc/setup/timestamp
./etc/setup/tzcode.lst.gz
./etc/setup/which.lst.gz
./etc/setup/xz.lst.gz
./etc/setup/zlib0.lst.gz
./etc/setup/_update-info-dir.lst.gz
./etc/skel
./etc/skel/.bashrc
./etc/skel/.bash_profile
./etc/skel/.inputrc
./etc/skel/.profile
./home
./lib
./service_install.bat
./service_uninstall.bat
./tmp
./usr
./usr/local
./usr/local/bin
./usr/local/etc
./usr/local/lib
./usr/sbin
./usr/sbin/alternatives.exe
./usr/sbin/backup
./usr/sbin/cygserver.exe
./usr/sbin/makewhatis
./usr/sbin/restore
./usr/sbin/tzselect
./usr/sbin/update-alternatives
./usr/sbin/zdump.exe
./usr/sbin/zic.exe
./usr/share
./usr/share/awk
./usr/share/awk/assert.awk
./usr/share/awk/bits2str.awk
./usr/share/awk/cliff_rand.awk
./usr/share/awk/ctime.awk
./usr/share/awk/ftrans.awk
./usr/share/awk/getopt.awk
./usr/share/awk/gettime.awk
./usr/share/awk/group.awk
./usr/share/awk/join.awk
./usr/share/awk/libintl.awk
./usr/share/awk/noassign.awk
./usr/share/awk/ord.awk
./usr/share/awk/passwd.awk
./usr/share/awk/quicksort.awk
./usr/share/awk/readable.awk
./usr/share/awk/rewind.awk
./usr/share/awk/round.awk
./usr/share/awk/strtonum.awk
./usr/share/awk/walkarray.awk
./usr/share/awk/zerofile.awk
./usr/share/file
./usr/share/file/magic
./usr/share/gettext
./usr/share/gettext/ABOUT-NLS
./usr/share/locale
./usr/share/locale/en@boldquot
./usr/share/locale/en@boldquot/LC_MESSAGES
./usr/share/locale/en@boldquot/LC_MESSAGES/bash.mo
./usr/share/locale/en@boldquot/LC_MESSAGES/gettext-runtime.mo
./usr/share/locale/en@quot
./usr/share/locale/en@quot/LC_MESSAGES
./usr/share/locale/en@quot/LC_MESSAGES/bash.mo
./usr/share/locale/en@quot/LC_MESSAGES/gettext-runtime.mo
./usr/share/locale/en_GB
./usr/share/locale/en_GB/LC_MESSAGES
./usr/share/locale/en_GB/LC_MESSAGES/alternatives.mo
./usr/share/locale/eu
./usr/share/locale/eu/LC_MESSAGES
./usr/share/locale/eu/LC_MESSAGES/coreutils.mo
./usr/share/locale/eu/LC_MESSAGES/grep.mo
./usr/share/locale/eu/LC_MESSAGES/sed.mo
./usr/share/locale/eu/LC_MESSAGES/tar.mo
./usr/share/locale/eu/LC_TIME
./usr/share/locale/eu/LC_TIME/coreutils.mo
./usr/share/locale/it
./usr/share/locale/it/LC_MESSAGES
./usr/share/locale/it/LC_MESSAGES/alternatives.mo
./usr/share/locale/it/LC_MESSAGES/coreutils.mo
./usr/share/locale/it/LC_MESSAGES/diffutils.mo
./usr/share/locale/it/LC_MESSAGES/findutils.mo
./usr/share/locale/it/LC_MESSAGES/gawk.mo
./usr/share/locale/it/LC_MESSAGES/gettext-runtime.mo
./usr/share/locale/it/LC_MESSAGES/grep.mo
./usr/share/locale/it/LC_MESSAGES/sed.mo
./usr/share/locale/it/LC_MESSAGES/tar.mo
./usr/share/locale/it/LC_MESSAGES/xz.mo
./usr/share/locale/it/LC_TIME
./usr/share/locale/it/LC_TIME/coreutils.mo
./usr/share/locale/locale.alias
./usr/share/magic
./usr/share/misc
./usr/share/tabset
./usr/share/tabset/std
./usr/share/tabset/stdcrt
./usr/share/tabset/vt100
./usr/share/tabset/vt300
./usr/share/terminfo
./usr/share/terminfo/41
./usr/share/terminfo/41/Apple_Terminal
./usr/share/terminfo/45
./usr/share/terminfo/45/Eterm
./usr/share/terminfo/45/Eterm-256color
./usr/share/terminfo/45/Eterm-88color
./usr/share/terminfo/45/Eterm-color
./usr/share/terminfo/61
./usr/share/terminfo/61/ansi
./usr/share/terminfo/61/ansi80x25
./usr/share/terminfo/61/ansis
./usr/share/terminfo/63
./usr/share/terminfo/63/cons25
./usr/share/terminfo/63/cygwin
./usr/share/terminfo/63/cygwin-1p5
./usr/share/terminfo/63/cygwin-old
./usr/share/terminfo/64
./usr/share/terminfo/64/dumb
./usr/share/terminfo/67
./usr/share/terminfo/67/gnome
./usr/share/terminfo/67/gnome+pcfkeys
./usr/share/terminfo/67/gnome-2007
./usr/share/terminfo/67/gnome-2008
./usr/share/terminfo/67/gnome-256color
./usr/share/terminfo/67/gnome-fc5
./usr/share/terminfo/67/gnome-rh62
./usr/share/terminfo/67/gnome-rh72
./usr/share/terminfo/67/gnome-rh80
./usr/share/terminfo/67/gnome-rh90
./usr/share/terminfo/68
./usr/share/terminfo/68/hurd
./usr/share/terminfo/6a
./usr/share/terminfo/6a/jfbterm
./usr/share/terminfo/6b
./usr/share/terminfo/6b/kon
./usr/share/terminfo/6b/kon2
./usr/share/terminfo/6c
./usr/share/terminfo/6c/linux
./usr/share/terminfo/6d
./usr/share/terminfo/6d/mach
./usr/share/terminfo/6d/mach-bold
./usr/share/terminfo/6d/mach-color
./usr/share/terminfo/6d/mlterm
./usr/share/terminfo/6d/mrxvt
./usr/share/terminfo/6e
./usr/share/terminfo/6e/nsterm
./usr/share/terminfo/6e/nsterm-old
./usr/share/terminfo/6e/nxterm
./usr/share/terminfo/70
./usr/share/terminfo/70/pcansi
./usr/share/terminfo/70/putty
./usr/share/terminfo/70/putty-256color
./usr/share/terminfo/70/putty-vt100
./usr/share/terminfo/72
./usr/share/terminfo/72/rxvt
./usr/share/terminfo/72/rxvt+pcfkeys
./usr/share/terminfo/72/rxvt-16color
./usr/share/terminfo/72/rxvt-256color
./usr/share/terminfo/72/rxvt-88color
./usr/share/terminfo/72/rxvt-basic
./usr/share/terminfo/72/rxvt-color
./usr/share/terminfo/72/rxvt-cygwin
./usr/share/terminfo/72/rxvt-cygwin-native
./usr/share/terminfo/72/rxvt-xpm
./usr/share/terminfo/73
./usr/share/terminfo/73/screen
./usr/share/terminfo/73/screen+fkeys
./usr/share/terminfo/73/screen-16color
./usr/share/terminfo/73/screen-16color-bce
./usr/share/terminfo/73/screen-16color-bce-s
./usr/share/terminfo/73/screen-16color-s
./usr/share/terminfo/73/screen-256color
./usr/share/terminfo/73/screen-256color-bce
./usr/share/terminfo/73/screen-256color-bce-s
./usr/share/terminfo/73/screen-256color-s
./usr/share/terminfo/73/screen-bce
./usr/share/terminfo/73/screen-s
./usr/share/terminfo/73/screen-w
./usr/share/terminfo/73/screen.Eterm
./usr/share/terminfo/73/screen.linux
./usr/share/terminfo/73/screen.mlterm
./usr/share/terminfo/73/screen.rxvt
./usr/share/terminfo/73/screen.teraterm
./usr/share/terminfo/73/screen.xterm-new
./usr/share/terminfo/73/screen.xterm-r6
./usr/share/terminfo/73/screen.xterm-xfree86
./usr/share/terminfo/73/screen2
./usr/share/terminfo/73/screen3
./usr/share/terminfo/73/sun
./usr/share/terminfo/73/sun1
./usr/share/terminfo/73/sun2
./usr/share/terminfo/74
./usr/share/terminfo/74/teraterm
./usr/share/terminfo/76
./usr/share/terminfo/76/vs100
./usr/share/terminfo/76/vt100
./usr/share/terminfo/76/vt100-am
./usr/share/terminfo/76/vt100-nav
./usr/share/terminfo/76/vt102
./usr/share/terminfo/76/vt200
./usr/share/terminfo/76/vt220
./usr/share/terminfo/76/vt52
./usr/share/terminfo/77
./usr/share/terminfo/77/wsvt25
./usr/share/terminfo/77/wsvt25m
./usr/share/terminfo/78
./usr/share/terminfo/78/xfce
./usr/share/terminfo/78/xterm
./usr/share/terminfo/78/xterm+256color
./usr/share/terminfo/78/xterm+88color
./usr/share/terminfo/78/xterm+app
./usr/share/terminfo/78/xterm+edit
./usr/share/terminfo/78/xterm+noapp
./usr/share/terminfo/78/xterm+pc+edit
./usr/share/terminfo/78/xterm+pcc0
./usr/share/terminfo/78/xterm+pcc1
./usr/share/terminfo/78/xterm+pcc2
./usr/share/terminfo/78/xterm+pcc3
./usr/share/terminfo/78/xterm+pce2
./usr/share/terminfo/78/xterm+pcf0
./usr/share/terminfo/78/xterm+pcf2
./usr/share/terminfo/78/xterm+pcfkeys
./usr/share/terminfo/78/xterm+r6f2
./usr/share/terminfo/78/xterm+sl
./usr/share/terminfo/78/xterm+sl-twm
./usr/share/terminfo/78/xterm+vt+edit
./usr/share/terminfo/78/xterm-1002
./usr/share/terminfo/78/xterm-1003
./usr/share/terminfo/78/xterm-16color
./usr/share/terminfo/78/xterm-24
./usr/share/terminfo/78/xterm-256color
./usr/share/terminfo/78/xterm-88color
./usr/share/terminfo/78/xterm-8bit
./usr/share/terminfo/78/xterm-basic
./usr/share/terminfo/78/xterm-bold
./usr/share/terminfo/78/xterm-color
./usr/share/terminfo/78/xterm-hp
./usr/share/terminfo/78/xterm-new
./usr/share/terminfo/78/xterm-nic
./usr/share/terminfo/78/xterm-noapp
./usr/share/terminfo/78/xterm-old
./usr/share/terminfo/78/xterm-pcolor
./usr/share/terminfo/78/xterm-r5
./usr/share/terminfo/78/xterm-r6
./usr/share/terminfo/78/xterm-sco
./usr/share/terminfo/78/xterm-sun
./usr/share/terminfo/78/xterm-vt220
./usr/share/terminfo/78/xterm-vt52
./usr/share/terminfo/78/xterm-xf86-v32
./usr/share/terminfo/78/xterm-xf86-v33
./usr/share/terminfo/78/xterm-xf86-v333
./usr/share/terminfo/78/xterm-xf86-v40
./usr/share/terminfo/78/xterm-xf86-v43
./usr/share/terminfo/78/xterm-xf86-v44
./usr/share/terminfo/78/xterm-xfree86
./usr/share/terminfo/78/xterm-xi
./usr/share/terminfo/78/xterm1
./usr/share/terminfo/78/xtermc
./usr/share/terminfo/78/xtermm
./usr/share/terminfo/78/xterms
./usr/share/terminfo/78/xterms-sun
./usr/share/texinfo
./usr/share/texinfo/texinfo.cat
./usr/share/texinfo/texinfo.dtd
./usr/share/texinfo/texinfo.xsl
./usr/src
./usr/tmp
./var
./var/cache
./var/cache/man
./var/cache/man/.keep-man
./var/lib
./var/lib/alternatives
./var/lib/alternatives/.keep-alternatives
./var/log
./var/run
./var/run/utmp
./var/tmp

Now the only thing missing is a bat with the commands used to install the service:

c:
cd c:\cygwin\bin\
cygrunsrv -I "RSYNC" -d "Rsync server" -p /bin/rsync.exe -a "--daemon --no-detach"
net start RSYNC

For ssh, telnet, amanda anythin else the steps are quite the same: start from the list above and add the needed dll and binaries. A nsis script that you can use as a template is available here.

Comments

Popular posts from this blog

From 0 to ZFS replication in 5m with syncoid

The ZFS filesystem has many features that once you try them you can never go back. One of the lesser known is probably the support for replicating a zfs filesystem by sending the changes over the network with zfs send/receive.
Technically the filesystem changes don't even need to be sent over a network: you could as well dump them on a removable disk, then receive  from the same removable disk.

Mirth: recover space when mirthdb grows out of control

I was recently asked to recover a mirth instance whose embedded database had grown to fill all available space so this is just a note-to-self kind of post.
Btw: the recovery, depending on db size and disk speed, is going to take long.

The problem A 1.8 Mirth Connect instance was started, then forgotten (well neglected, actually). The user also forgot to setup pruning so the messages filled the embedded Derby database until it grew to fill all the available space on the disk. The SO is linux.

The solution First of all: free some disk space so that the database can be started in embedded mode from the cli. You can also copy the whole mirth install to another server if you cannot free space. Depending on db size you will need a corresponding amount of space: in my case a 5GB db required around 2GB to start, process logs and then store the temp files during shrinking.

Then open a shell as the user that mirth runs as (you're not running it as root, are you?) and cd into the mirth home. …

Indexing Apache access logs with ELK (Elasticsearch+Logstash+Kibana)

Who said that grepping Apache logs has to be boring?

The truth is that, as Enteprise applications move to the browser too, Apache access logs are a gold mine, it does not matter what your role is: developer, support or sysadmin. If you are not mining them you are most likely missing out a ton of information and, probably, making the wrong decisions.
ELK (Elasticsearch, Logstash, Kibana) is a terrific, Open Source stack for visually analyzing Apache (or nginx) logs (but also any other timestamped data).