开发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
fi3、对启动脚本进行测试
[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/rsync4、设置为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]#
本文出自 “福州恒达电脑” 博客,请务必保留此出处http://fzhddn.blog.51cto.com/12650899/1944984
原文:http://fzhddn.blog.51cto.com/12650899/1944984