Haproxy init启动脚本

[root@www80 ~]# cat /etc/init.d/haproxy   

#!/bin/sh

#

# chkconfig: - 85 15

# description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \

#              for high availability environments.

# processname: haproxy

# config: /etc/haproxy/haproxy.cfg

# pidfile: /var/run/haproxy.pid


# Script Author: Simon Matter <simon.matter@invoca.ch>

# Version: 2004060600

# Source function library.

if [ -f /etc/init.d/functions ]; then

  . /etc/init.d/functions

elif [ -f /etc/rc.d/init.d/functions ] ; then

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

else

  exit 0

fi

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

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


HAPROXYDIR=/usr/local/haproxy

BASENAME=haproxy


# This is our service name

#BASENAME=`basename $0`

#if [ -L $0 ]; then

#  BASENAME=`find $0 -name $BASENAME -printf %l`

#  BASENAME=`basename $BASENAME`

#fi

[ -f $HAPROXYDIR/etc/$BASENAME.cfg ] || exit 1


RETVAL=0

start() {

  $HAPROXYDIR/sbin/$BASENAME -c -q -f $HAPROXYDIR/etc/$BASENAME.cfg

  if [ $? -ne 0 ]; then

    echo "Errors found in configuration file, check it with '$BASENAME check'."

    return 1

  fi

  echo -n "Starting $BASENAME: "

  daemon $HAPROXYDIR/sbin/$BASENAME -D -f $HAPROXYDIR/etc/$BASENAME.cfg -p /var/run/$BASENAME.pid

  RETVAL=$?

  echo

  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASENAME

  return $RETVAL

}

 
stop() {

  echo -n "Shutting down $BASENAME: "

  killproc $BASENAME -USR1

  RETVAL=$?

  echo

  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BASENAME

  [ $RETVAL -eq 0 ] && rm -f /var/run/$BASENAME.pid

  return $RETVAL

}

restart() {

  $HAPROXYDIR/sbin/$BASENAME -c -q -f $HAPROXYDIR/etc/$BASENAME.cfg

  if [ $? -ne 0 ]; then

    echo "Errors found in configuration file, check it with '$BASENAME check'."

    return 1

  fi

  stop

  start

}

reload() {

  $HAPROXYDIR/sbin/$BASENAME -c -q -f $HAPROXYDIR/etc/$BASENAME.cfg

  if [ $? -ne 0 ]; then

    echo "Errors found in configuration file, check it with '$BASENAME check'."

    return 1

  fi

  $HAPROXYDIR/sbin/$BASENAME -D -f $HAPROXYDIR/etc/$BASENAME.cfg -p /var/run/$BASENAME.pid -sf $(cat /var/run/$BASENAME.pid)

}

check() {

  $HAPROXYDIR/sbin/$BASENAME -c -q -V -f $HAPROXYDIR/etc/$BASENAME.cfg

}

rhstatus() {

  status $BASENAME

}

condrestart() {

  [ -e /var/lock/subsys/$BASENAME ] && restart || :

}

# See how we were called.

case "$1" in

  start)

    start

    ;;

  stop)

    stop

    ;;

  restart)

    restart

    ;;

  reload)

    reload

    ;;

  condrestart)

    condrestart

    ;;

  status)

    rhstatus

    ;;

  check)

    check

    ;;

  *)

    echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status|check}"

    exit 1

esac

exit $?

转载于:https://my.oschina.net/u/1433006/blog/1580509

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值