Chinaunix首页 | 论坛 | 博客
  • 博客访问: 245360
  • 博文数量: 188
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -30
  • 用 户 组: 普通用户
  • 注册时间: 2017-03-29 11:17
文章分类
文章存档

2013年(8)

2012年(5)

2011年(13)

2010年(26)

2009年(63)

2008年(20)

2007年(32)

2006年(21)

分类: 系统运维

2013-07-11 15:09:20


点击(此处)折叠或打开

  1. # haproxy
  2. #
  3. # chkconfig: 35 85 15
  4. # description: HAProxy is a free, very fast and reliable solution
  5. # offering high availability, load balancing, and
  6. # proxying for TCP and HTTP-based applications
  7. # processname: haproxy
  8. # config: /usr/local/haproxy/conf/haproxy.cfg
  9. # pidfile: /var/run/haproxy.pid

  10. # Source function library.
  11. . /etc/rc.d/init.d/functions

  12. # Source networking configuration.
  13. . /etc/sysconfig/network

  14. # Check that networking is up.
  15. [ "$NETWORKING" = "no" ] && exit 0

  16. config="/usr/local/haproxy/haproxy.conf"
  17. exec="/usr/local/haproxy/sbin/haproxy"
  18. prog="haproxy"
  19. pidfile="/var/run/haproxy.pid"
  20. [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

  21. lockfile=/var/lock/subsys/haproxy

  22. check() {
  23.     $exec -c -f $config
  24. }

  25. start() {
  26.     if [ -e $pidfile ];then
  27.     echo "haproxy already running...."
  28.     exit 1
  29.     fi

  30.     $exec -q -c -f $config
  31.     if [ $? -ne 0 ]; then
  32.         echo "Errors in configuration file, check with $prog check."
  33.         return 1
  34.     fi
  35.     echo -n $"Starting $prog: "
  36.     daemon $exec -q -D -f $config -p $pidfile 2> /dev/null
  37.     retval=$?
  38.     echo
  39.     [ $retval -eq 0 ] && touch $lockfile
  40.     return $retval
  41. }

  42. stop() {
  43.     echo -n $"Stopping $prog: "
  44.    # kill -TTOU $(cat $pidfile)
  45.    # kill -USR1 $(cat $pidfile)
  46.     killproc $prog -USR1 2> /dev/null && killall haproxy 2> /dev/null
  47.     retval=$?
  48.     echo
  49.     [ $retval -eq 0 ] && rm -f $pidfile
  50.     [ $retval -eq 0 ] && rm -f $lockfile
  51.     return $retval
  52. }

  53. restart() {
  54.     $exec -q -c -f $config
  55.     if [ $? -ne 0 ]; then
  56.         echo "Errors in configuration file, check with $prog check."
  57.         return 1
  58.     fi
  59.     stop
  60.     start
  61. }

  62. reload() {
  63.     $exec -q -c -f $config
  64.     if [ $? -ne 0 ]; then
  65.         echo "Errors in configuration file, check with $prog check."
  66.         return 1
  67.     fi
  68.     echo -n $"Reloading $prog: "
  69.     $exec -q -D -f $config -p $pidfile -sf $(cat $pidfile)
  70.     retval=$?
  71.     echo
  72.     return $retval
  73. }

  74. force_reload() {
  75.     restart
  76. }

  77. fdr_status() {
  78.     status $prog
  79. }

  80. case "$1" in
  81.     start|stop|restart|reload)
  82.         $1
  83.         ;;
  84.     force-reload)
  85.         force_reload
  86.         ;;
  87.     checkconfig)
  88.         check
  89.         ;;
  90.     status)
  91.         fdr_status
  92.         ;;
  93.     condrestart|try-restart)
  94.         [ ! -f $lockfile ] || restart
  95.         ;;
  96.     *)
  97.         echo $"Usage: $0 {start|stop|status|checkconfig|restart|try-restart|reload|force-reload}"
  98.         exit 2
  99. esa


阅读(2642) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~