[root@m01 init.d]# vim rsyncd.sh
#!/bin/bash
# chkconfig: 2345 99 98
#author:oldyang
choice=$1
STOP=/var/run/rsyncd.pid
start(){
[ -f $STOP ] || rsync --daemon
}
stop(){
[ -f $STOP ] && kill `cat /var/run/rsyncd.pid`
}
restart(){
[ -f $STOP ] && kill `cat /var/run/rsyncd.pid`
}
case "$choice" in
start)
start
;;
stop)
stop
;;
restart)
restart
sleep 1
rsync --daemon
;;
*)
echo "Usage: input right CMD. EX: {start|restart|stop}"
exit 1
esac
测试脚本
[root@m01 init.d]# sh rsyncd.sh start
[root@m01 init.d]# ss -lntup|grep rsync
tcp LISTEN 0 5 *:873 *:* users:(("rsync",pid=17562,fd=3))
tcp LISTEN 0 5 :::873 :::* users:(("rsync",pid=17562,fd=5))
[root@m01 init.d]# sh rsyncd.sh stop
[root@m01 init.d]# ss -lntup|grep rsync
[root@m01 init.d]# sh rsyncd.sh restart
[root@m01 init.d]# ss -lntup|grep rsync
tcp LISTEN 0 5 *:873 *:* users:(("rsync",pid=17577,fd=3))
tcp LISTEN 0 5 :::873 :::* users:(("rsync",pid=17577,fd=5))
[root@m01 init.d]# sh rsyncd.sh stop
[root@m01 init.d]# ss -lntup|grep rsync
来源:CSDN
作者:艺妓与酒
链接:https://blog.csdn.net/xiaobaiqifei/article/details/104010855