#!/usr/bin/env /lib/runit/invoke-run
set -e

NAME="rsync"
DAEMON=/usr/bin/rsync

# Exit service if DAEMON is not installed
if [ ! -x $DAEMON ]; then
    exit 161
fi

# Load defaults
[ -f /etc/default/rsync ] && . /etc/default/rsync
if ! "$RSYNC_ENABLE"; then
    exit 161
fi

# Create config file if needed
if [ ! -f /etc/rsyncd.conf ]; then
    cp /usr/share/doc/rsync/examples/rsyncd.conf /etc/rsyncd.conf
fi

exec 2>&1

exec $DAEMON --daemon --no-detach
