Ticket #670: second.sh.txt

File second.sh.txt, 2.0 KB (added by chris, 3 years ago)

/var/xdrago/second.sh

Line 
1#!/bin/bash
2
3SHELL=/bin/bash
4PATH=/usr/local/sbin:/usr/local/bin:/opt/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
5
6hold()
7{
8  /etc/init.d/nginx stop
9  killall -9 nginx
10  sleep 1
11  killall -9 nginx
12  /etc/init.d/php-fpm stop
13  /etc/init.d/php53-fpm stop
14  killall -9 php-fpm php-cgi
15  echo load is $ONEX_LOAD:$FIVX_LOAD while maxload is $CTL_ONEX_LOAD:$CTL_FIVX_LOAD
16}
17
18terminate()
19{
20  if [ -e "/var/run/boa_run.pid" ] ; then
21    sleep 1
22  else
23    killall -9 php drush.php wget
24  fi
25}
26
27nginx_high_load_on()
28{
29  mv -f /data/conf/nginx_high_load_off.conf /data/conf/nginx_high_load.conf
30  /etc/init.d/nginx reload
31}
32
33nginx_high_load_off()
34{
35  mv -f /data/conf/nginx_high_load.conf /data/conf/nginx_high_load_off.conf
36  /etc/init.d/nginx reload
37}
38
39control()
40{
41ONEX_LOAD=`awk '{print $1*100}' /proc/loadavg`
42FIVX_LOAD=`awk '{print $2*100}' /proc/loadavg`
43CTL_ONEX_SPIDER_LOAD=2716
44CTL_FIVX_SPIDER_LOAD=2716
45CTL_ONEX_LOAD=10108
46CTL_FIVX_LOAD=6216
47CTL_ONEX_LOAD_CRIT=13216
48CTL_FIVX_LOAD_CRIT=10885
49if [ $ONEX_LOAD -ge $CTL_ONEX_SPIDER_LOAD ] && [ $ONEX_LOAD -lt $CTL_ONEX_LOAD ] && [ -e "/data/conf/nginx_high_load_off.conf" ] ; then
50  nginx_high_load_on
51elif [ $FIVX_LOAD -ge $CTL_FIVX_SPIDER_LOAD ] && [ $FIVX_LOAD -lt $CTL_FIVX_LOAD ] && [ -e "/data/conf/nginx_high_load_off.conf" ] ; then
52  nginx_high_load_on
53elif [ $ONEX_LOAD -lt $CTL_ONEX_SPIDER_LOAD ] && [ $FIVX_LOAD -lt $CTL_FIVX_SPIDER_LOAD ] && [ -e "/data/conf/nginx_high_load.conf" ] ; then
54  nginx_high_load_off
55fi
56if [ $ONEX_LOAD -ge $CTL_ONEX_LOAD_CRIT ] ; then
57  terminate
58elif [ $FIVX_LOAD -ge $CTL_FIVX_LOAD_CRIT ] ; then
59  terminate
60fi
61if [ $ONEX_LOAD -ge $CTL_ONEX_LOAD ] ; then
62  hold
63elif [ $FIVX_LOAD -ge $CTL_FIVX_LOAD ] ; then
64  hold
65else
66  echo load is $ONEX_LOAD:$FIVX_LOAD while maxload is $CTL_ONEX_LOAD:$CTL_FIVX_LOAD
67  echo ...OK now doing CTL...
68  perl /var/xdrago/proc_num_ctrl.cgi
69  touch /var/xdrago/log/proc_num_ctrl.done
70  echo CTL done
71fi
72}
73
74control
75sleep 10
76control
77sleep 10
78control
79sleep 10
80control
81sleep 10
82control
83sleep 10
84control
85echo Done !
86###EOF2013###