#!/bin/bash
#chkconfig: 2345 30 50
#Date:2017-6-29
#Author:xcn(baishuchao@yeah.net)
#version 1.0
PID="/var/run/rsync.pid"
start_rsync(){
if [ -f $PID ]  
then 
	echo "rsync is running"
else
	 rsync --daemon
	echo "rsync is started"
fi
}

stop_rsync(){
if [ -f $PID ]   #存在而不为空
then
	kill -USR2 `cat $PID`
	rm -rf $PID
	echo "rsync is stoped"
else
	echo "rsync no running"
fi
}

case $1 in
	start)
	start_rsync
	;;
	stop)
	stop_rsync
	;;
	restart)
	stop_rsync
	start_rsync
	;;
	*)
	echo "USAGE:$0 {start|stop|restart}"
	exit1
esac