#!/bin/bash
# chkconfig: 2345 20 80
# description: rsync.sh
function start_rsync {
        if [ ! -s /var/run/rsyncd.pid ];then
                /usr/bin/rsync --daemon
        else
                echo -e "\033[33mRsync is already running\033[0m"
        fi
}
function stop_rsync {
        if [ -s /var/run/rsyncd.pid ];then
                kill `cat /var/run/rsyncd.pid`
        else
                echo -e "\033[33mRsync is no running\033[0m"
                return 1
        fi
}
function restart_rsync {
        stop_rsync
        if [ $? -ne 1 ];then
                sleep 1
                start_rsync
        fi
}
case $1 in
        start)
        start_rsync
        ;;
        stop)
        stop_rsync
        ;;
        restart)
        restart_rsync
        ;;
        *)
        echo -e "\033[33mUsage: start | stop | restart \033[0m"
        ;;
esac
chmod +x /etc/init.d/rsync.sh
chkconfig  --add rsync.sh
chkconfig rsync.sh on
[Unit]
After=network.target remote-fs.target
[Service]
Type=forking
ExecStart=/etc/init.d/rsync.sh start
ExecReload=/etc/init.d/rsync.sh restart
ExecStop=/etc/init.d/rsync.sh stop
[Install]
WantedBy=multi-user.target原文:https://www.cnblogs.com/IMSCZ/p/12193623.html