○ postfix起動スクリプト

*postfix-2.7.1を自動起動するスクリプトです
*CentOSのpostfix起動スクリプトを参考にしています
紫色文字 db作成用ファイルが存在した場合に、dbを作ります
*完全コピーしないこと (エラーが出ることあり)

*"#" で始まる行はコメントとして解釈され、"$" の付いた文字は変数を表します
*スクリプトの先頭で, 処理を行うシェルを明示します (#!/bin/bash)
*# chkconfig: の#のあとに半角スペース
*# description: の#のあとに半角スペース
*. /  . はファイルを読み込むコマンド 後に半角スペース
*[ ] はテストコマンドです 半角スペースを忘れないように
*[ = ] テストコマンド内は = の前後に半角スペース
*環境変数等価式=の場合、前後に半角スペースをいれない
*A && B Aが正ならばBを実効
*A || B Aが為ならばBを実効
*$0 はスクリプト本体 $1は 第1引数

○/etc/rc.d/init.d/postfix

#!/bin/bash
#
# postfix      Postfix Mail Transfer Agent
#
# chkconfig: 235 80 30
# description: Postfix is a Mail Transport Agent, which is the program \
#              that moves mail from one machine to another.
# processname: master
# pidfile: /var/spool/postfix/pid/master.pid
# config: /etc/postfix/main.cf
# config: /etc/postfix/master.cf

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

[ -x /usr/sbin/postfix ] || exit 0
[ -d /etc/postfix ] || exit 0
[ -d /var/spool/postfix ] || exit 0

RETVAL=0

start() {
    # Start daemons.
    echo -n "Starting postfix: "
    /usr/bin/newaliases
    for i in access canonical relocated transport virtual
    do
    if [ -f /etc/postfix/$i ] ; then
        /usr/sbin/postmap hash:/etc/postfix/$i < /etc/postfix/$i
    fi
    done
    /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure
    RETVAL=$?
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
        echo
    return $RETVAL
}

stop() {
    # Stop daemons.
    echo -n "Shutting down postfix: "
    /usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure
    RETVAL=$?
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
    echo
    return $RETVAL
}

reload() {
    echo -n "Reloading postfix: "
    /usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure
    RETVAL=$?
    echo
    return $RETVAL
}

abort() {
    /usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure
    return $?
}

flush() {
    /usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure
    return $?
}

check() {
    /usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure
    return $?
}

restart() {
    stop
    start
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    reload)
        reload
        ;;
    abort)
        abort
        ;;
    flush)
        flush
        ;;
    check)
        check
        ;;
    status)
        status master
        ;;
    condrestart)
        [ -f /var/lock/subsys/postfix ] && restart || :
        ;;
    *)
        echo "Usage: postfix \
        {start|stop|restart|reload|abort|flush|check|status|condrestart}"
    exit 1
esac

exit $?

postfix

○ Copyright(c) 528p.com All Rights Reserved.