#!/bin/sh
cpu=`cat /proc/loadavg | awk '{print int($1)}'`
#echo cpu负载：$cpu

v2=`service v2ray status | grep "running"`
#echo $v2

if [[ "$v2" != "" ]]
then
	#echo "running"
	if [ $cpu -ge 2 ]
	then
		echo 正在停止v2ray 当前负载：$cpu `date +"%Y-%m-%d %H:%M:%S"`
		service v2ray stop
	fi
else
	#echo "dead"
	if [ $cpu -le 2 ]
	then
		echo 正在重启v2ray 当前负载：$cpu `date +"%Y-%m-%d %H:%M:%S"`
		service v2ray restart
	fi
fi
#date +"%Y-%m-%d %H:%M:%S"
