ubuntu haproxy 服务启动脚本

这是一个用于在Ubuntu上启动HAProxy服务的脚本。它检查配置文件、启动、停止、重启和重新加载HAProxy服务,并确保在配置文件有误时提供检查功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#!/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
. /lib/lsb/init-functions
   # Source networking configuration.
#    . /etc/sysconfig/network
#/run/network 
   # Check that networking is up.
    [ "$NETWORKING" = "no" ] && exit 0
    config="/etc/haproxy/haproxy.cfg"
    exec="/usr/local/haproxy/sbin/haproxy"
    prog=$(basename $exec)
    [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
    lockfile=/run/lock/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"
        start-stop-daemon --quiet --oknodo --start --pidfile /var/run/"$prog.pid"  \
--exec "$exec" -- -f "$config"  -D -p /var/run/"$prog.pid" || return 2
        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
                  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值