[root@tweb02 ~]# cat rsync5.sh
#!/bin/bash
# chkconfig: 2345 20 80
# description: rsync start and stop scripts
##############################################################
# File Name: rsync5.sh
# Version: V5.0
# Author: junwang
# Created Time : 2018-06-08 17:28:32
# Description:
##############################################################
lockfile=/mnt/rsyncd
rsync_pid=/var/run/rsyncd.pid
. /etc/init.d/functions
start(){
    if test -e $lockfile
    then
        echo "Rsync service started"
        exit 6
    else
    rsync --daemon
    retval=$?
    if [ $retval -eq 0 ]
    then
        action  "rsync startup ok" /bin/true
        touch $lockfile
        return $retval
    else
      action  "rsync startup fail" /bin/false
        return $retval
    fi
fi
}
stop(){
    if test -s $rsync_pid
    then
        rsyncid=`cat $rsync_pid`
        if (kill -0 $rsyncid)
        then
    killall rsync&>/dev/null
    retval=$?
    if [ $retval -eq 0 ]
    then
        action "rsync stop ok" /bin/true
        rm -f $lockfile
        return $retval
    else
        action  "rsync stop fail" /bin/false
        return $retval
    fi
else
    echo "PID does not exist"
    return $retval
fi
else
    echo "Rsync service did not start"
fi
}
status(){
    if test -s $rsync_pid
    then
        echo "rsync is running"
    else
        echo "rsync is not running"
    fi
}
       
if [ $# -ne 1 ]
then
     echo "usage:$0 {start|stop|restart|status}"
 else
case "$1" in
    start)
        start
        retval=$?
        ;;
    stop)
        stop
        retval=$?
        ;;
    restart)
        stop
        sleep 1
        start
        retval=$?
        ;;
    status)
        status
        retval=$?
        ;;
    *)
        echo "usage:$0 {start|stop|restart|status}"
        exit 1
esac
exit $retval
fi