Rsyncd的Linux服务文件写法

Rsyncd的Linux服务文件写法

#! /bin/sh

# rsynctools init file for rsyncd

# Copyright (C) 2002-4 Zhang Hui<zhangh@oec-h.com>

# $Id$

# For RedHat and cousins:

# chkconfig: – 99 01

# description: Self Monitoring and Reporting RSYNC Daemon

# processname: rsync

### BEGIN INIT INFO

# Provides: rsync

# Required-Start: $local_fs $network

# Required-Stop: $local_fs $network

# Should-Start:

# Default-Start:

# Default-Stop: 0 1 2 3 4 5 6

# Short-Description: Self Monitoring and Reporting Technology (SMART) Daemon

# Description: The smartd daemon monitors SMART status of the local hard drives and

#   provides advanced warnings of of disk degradation or failures.

### END INIT INFO

# Uncomment the line below to pass options to smartd on startup.

rsyncd_opts=”–daemon –config=/etc/rsyncd.conf”

RSYNCD_BIN=/usr/bin/rsync

# Source function library

. /etc/rc.d/init.d/functions

RETVAL=0

prog=rsyncd

pidfile=/var/lock/subsys/rsyncd

lockfile=/var/run/rsyncd.lock

logfile=/var/log/rsyncd.log

config=/etc/rsyncd.conf

start()

{

        if [ -e $lockfile ]; then //如果锁文件存在,就提示rsyncd正在运行

                echo -n $”$prog is running…”

                echo

                return $RETVAL

        else //如果不存在就正常启动rsyncd

                [ $UID -eq 0 ] || exit 4

                [ -x $RSYNC_BIN ] || exit 5

                [ -f $config ] || exit 6

                echo -n $”Starting $prog: “

                daemon $RSYNCD_BIN $rsyncd_opts

                RETVAL=$?

                echo

                [ $RETVAL = 0 ] && touch $pidfile && touch $lockfile

                return $RETVAL

        fi

}

stop()

{

        [ $UID -eq 0 ] || exit 4

        echo -n $”Shutting down $prog: “

        killproc $RSYNCD_BIN

        RETVAL=$?

        echo

        rm -f $pidfile //删除pid文件

        rm -f $lockfile //删除lock文件

        return $RETVAL

}

reload()

{

        echo -n $”Reloading $prog daemon configuration: “

        killproc $RSYNCD_BIN -HUP

        RETVAL=$?

        echo

        return $RETVAL

}

case “$1” in

        start)

                start

                ;;

        stop)

                stop

                ;;

        reload)

                reload

                ;;

        restart)

                stop

                start

                ;;

        status)

                status $prog

                RETVAL=$?

                ;;

        *)

                echo $”Usage: $0 {start|stop|restart|status|reload}”

                RETVAL=2

                [ “$1” = ‘usage’ ] && RETVAL=0

esac

exit $RETVAL

保存完退出

chmod +x /etc/init.d/rsyncd

chkconfig –add rsyncd //>将 rsyncd>加入服务列表

chkconifg rsyncd on //>将 rsyncd>服务设置为随重启自动运行