varnish启动脚本

发布时间:2020-04-17编辑:脚本学堂
varnish启动脚本

varnish启动脚本,感兴趣的朋友可以参考下。
 

复制代码 代码如下:

#!/bin/bash
if [ -z $1 ];then
echo "请输入参数"
exit
fi

check_ver() {
echo $1 | grep -Eq '[0-9]{14}$'
if [ $? -ne 0 ];then
echo "请输入正确的参数版本号"
exit
fi
}

varnish_id=$(date +%Y%m%d%H%M%S)
varnish="/usr/local/varnish/sbin/varnishd"
varnishadm="/usr/local/varnish/bin/varnishadm"
prog=$(basename $varnish)
VARNISH_CONF_FILE="/home/www/config/varnish/aifang.vcl"
PID=$(pgrep varnish)
start_jobs() {
$varnish
-u evans
-g www-data
-a :30080
-f $VARNISH_CONF_FILE
-T 0.0.0.0:8800
-s malloc,2G
-w 50,51200,10
-p thread_pool_min=200
-p thread_pool_max=4000
-p thread_pools=4
-p listen_depth=4096
-p lru_interval=86400
}

start_check() {
[ -x $varnish ] || exit 5
[ -f $VARNISH_CONF_FILE ] || exit 6
if [ -z "$PID" ];then
echo $"Starting $prog: OK"
start_jobs
fi
}

stop_check() {
[ -x $varnish ] || exit 5
[ -f $VARNISH_CONF_FILE ] || exit 6
if [ -z "$PID" ];then
echo $"$prog not running"
else
kill -9 $(pgrep varnish)
if [ $? -eq 0 ];then
echo $"Stopping $prog: OK"
else
echo $"Stopping $prog Fail: "
fi
fi
}


check_reload(){
[ -x $varnishadm ] || exit 5
[ -f $VARNISH_CONF_FILE ] || exit 6
if [ -z "$PID" ];then
echo $"$prog not running"
else
$varnishadm -T localhost:8800 vcl.load $varnish_id $VARNISH_CONF_FILE
if [ $? -eq 0 ];then
$varnishadm -T localhost:8800 vcl.use $varnish_id
echo $"Check $prog : OK "
else
echo $"Check $prog Fail: "
fi
fi

}

check_list() {
if [ -z "$PID" ];then
echo $"$prog not running"
else
$varnishadm -T localhost:8800 vcl.list
fi
}

check_reback() {
check_ver $1
if [ $? -eq 0 ];then
if [ -z "$PID" ];then
echo $"$prog not running"
else
$varnishadm -T localhost:8800 vcl.use $1
fi
echo $"$prog Version Back $1"
fi
}

case "$1" in
start)
start_check && exit 0
$1
;;
stop)
stop_check && exit 0
$1
;;
reload)
check_reload && exit 7
$1
;;
list)
check_list && exit 0
$1
;;
reback)
check_reback $2 && exit 0
$1
;;
*)
echo $"Usage: $0 {start|stop|reload|list|reback}"
exit 2
esac