Ubuntu batch hadoop env
#!/usr/bin/python2
'''
Created on Jun 20, 2014
@author: burkun
'''
import os
def has_install(str_v):
res = os.popen("which "+str_v)
line = None
for line in res:
break;
if line == None:
return False
return True
def set_java(version = 6):
if(not has_install("java")):
os.system("sudo apt-get purge openjdk*")
os.system("sudo apt-get install software-properties-common")
os.system("sudo add-apt-repository ppa:webupd8team/java")
os.system("sudo apt-get update")
os.system("sudo apt-get install oracle-java+"+version+"-installer")
else:
print "java had installed"
def set_ssh():
if(not has_install("ssh")):
os.system("sudo apt-get install ssh")
else:
print "ssh had installed"
def set_env():
cur_dir = os.getcwd()
#run import
dst_dir = "/etc/profile.d"
new_file_name = "hadoop_export_env.sh"
if not os.path.exists(dst_dir+"/"+new_file_name):
if not os.path.exists(dst_dir):
os.system("echo '"+dst_dir+" does not exist!'")
else:
f = open(dst_dir+"/"+new_file_name, "w")
f.writelines("""#!/usr/bin/bash
#this file is autogenerated by export_env.py
export JAVA_HOME=/usr/bin/jvm/java-6-oracle
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export HADOOP_HOME=""" + cur_dir +"""
export HADOOP_MAPRED_HOME=${HADOOP_HOME}
export HADOOP_COMMON_HOME=${HADOOP_HOME}
export HADOOP_HDFS_HOME=${HADOOP_HOME}
export YARN_HOME=${HADOOP_HOME}
export HADOOP_YARN_HOME=${HADOOP_HOME}
export HADOOP_CONF_DIR=${HADOOP_HOME}/etc/hadoop
export HDFS_CONF_DIR=${HADOOP_HOME}/etc/hadoop
export YARN_CONF_DIR=${HADOOP_HOME}/etc/hadoop
export PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:$HADOOP_HOME/sbin""")
f.close()
if __name__ == '__main__':
set_java()
set_ssh()
set_env()