rsync控制脚本(停止、重启、启动)

原创 楚盟  2017-10-14 15:44  阅读 458 views 次

这个控制脚本在Centos7系统上测试正常,因为不知道如何控制rsync所以在网上找了这个脚本,非常方便,能够快速的停止、启动、重启控制rsync

rsync控制命令(新建好下面的脚本就可以使用):

启动命令:service rsync start
重启命令:service rsync restart
停止命令:service rsync stop

编辑脚本命令:

[root@backup ~]# vi /etc/init.d/rsync

添加如下内容:

#!/bin/bash 
  
#this script for start|stop rsync daemon service 
#date:2012/2/13 
  
status1=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep') 
pidfile="/var/run/rsyncd.pid" 
start_rsync="rsync --daemon --config=/etc/rsyncd.conf" 
  
function rsyncstart() { 
  
    if [ "${status1}X" == "X" ];then 
  
        rm -f $pidfile       
  
        ${start_rsync}   
  
        status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep') 
          
        if [  "${status2}X" != "X"  ];then 
              
            echo "rsync service start.......OK" 
              
        fi 
  
    else 
  
        echo "rsync service is running !"    
  
    fi 
} 
  
function rsyncstop() { 
  
    if [ "${status1}X" != "X" ];then 
      
        kill -9 $(cat $pidfile) 
  
        status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep') 
  
        if [ "${statusw2}X" == "X" ];then 
              
            echo "rsync service stop.......OK" 
        fi 
    else 
  
        echo "rsync service is not running !"    
  
    fi 
} 
  
  
function rsyncstatus() { 
  
  
    if [ "${status1}X" != "X" ];then 
  
        echo "rsync service is running !"   
      
    else 
  
         echo "rsync service is not running !"  
  
    fi 
  
} 
  
function rsyncrestart() { 
  
    if [ "${status1}X" == "X" ];then 
  
               echo "rsync service is not running..." 
  
               rsyncstart 
        else 
  
               rsyncstop 
  
               rsyncstart    
  
        fi       
}  
  
case $1 in 
  
        "start") 
               rsyncstart 
                ;; 
  
        "stop") 
               rsyncstop 
                ;; 
  
        "status") 
               rsyncstatus 
               ;; 
  
        "restart") 
               rsyncrestart 
               ;; 
  
        *) 
          echo 
                echo  "Usage: $0 start|stop|restart|status" 
          echo 
esac

给脚本设置可执行权限:

[root@backup ~]# chmod a+x /etc/init.d/rsync
本文地址:https://www.5yun.org/14392.html
关注我们:请关注一下我们的微信公众号:扫描二维码楚盟网的公众号,公众号:chubin5yun
版权声明:本文为原创文章,版权归 楚盟 所有,欢迎分享本文,转载请保留出处!