Rootop 服务器运维与web架构

varnish启动关闭脚本

| 暂无评论

#!/bin/bash
varnish_pid=/tmp/varnish.pid
v_command="/usr/local/varnish/sbin/varnishd -a 0.0.0.0:80 -f /usr/local/varnish/etc/varnish/default.vcl -P $varnish_pid"

case $1 in
start)
        if [ -s $varnish_pid ];then
                echo "varnish already running!"
        else
                $v_command
                echo "Start Ok!"
        fi
;;

stop)
        if [ -s $varnish_pid ];then
                kill -9 $(cat $varnish_pid) && echo "Stop Ok!" && rm -rf $varnish_pid
        else
                echo "varnish pid not found!"
        fi

;;

restart)

        if [ -s $varnish_pid ];then
                kill -9 $(cat $varnish_pid) && echo "Stop Ok!" && rm -rf $varnish_pid
                $v_command
                echo "Start Ok!"
        else
                echo "varnish pid not found!"
                echo "Start It!"
                $v_command
                echo "Start Ok!"
        fi
;;

*)
echo "Just start/stop/restart"
;;
esac

exit

脚本可接受的参数,start 启动、stop 关闭、restart 重启。

可将其复制到 /etc/init.d 下使用service varnish start/stop/restart 管理。

cp varnish.sh  /etc/init.d/varnish

chmod 755  /etc/init.d/varnish

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/2032.html

作者:Venus

服务器运维与性能优化

发表回复