| 1 |
#! /bin/sh |
| 2 |
|
| 3 |
### BEGIN INIT INFO |
| 4 |
# Provides: rsyncd |
| 5 |
# Required-Start: $remote_fs $syslog |
| 6 |
# Required-Stop: $remote_fs $syslog |
| 7 |
# Should-Start: $named autofs |
| 8 |
# Default-Start: 2 3 4 5 |
| 9 |
# Default-Stop: |
| 10 |
# Short-Description: fast remote file copy program daemon |
| 11 |
# Description: rsync is a program that allows files to be copied to and |
| 12 |
# from remote machines in much the same way as rcp. |
| 13 |
# This provides rsyncd daemon functionality. |
| 14 |
### END INIT INFO |
| 15 |
|
| 16 |
set -e |
| 17 |
|
| 18 |
# /etc/init.d/rsync: start and stop the rsync daemon |
| 19 |
|
| 20 |
DAEMON=/usr/bin/rsync |
| 21 |
RSYNC_ENABLE=false |
| 22 |
RSYNC_OPTS='' |
| 23 |
RSYNC_DEFAULTS_FILE=/etc/default/rsync |
| 24 |
RSYNC_CONFIG_FILE=/etc/rsyncd.conf |
| 25 |
RSYNC_PID_FILE=/var/run/rsync.pid |
| 26 |
RSYNC_NICE_PARM='' |
| 27 |
RSYNC_IONICE_PARM='' |
| 28 |
|
| 29 |
test -x $DAEMON || exit 0 |
| 30 |
|
| 31 |
. /lib/lsb/init-functions |
| 32 |
|
| 33 |
if [ -s $RSYNC_DEFAULTS_FILE ]; then |
| 34 |
. $RSYNC_DEFAULTS_FILE |
| 35 |
case "x$RSYNC_ENABLE" in |
| 36 |
xtrue|xfalse) ;; |
| 37 |
xinetd) exit 0 |
| 38 |
;; |
| 39 |
*) log_failure_msg "Value of RSYNC_ENABLE in $RSYNC_DEFAULTS_FILE must be either 'true' or 'false';" |
| 40 |
log_failure_msg "not starting rsync daemon." |
| 41 |
exit 1 |
| 42 |
;; |
| 43 |
esac |
| 44 |
case "x$RSYNC_NICE" in |
| 45 |
x[0-9]|x1[0-9]) RSYNC_NICE_PARM="--nicelevel $RSYNC_NICE";; |
| 46 |
x) ;; |
| 47 |
*) log_warning_msg "Value of RSYNC_NICE in $RSYNC_DEFAULTS_FILE must be a value between 0 and 19 (inclusive);" |
| 48 |
log_warning_msg "ignoring RSYNC_NICE now." |
| 49 |
;; |
| 50 |
esac |
| 51 |
case "x$RSYNC_IONICE" in |
| 52 |
x-c[123]*) RSYNC_IONICE_PARM="$RSYNC_IONICE";; |
| 53 |
x) ;; |
| 54 |
*) log_warning_msg "Value of RSYNC_IONICE in $RSYNC_DEFAULTS_FILE must be -c1, -c2 or -c3;" |
| 55 |
log_warning_msg "ignoring RSYNC_IONICE now." |
| 56 |
;; |
| 57 |
esac |
| 58 |
fi |
| 59 |
|
| 60 |
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" |
| 61 |
|
| 62 |
rsync_start() { |
| 63 |
if [ ! -s "$RSYNC_CONFIG_FILE" ]; then |
| 64 |
log_failure_msg "missing or empty config file $RSYNC_CONFIG_FILE" |
| 65 |
log_end_msg 1 |
| 66 |
exit 0 |
| 67 |
fi |
| 68 |
# See ionice(1) |
| 69 |
if [ -n "$RSYNC_IONICE_PARM" ] && [ -x /usr/bin/ionice ] && |
| 70 |
/usr/bin/ionice "$RSYNC_IONICE_PARM" true 2>/dev/null; then |
| 71 |
/usr/bin/ionice "$RSYNC_IONICE_PARM" -p$$ > /dev/null 2>&1 |
| 72 |
fi |
| 73 |
if start-stop-daemon --start --quiet --background \ |
| 74 |
--pidfile $RSYNC_PID_FILE --make-pidfile \ |
| 75 |
$RSYNC_NICE_PARM --exec $DAEMON \ |
| 76 |
-- --no-detach --daemon --config "$RSYNC_CONFIG_FILE" $RSYNC_OPTS |
| 77 |
then |
| 78 |
rc=0 |
| 79 |
sleep 1 |
| 80 |
if ! kill -0 $(cat $RSYNC_PID_FILE) >/dev/null 2>&1; then |
| 81 |
log_failure_msg "rsync daemon failed to start" |
| 82 |
rc=1 |
| 83 |
fi |
| 84 |
else |
| 85 |
rc=1 |
| 86 |
fi |
| 87 |
if [ $rc -eq 0 ]; then |
| 88 |
log_end_msg 0 |
| 89 |
else |
| 90 |
log_end_msg 1 |
| 91 |
rm -f $RSYNC_PID_FILE |
| 92 |
fi |
| 93 |
} # rsync_start |
| 94 |
|
| 95 |
|
| 96 |
case "$1" in |
| 97 |
start) |
| 98 |
if "$RSYNC_ENABLE"; then |
| 99 |
log_daemon_msg "Starting rsync daemon" "rsync" |
| 100 |
if [ -s $RSYNC_PID_FILE ] && kill -0 $(cat $RSYNC_PID_FILE) >/dev/null 2>&1; then |
| 101 |
log_progress_msg "apparently already running" |
| 102 |
log_end_msg 0 |
| 103 |
exit 0 |
| 104 |
fi |
| 105 |
rsync_start |
| 106 |
else |
| 107 |
if [ -s "$RSYNC_CONFIG_FILE" ]; then |
| 108 |
[ "$VERBOSE" != no ] && log_warning_msg "rsync daemon not enabled in $RSYNC_DEFAULTS_FILE, not starting..." |
| 109 |
fi |
| 110 |
fi |
| 111 |
;; |
| 112 |
stop) |
| 113 |
log_daemon_msg "Stopping rsync daemon" "rsync" |
| 114 |
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $RSYNC_PID_FILE |
| 115 |
RETVAL="$?" |
| 116 |
log_end_msg $RETVAL |
| 117 |
if [ $RETVAL != 0 ] |
| 118 |
then |
| 119 |
exit 1 |
| 120 |
fi |
| 121 |
rm -f $RSYNC_PID_FILE |
| 122 |
;; |
| 123 |
|
| 124 |
reload|force-reload) |
| 125 |
log_warning_msg "Reloading rsync daemon: not needed, as the daemon" |
| 126 |
log_warning_msg "re-reads the config file whenever a client connects." |
| 127 |
;; |
| 128 |
|
| 129 |
restart) |
| 130 |
set +e |
| 131 |
if $RSYNC_ENABLE; then |
| 132 |
log_daemon_msg "Restarting rsync daemon" "rsync" |
| 133 |
if [ -s $RSYNC_PID_FILE ] && kill -0 $(cat $RSYNC_PID_FILE) >/dev/null 2>&1; then |
| 134 |
start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $RSYNC_PID_FILE |
| 135 |
else |
| 136 |
log_warning_msg "rsync daemon not running, attempting to start." |
| 137 |
rm -f $RSYNC_PID_FILE |
| 138 |
fi |
| 139 |
rsync_start |
| 140 |
else |
| 141 |
if [ -s "$RSYNC_CONFIG_FILE" ]; then |
| 142 |
[ "$VERBOSE" != no ] && log_warning_msg "rsync daemon not enabled in $RSYNC_DEFAULTS_FILE, not starting..." |
| 143 |
fi |
| 144 |
fi |
| 145 |
;; |
| 146 |
|
| 147 |
status) |
| 148 |
status_of_proc -p $RSYNC_PID_FILE "$DAEMON" rsync |
| 149 |
exit $? # notreached due to set -e |
| 150 |
;; |
| 151 |
*) |
| 152 |
echo "Usage: /etc/init.d/rsync {start|stop|reload|force-reload|restart|status}" |
| 153 |
exit 1 |
| 154 |
esac |
| 155 |
|
| 156 |
exit 0 |