码迷,mamicode.com
首页 > 其他好文 > 详细

创建haproxy启动脚本

时间:2016-02-11 06:48:42      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:haproxy

vim /etc/init.d/haproxy

#!/bin/bash

#

# haproxy

#

# chkconfig: 35 85 15

# description: HAProxy is a free, very fast and reliable solution \

# offering high availability, load balancing, and \

# proxying for TCP and HTTP-based applications

# processname: haproxy

# config: /etc/haproxy.cfg

# pidfile: /var/run/haproxy.pid


# Source function library.

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


# Source networking configuration.

. /etc/sysconfig/network


# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0


config="/etc/haproxy.cfg"

exec="/usr/local/haproxy/sbin/haproxy"

prog=$(basename $exec)


[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog


lockfile=/var/lock/subsys/haproxy


check() {

    $exec -c -V -f $config

}


start() {

    $exec -c -q -f $config

    if [ $? -ne 0 ]; then

        echo "Errors in configuration file, check with $prog check."

        return 1

    fi

 

    echo -n $"Starting $prog: "

    # start it up here, usually something like "daemon $exec"

    daemon $exec -D -f $config -p /var/run/$prog.pid

    retval=$?

    echo

    [ $retval -eq 0 ] && touch $lockfile

    return $retval

}


stop() {

    echo -n $"Stopping $prog: "

    # stop it here, often "killproc $prog"

    killproc $prog 

    retval=$?

    echo

    [ $retval -eq 0 ] && rm -f $lockfile

    return $retval

}


restart() {

    $exec -c -q -f $config

    if [ $? -ne 0 ]; then

        echo "Errors in configuration file, check with $prog check."

        return 1

    fi

    stop

    start

}


reload() {

    $exec -c -q -f $config

    if [ $? -ne 0 ]; then

        echo "Errors in configuration file, check with $prog check."

        return 1

    fi

    echo -n $"Reloading $prog: "

    $exec -D -f $config -p /var/run/$prog.pid -sf $(cat /var/run/$prog.pid)

    retval=$?

    echo

    return $retval

}


force_reload() {

    restart

}


fdr_status() {

    status $prog

}


case "$1" in

    start|stop|restart|reload)

        $1

        ;;

    force-reload)

        force_reload

        ;;

    checkconfig)

        check

        ;;

    status)

        fdr_status

        ;;

    condrestart|try-restart)

      [ ! -f $lockfile ] || restart

    ;;

    *)

        echo $"Usage: $0 {start|stop|status|checkconfig|restart|try-restart|reload|force-reload}"

        exit 2

esac


本文出自 “我的运维时光” 博客,请务必保留此出处http://aaronsa.blog.51cto.com/5157083/1741519

创建haproxy启动脚本

标签:haproxy

原文地址:http://aaronsa.blog.51cto.com/5157083/1741519

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!