您的位置:首页 > 运维架构 > Linux

linux系统服务rsync启动脚本

2014-06-02 16:16 489 查看
本脚本估计存在一些问题:如有发现,请告知谢谢~
#!/bin/sh
# chkconfig: 2345 21 60
# description: Saves and restores system entropy pool for \
#create by xiaohu
#2014.06.02
#This script is the Rsync service script
. /etc/init.d/functions
case "$1" in
start)
echo "rsync is starting"
rsync --daemon
sleep 2
myport=`netstat -lnt|grep 873|wc -l`
if [ $myport -eq 2 ]
then
action "rsync start"   /bin/true
else
action "rsync start"   /bin/false
fi
;;
stop)
echo "rsync is stoping"
myport=`netstat -lnt|grep 873|wc -l`
if [ $myport -eq 2 ]
then
killall rsync &>/dev/null
sleep 2
killall rsync &>/dev/null
sleep 1
fi
myport=`netstat -lnt|grep 873|wc -l`
if [ $myport -ne 2 ]
then
action "rsync stop"   /bin/true
else
action "rsync stop"   /bin/false
fi
;;
restart)
if [ `netstat -lnt|grep 873|wc -l` -eq 0 ]
then
rsync --daemon
sleep 2
myport=`netstat -lnt|grep 873|wc -l`
if [ $myport -eq 2 ]
then
action "rsync restart"   /bin/true
else
action "rsync restart"   /bin/false
exit
fi
else
killall rsync &>/dev/null
sleep 2
killall rsync &>/dev/null
sleep 1
rsync --daemon
sleep 2
myport=`netstat -lnt|grep 873|wc -l`
if [ $myport -eq 2 ]
then
action "rsync restart"   /bin/true
else
action "rsync restart"   /bin/false
fi
fi
;;
status)
myport=`netstat -lnt|grep 873|wc -l`
if [ $myport -eq 2 ]
then
echo  "rsync is running"
else
echo "rsync is stoped"
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
;;
esac
在stop参数中,不建议采用pkill或看kill,尤其是数据库方面,容易让服务出现问题。

本文出自 “Alan wake” 博客,请务必保留此出处http://alanwake.blog.51cto.com/6881848/1421188
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: