前言
也不知道这个脚本原形是谁的,自己拿来做了简单的修改,使用起来更为人性化吧。反正只是个小脚本,拿里用着不爽再做修改呗!不喜勿喷,既然有好的模板,就好好利用吧。O(∩_∩)O哈哈~,欢迎大家拿去使用,有不足的地方大家可以提出来,当然自己修改就是了。
脚本
[root@server ~]# cat /etc/init.d/rsyncd #!/bin/bash # # rsyncd This shell script takes care of starting and stopping # standalone rsync. # # chkconfig: - 99 50 # description: rsync is a file transport daemon # processname: rsync # config: /etc/rsyncd.conf # Source function library . /etc/init.d/functions RETVAL=0 rsync="/usr/bin/rsync" prog="rsync" CFILE="/etc/rsyncd.conf" start() { # Start daemons. [ -x $rsync ] || \ { echo "FATAL: No such programme";exit 4; } [ -f $CFILE ] || \ { echo "FATAL: $CFILE file does not exist";exit 6; } [ -f /var/lock/subsys/$prog ]&& \ { status $prog;RETVAL=$?;exit;} echo -n $"Starting $prog: " daemon $rsync --daemon RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog echo return $RETVAL } stop() { # Stop daemons. [ -f /var/lock/subsys/$prog ] || \ { status $prog;RETVAL=$?;exit;} echo -n $"Stopping $prog: " killproc $prog -QUIT RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog return $RETVAL } # call the function we defined case "$1" in start) start ;; stop) stop ;; restart|reload) stop start RETVAL=$? ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|reload|status}" exit 2 esac exit $RETVAL
脚本效果
启动停止
[root@server ~]# /etc/init.d/rsyncd Usage: /etc/init.d/rsyncd {start|stop|restart|reload|status} [root@server ~]# /etc/init.d/rsyncd status rsync (pid 2203) is running... [root@server ~]# /etc/init.d/rsyncd stop Stopping rsync: [ OK ] [root@server ~]# /etc/init.d/rsyncd status rsync is stopped [root@server ~]# /etc/init.d/rsyncd start Starting rsync: [ OK ] [root@server ~]# /etc/init.d/rsyncd status rsync (pid 2336) is running... [root@server ~]# /etc/init.d/rsyncd start rsync (pid 2336) is running... [root@server ~]# /etc/init.d/rsyncd stop Stopping rsync: [ OK ] [root@server ~]# /etc/init.d/rsyncd status rsync is stopped [root@server ~]# /etc/init.d/rsyncd stop rsync is stopped [root@server ~]# /etc/init.d/rsyncd start Starting rsync: [ OK ] [root@server ~]# /etc/init.d/rsyncd restart Stopping rsync: [ OK ] Starting rsync: [ OK ] [root@server ~]# /etc/init.d/rsyncd reload Stopping rsync: [ OK ] Starting rsync: [ OK ] [root@server ~]# lsof -i:873 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME rsync 2397 root 4u IPv4 15419 0t0 TCP *:rsync (LISTEN) rsync 2397 root 5u IPv6 15420 0t0 TCP *:rsync (LISTEN)
2. 添加开机自启动
[root@server ~]# chkconfig --list|grep rsyncd [root@server ~]# chkconfig rsyncd on [root@server ~]# chkconfig --list|grep rsyncd rsyncd 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@server ~]# find /etc/rc.d/ -name *rsyncd /etc/rc.d/rc3.d/S99rsyncd /etc/rc.d/init.d/rsyncd /etc/rc.d/rc4.d/S99rsyncd /etc/rc.d/rc2.d/S99rsyncd /etc/rc.d/rc5.d/S99rsyncd [root@server ~]# chkconfig rsyncd --level 5 off [root@server ~]# find /etc/rc.d/ -name *rsyncd /etc/rc.d/rc3.d/S99rsyncd /etc/rc.d/init.d/rsyncd /etc/rc.d/rc4.d/S99rsyncd /etc/rc.d/rc2.d/S99rsyncd /etc/rc.d/rc5.d/K50rsyncd