源文件:
apache-ambari-2.4.2-src/ambari-server/src/main/python/ambari_server/serverSetup.py
1000行之后
#
# 执行ambari-server setup
# Setup the Ambari Server.
#
def setup(options):
if options.only_silent:
# 命令ambari-server setup已经执行,且只能执行一次
if check_setup_already_done():
print "Nothing was done. Ambari Setup already performed and cannot re-run setup in silent mode. Use \"ambari-server setup\" command without -s option to change Ambari setup."
sys.exit(0)
#设置安全先决条件
retcode = verify_setup_allowed(options)
if not retcode == 0:
raise FatalException(1, None)
#最终调用ambari-common/src/main/python/os_utils.py -> os_linux.py/os_is_root()
#判定当前是否root用户或拥有root权限
if not is_root():
warn_msg = configDefaults.MESSAGE_WARN_SETUP_NOT_ROOT
print warn_msg
# proceed jdbc properties if they were set 如果设置它们,请继续jdbc属性
if _check_jdbc_options(options):
proceedJDBCProperties(options)
return
#SELinux
(retcode, err) = disable_security_enhancements()
if not retcode == 0:
raise FatalException(retcode, err)
#Create ambari user, if needed; 如果需要,请创建ambari用户
(retcode, register_service, svc_user, svc_password) = check_ambari_user(options)
if not retcode == 0:
err = 'Failed to create user. Exiting.'
raise FatalException(retcode, err)
#防火墙
print configDefaults.MESSAGE_CHECK_FIREWALL
check_firewall()
# proceed jdbc properties if they were set 如果设置它们,请继续jdbc属性
if _check_jdbc_options(options):
proceedJDBCProperties(options)
#检测JDK
# 在检查防火墙结束后,可以看到这句输出,开始检查JDK
print 'Checking JDK...'
try:
download_and_install_jdk(options)
except FatalException as e:
err = 'Downloading or installing JDK failed: {0}. Exiting.'.format(e)
raise FatalException(e.code, err)
#完成JDK设置
print 'Completing setup...'
retcode = configure_os_settings()
if not retcode == 0:
err = 'Configure of OS settings in ambari.properties failed. Exiting.'
raise FatalException(retcode, err)
#开始设置数据库
print 'Configuring database...'
#显示数据库提示信息
prompt_db_properties(options)
#DB setup should be done last after doing any setup. DB设置应该在做任何设置后最后完成。
_setup_database(options)
#检测JDBC驱动程序
check_jdbc_drivers(options)
#正在提取系统视图...
print 'Extracting system views...'
retcode = extract_views(options)
if not retcode == 0:
err = 'Error while extracting system views. Exiting'
raise FatalException(retcode, err)
# we've already done this, but new files were created so run it one time.
# 我们已经做到了,但是创建了新文件,所以运行它一次。
adjust_directory_permissions(svc_user)
service_setup(register_service, svc_user, svc_password)
源文件:
apache-ambari-2.4.2-src/ambari-server/src/main/python/ambari-server.py
100行之后
#
# 执行命令:ambari-server start
# Starts the Ambari Server.启动Ambari服务器。
# Ensures only one instance of the process is running.确保只有一个进程正在运行。
# If this is the second instance of the process, the function fails.如果这是进程的第二个实例,函数失败。
#
@OsFamilyFuncImpl(OsFamilyImpl.DEFAULT)
def start(args):
#先判定ambari-server是否已经运行,如果已经,则抛出异常
status, pid = is_server_runing()
if status:
err = "Ambari Server is already running."
raise FatalException(1, err)
#ambari-server处理主程序
server_process_main(args)
源文件:ambari_server_main.py/server_process_main(args)
内容很多
apache-ambari-2.4.2-src/ambari-server/src/main/python/ambari-server.py
#
# Stops the Ambari Server.
# 停止Ambari服务器,本质上就是执行操作系统的kill命令
#
@OsFamilyFuncImpl(OsFamilyImpl.DEFAULT)
def stop(args):
if (args != None):
args.exit_message = None
status, pid = is_server_runing()
# status=true 说明Ambari Server处于运行态
if status:
try:
#信号量SIGTERM:终止进程,软件终止信号
os.kill(pid, signal.SIGTERM)
except OSError, e:
print_info_msg("Unable to stop Ambari Server - " + str(e))
return
pid_file_path = os.path.join(configDefaults.PID_DIR, PID_NAME)
os.remove(pid_file_path)
print "Ambari Server stopped"
else:
print "Ambari Server is not running"
#
# The Ambari Server status. Ambari服务器状态。
#
@OsFamilyFuncImpl(OsFamilyImpl.DEFAULT)
def status(args):
args.exit_message = None
status, pid = is_server_runing()
#Ambari Server的pid文件
pid_file_path = os.path.join(configDefaults.PID_DIR, PID_NAME)
if status:
args.exit_code = 0
print "Ambari Server running"
print "Found Ambari Server PID: " + str(pid) + " at: " + pid_file_path
else:
print "Ambari Server not running. Stale PID File at: " + pid_file_path
args.exit_code = 3
apache-ambari-2.4.2-src/ambari-server/src/main/python/ambari_server/userInput.py
#
# Gets the y/n input.
#
# return True if 'y' or False if 'n'
#
def get_YN_input(prompt, default, answer = None):
yes = set(['yes', 'ye', 'y'])
no = set(['no', 'n'])
if answer is not None and answer:
yes.update(['True', 'true'])
no.update(['False', 'false'])
return get_choice_string_input(prompt, default, yes, no, answer)
apache-ambari-2.4.2-src/ambari-server/src/main/python/setupAgent.py
def installAgent(projectVersion, ret=None):
# 在其他系统上安装(包括CentOS)
else:
#--nogpgcheck表示没有签名的软件包,projectVersion是HDP版本号
Command = ["yum", "-y", "install", "--nogpgcheck", "ambari-agent-" + projectVersion]