rsync daemon模式的 启动脚本

1.1 rsync部署情况

01:利用rsync daemon模式部署的备份服务器:

02:Pid文件的路径: pid file = /var/run/rsyncd.pid

03:rsync守护进程的启动方式为:rsync --daemon

1.2 脚本内容

#!/bin/bash
#
# Define variables
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
RETVAL=0
Port=873
Pid=/var/run/rsyncd.pid

# Determine the user to execute
if [ "$UID" -ne "$RETVAL" ];then
  echo "Must be root to run scripts"
  exit 1
fi

# Load local functions
[ -f /etc/init.d/functions ] && source /etc/init.d/functions

# Define functions
start(){
       if [ ! -f "$Pid" ];then
          /usr/bin/rsync --daemon
          RETVAL=$?
          if [ $RETVAL -eq 0 ];then
             action "Start Rsync service[$Port]" /bin/true
            else
             action "Start Rsync service[$Port]" /bin/false
          fi
         else
          echo "Rsync service[$Port] is running"
       fi
       return $RETVAL
}

stop(){
       if [ -f "$Pid" ];then
          kill -USR2 $(cat $Pid)
          rm -f $Pid
          RETVAL=$?
          if [ $RETVAL -eq 0 ];then
             action "Start Rsync service[$Port]" /bin/true
            else
             action "Start Rsync service[$Port]" /bin/false
          fi
         else
          echo "Rsync Service[$Port] is not running"
       fi
       return $RETVAL
}

status(){
       if [ -f "$Pid" ];then
          echo "Rsync service[$Port] is running"
         else
          echo "Rsync service[$Port] is nog running"
       fi
       return $RETVAL
}

# Case callf functions
case "$1" in
 start)
       start
       RETVAL=$?
       ;;
 stop)
       stop
       RETVAL=$?
       ;;
 restart)
       stop
       start
       RETVAL=$?
       ;;
 status)
       status
       RETVAL=$?
       ;;
 *)
       echo "USAGE:$0 {start|stop|restart|status}"
       exit 1
esac

# Scripts return values
exit $RETVAL

1.3 执行脚本

[[email protected] ~]# /etc/init.d/rsyncd
USAGE:/etc/init.d/rsyncd {start|stop|restart|status}

[[email protected] ~]# /etc/init.d/rsyncd status
Rsync service[873] is running

[[email protected] ~]# /etc/init.d/rsyncd stop
Start Rsync service[873]                                   [  OK  ]


[[email protected] ~]# /etc/init.d/rsyncd start
Start Rsync service[873]                                   [  OK  ]


[[email protected] ~]# /etc/init.d/rsyncd restart
Start Rsync service[873]                                   [  OK  ]
Start Rsync service[873]                                   [  OK  ]


[[email protected] ~]# netstat -lntup|grep rsync
tcp   0   0 0.0.0.0:873    0.0.0.0:*    LISTEN      2396/rsync         
tcp   0   0 :::873         :::*         LISTEN      2396/rsync

猜你喜欢

转载自blog.51cto.com/11576296/2349216
0条评论
添加一条新回复