開發rsync服務的啓動腳本

開發rsync服務的啓動腳本


1、查看rsync軟件包是否安裝:

[root@sxun scripts]# rpm -qa rsync
rsync-3.0.6-9.el6_4.1.x86_64
[root@sxun scripts]# touch /etc/rsyncd.conf
[root@sxun scripts]# rsync --daemon
[root@sxun scripts]# netstat -lntup |grep 873
tcp        0      0 0.0.0.0:873                 0.0.0.0:*                   LISTEN      31908/rsync         
tcp        0      0 :::873                      :::*                        LISTEN      31908/rsync         
[root@sxun scripts]# pkill rsync


2、開發rsync服務的啓動腳本:

[root@sxun scripts]# vi rsyncd.sh
[root@sxun scripts]# cat /etc/init.d/rsyncd 
#!/bin/bash
# chkconfig:2345 20 80
#description:Rsyncd Startup scripts by fzhddn.
if [ $# -ne 1 ]
  then
    echo $"usage:$0 {start|stop|restart}"
    exit 1
fi
if [ "$1" = "start" ]
  then
    rsync --daemon
    sleep 2
    if [ `netstat -lntup|grep rsync|wc -l` -ge 1 ]
      then
        echo "resyncd is started."
        exit 0
    fi
elif [ "$1" = "stop" ]
  then
    killall rsync &>/dev/null
    sleep 2
    if [ `netstat -lntup|grep rsync|wc -l` -eq 0 ]
      then
        echo "rsyncd is stopped."
        exit 0
    fi  
elif [ "$1" = "restart" ]
  then
    killall rsync
    sleep 1
    killpro=`netstat -lntup|grep rsync|wc -l`
    rsync --daemon
    sleep 1
    startpro=`netstat -lntup|grep rsync|wc -l`
    if [ $killpro -eq 0 -a $startpro -ge 1 ]
      then
        echo "rsyncd is restarted."
        exit 0
    fi
else
  echo $"usage:$0 {start|stop|restart}"
  exit 1
fi

3、對啓動腳本進行測試

[root@sxun scripts]# sh rsyncd.sh 
usage:rsyncd.sh {start|stop|restart}
[root@sxun scripts]# sh rsyncd.sh start
resyncd is started.
[root@sxun scripts]# sh rsyncd.sh restart
rsyncd is restarted.
[root@sxun scripts]# sh rsyncd.sh stop
rsyncd is stopped.
[root@sxun scripts]# sh rsyncd.sh start
resyncd is started.
[root@sxun scripts]# netstat -tlnup |grep 873
tcp        0      0 0.0.0.0:873                 0.0.0.0:*                   LISTEN      16073/rsync         
tcp        0      0 :::873                      :::*                        LISTEN      16073/rsync

4、設置爲rsync服務,開機自啓動

[root@sxun scripts]# cp rsyncd.sh /etc/init.d/rsyncd
[root@sxun scripts]# chmod +x /etc/init.d/rsyncd 
[root@sxun scripts]# chkconfig --list rsyncd
service rsyncd supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add rsyncd')
[root@sxun scripts]# chkconfig --add rsyncd
[root@sxun scripts]# chkconfig --list rsyncd
rsyncd         0:off1:off2:on3:on4:on5:on6:off
[root@sxun scripts]#


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章