Table of Contents

Top#Middleware Management

Squid (squid.py)

$FHHOME/fabfile/squid.py


Squid Operation

$ fab -l |grep squid

$ fab  -H x.x.x.x   squid.yum_install


Fabric Temporary Run Call Examples

$ H=test-serve-01,test-server-02

$ fab -H $H  -- sudo diff /etc/squid/squid.conf /etc/squid/squid.conf.20171205
$ fab -H $H  -- sudo mv /etc/squid/squid.conf.20171205 /etc/squid/squid.conf

$ fab -H $H  -- "ps aux |grep suqid"
$ fab -H $H  -- sudo systemctl status squid
$ fab -H $H  -- sudo systemctl restart squid


squid.py

$FHHOME/fabfile/squid.py

import sys, os
from fabric.api import *
from fabric.contrib import files

FHHOME=os.environ["FHHOME"]

#----------------------------------------------------------------------
# Installing Squid
#----------------------------------------------------------------------
# squid.install_yum
@task
def install_yum():
    sudo("rpm -q squid        > /dev/null 2>&1 || yum -y install squid")

#----------------------------------------------------------------------
# Service
#----------------------------------------------------------------------
# squid.systemctl_restart
@task
def systemctl_restart():
    run("ps aux |grep squid")
    sudo("systemctl stauts squid")
    sudo("systemctl restart squid")
    sudo("systemctl stauts squid")
    run("ps aux |grep squid")

#----------------------------------------------------------------------
# Configuration
#----------------------------------------------------------------------
# squid.change_squidconf:test-server-01
@task
def change_squidconf(host):
    today = datetime.now().strftime('%Y%m%d')
    sudo("cp -f /etc/squid/squid.conf /etc/squid/squid.conf.`date -d '1day ago' +%Y%m%d`")
    put("%s/conf/squid/squid.conf.%s" % (FHHOME, host), "/tmp/squid.conf.%s" % date)
    sudo("mv /tmp/squid.conf.%s /etc/sysctl.conf" % date)


Squid Configuration Examples




middleware



Top#Middleware Management