Table of Contents

Top#Programming Languages

Java (java.py)

$FHHOME/fabfile/java.py


Java Operation

Fabric one-line Task Examples

$ fab -l |grep -F java.

$ fab  -H $H   java.install_yum

Fabric one-line Task Examples

$ H=test-server-1,test-server-2



java.py

$FHHOME/fabfile/java.py

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

FHHOME=os.environ["FHHOME"]


#----------------------------------------------------------------------
# Installing Java
#----------------------------------------------------------------------
# java.install_yum
@task
def install_targz(FILE):
    """ java.install_targz:jdk-8u161-linux-x64.tar.gz"""
    put("%s/src/%s" % (FHHOME, FILE), "/usr/java/" , use_sudo=True)
    with cd('/usr/java/'):
        sudo("tar zxvf %s" % FILE)

#----------------------------------------------------------------------
# Add /etc/profile
#----------------------------------------------------------------------
@task
def add_etc_profile(PATH):
    """ java.add_etc_profile:/usr/java/jdk1.8.0_74"""
    # Backup
    sudo("cp -p /etc/profile /etc/profile.`date -d '1day ago' +%Y%m%d`")
    # Add /etc/profile
    sudo('echo "" >> /etc/profile')
    sudo('echo "" >> /etc/profile')
    sudo('echo "JAVA_HOME=%s" >> /etc/profile' % PATH)
    sudo('echo "PATH=$PATH:$JAVA_HOME/bin" >> /etc/profile')
    sudo('echo "export JAVA_HOME" >> /etc/profile')
    sudo('echo "export PATH" >> /etc/profile')




languages



Top#Programming Languages