rsyncd启动脚本

 

 

#!/bin/bash
##############################################################
# File Name: 05-05.sh
# Version: V1.0
# Author: guojintao
# Organization: https://www.cnblogs.com/guojintao/
# Created Time : 2018-12-12 23:25:55
# Description:
##############################################################
. /etc/init.d/functions
RETVAL=0
prog="rsyncd"
rsyncd=/usr/bin/rsync
pid_file=/var/run/rsyncd.pid
lockfile=/var/lock/subsys/$prog
conf_file=/etc/rsyncd.conf

if [ -f $conf_file ];then
    grep "pid file=$pid_file" $conf_file |grep -v "^#" >/dev/null || { 
     action "pid file undefined in $conf_file" /bin/false
     exit 2 
    }   
else
    action "$conf_file not exist" /bin/false
    exit 3
fi
start(){
    echo -n $"Starting $prog: "
    rsync --daemon && success || failure
    RETVAL=$?
    [ $RETVAL -eq 0 ] && touch $lockfile
    echo
    return $RETVAL
}
stop(){
    echo -n $"Stopping $prog: "
    killproc -p $pid_file $rsyncd
    RETVAL=$?
    [ $RETVAL -eq 0 ] && rm -f $lockfile
    echo
}
rh_status() {
        status -p $pid_file rsyncd
}
rh_status_q() {
        rh_status >/dev/null 2>&1
}
case "$1" in 
    "start")
        rh_status_q && exit 0
        start
        ;;
    "stop")
        if ! rh_status_q; then
            rm -f $lockfile
            exit 0
        fi
        stop
        ;;
    "status")
        rh_status
        RETVAL=$?
        if [ $RETVAL -eq 3 -a -f $lockfile ] ; then
            RETVAL=2
        fi
        ;;
    "restart")
        stop
        start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        RETVAL=2
esac
exit $RETVAL

 

posted @ 2018-12-13 21:26  狂奔__蜗牛  阅读(372)  评论(0)    收藏  举报
levels of contents