我是靠谱客的博主 高高寒风,最近开发中收集的这篇文章主要介绍ubuntu 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
. /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
                  

最后

以上就是高高寒风为你收集整理的ubuntu haproxy 服务启动脚本的全部内容,希望文章能够帮你解决ubuntu haproxy 服务启动脚本所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部