Linux学习-postfix服务启动脚本

基于CentOS6的postfix服务启动脚本

#创建服务启动脚本
[root@lotus ~]# vim /etc/rc.d/init.d/postfix

#!/bin/bash
#
# postfix postfix Mail Transfer Agent
#
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transfer 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 network configuration
. /etc/sysconfig/network

# check that networking is up.
[ $NETWORKING = "no" ] && exit 3

[ -x /usr/sbin/postfix ] || exit 4
[ -d /etc/postfix ] || exit 5
[ -d /var/spool/postfix ] || exit 6

RETVAL=0
prog="postfix"

start() {
# start daemons.
 echo -n $"Starting postfix"
 /usr/bin/newaliases >/dev/null 2&>1
 /usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
 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 $"$prog stop"
 RETVAL=$?
 [ $RETVAL -eq 0 ] && rm -rf /var/lock/subsys/postfix
 echo
 return $RETVAL
}

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

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

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

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

restart() {
 stop
 start
}

case $1 in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        restart
        ;;
    reload)
        reload
        ;;
    abort)
        abort
        ;;
    flush)
        flush
        ;;
    check)
        check
        ;;
    status)
        status master
        ;;
    condrestart)
        [ -f /var/lock/subsys/postfix ] && restart || :
        ;;
    *)
        echo $"Usage:$0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
        exit 1
esac
exit $?
# END

#给文件添加执行权限
[root@lotus ~]# chmod +x /etc/init.d/postfix
#加入服务启动列表
[root@lotus ~]# chkconfig --add postfix
[root@lotus ~]# chkconfig --list postfix
postfix        	0:off	1:off	2:on	3:on	4:on	5:on	6:off
#测试启动服务
[root@lotus ~]# service postfix start
Starting postfix                                           [  OK  ]
#测试重启服务
[root@lotus ~]# service postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix                                           [  OK  ]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值