multiple rsyncd daemons: init script

Johan Huysmans johan.huysmans at
Fri Dec 21 08:19:46 GMT 2007


Thanks for the input.

I worked this out and have now an init script which can work with multiple
rsync instances. 

I've read through the daemon and killproc functions of the functions file,
and found an even easier solution. The only requirement is dat the basename
of the pid file must be the same as the init script.

Here is my init script:

#! /bin/sh
# chkconfig:   2345 50 50
# description: The rsync daemon

# source function library
. /etc/rc.d/init.d/functions


# Adapt the --config parameter to point to your rsync daemon configuration
# The config file must contain following line:
#  pid file = /var/run/<filename>.pid
# Where <filename> is the filename of the init script (= this file)
OPTIONS="--daemon --config=/etc/rsyncd.conf"

case "$1" in
        echo -n $"Starting $BASE: "
        daemon --check $BASE $PROG $OPTIONS
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASE
        echo -n $"Shutting down $BASE: "
        killproc $BASE
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BASE
        $0 stop
        sleep 1
        $0 start
        echo "Usage: $0 {start|stop|restart|force-reload}" >&2
        exit 1

exit 0

Matt McCutchen-7 wrote:
> On Wed, 2007-12-19 at 11:10 +0100, Johan Huysmans wrote: 
>> I want to run 2 rsync daemons on my system. Each has its own 
>> configuration file, and they are listening on a specific port.
>> These 2 daemons are running perfectly but getting them started by 2 init 
>> scripts is a bit more difficult.
>> The problem is that when stopping rsync you check the pid of rsync, 
>> which results in both pids of the daemons.
>> Off course i want the script to be very generic, meaning that they are 
>> identical for both daemons, except the rsync options.
>> But the script must also be used in a simple situation (= 1 rsync daemon 
>> running on the system).
>> Does someone have such init script or ideas of how that should be build.
>> I'm trying using the functions provided by /etc/init.d/functions on a 
>> centos system.
>> This will check for the pid in /var/run/, but this doesn't work 
>> nicely with multiple daemons.
> Just use a different pid file for each daemon, perhaps
> /var/run/ and /var/run/ .  Each daemon's
> configuration file should specify the location of that daemon's pid
> file.  Then, on the reasonable assumption that your CentOS init.d
> functions work like my Fedora ones, it looks like each init script just
> has to specify the appropriate pid file to killproc:
> killproc -p /var/run/ rsync
> The httpd init script has an example of this usage of killproc.
> If you are unhappy with hard-coding a different pid file in each init
> script: each script must know somehow which daemon configuration file it
> is supposed to specify to rsync, so the scripts could parse the pid file
> path out of the configuration file using sed.
> Matt
> -- 
> To unsubscribe or change options:
> Before posting, read:

View this message in context:
Sent from the Samba - rsync mailing list archive at

More information about the rsync mailing list