Bläddra i källkod

AMBARI-9663. Modifying the ambari server to run as a sudo root account prints error on start (aonishuk)

Andrew Onishuk 10 år sedan
förälder
incheckning
46fbae9eb8

+ 9 - 5
ambari-server/src/main/python/ambari_server_main.py

@@ -213,28 +213,32 @@ def generate_child_process_param_list(ambari_user, current_user, java_exe, class
 
   command_base = SERVER_START_CMD_DEBUG if debug_start else SERVER_START_CMD
 
-  command = "%s %s; %s" % (ULIMIT_CMD, str(get_ulimit_open_files(properties)),
-      command_base.format(java_exe,
+  ulimit_cmd = "%s %s" % (ULIMIT_CMD, str(get_ulimit_open_files(properties)))
+  command = command_base.format(java_exe,
           ambari_provider_module_option,
           jvm_args,
           class_path,
           configDefaults.SERVER_OUT_FILE,
           os.path.join(configDefaults.PID_DIR, EXITCODE_NAME),
           suspend_mode)
-  )
 
   # required to start properly server instance
   os.chdir(configDefaults.ROOT_FS_PATH)
 
   #For properly daemonization server should be started using shell as parent
+  param_list = [locate_file('sh', '/bin'), "-c"]
   if is_root() and ambari_user != "root":
     # To inherit exported environment variables (especially AMBARI_PASSPHRASE),
     # from subprocess, we have to skip --login option of su command. That's why
     # we change dir to / (otherwise subprocess can face with 'permission denied'
     # errors while trying to list current directory
-    param_list = [locate_file('su', '/bin'), ambari_user, "-s", locate_file('sh', '/bin'), "-c", command]
+    cmd = "{ulimit_cmd} ; {su} {ambari_user} -s {sh_shell} -c '{command}'".format(ulimit_cmd=ulimit_cmd, 
+                                                                                su=locate_file('su', '/bin'), ambari_user=ambari_user,
+                                                                                sh_shell=locate_file('sh', '/bin'), command=command)
   else:
-    param_list = [locate_file('sh', '/bin'), "-c", command]
+    cmd = "{ulimit_cmd} ; {command}".format(ulimit_cmd=ulimit_cmd, command=command)
+    
+  param_list.append(cmd)
   return param_list
 
 @OsFamilyFuncImpl(OSConst.WINSRV_FAMILY)

+ 1 - 1
ambari-server/src/test/python/TestAmbariServer.py

@@ -3477,7 +3477,7 @@ MIIFHjCCAwYCCQDpHKOBI+Lt0zANBgkqhkiG9w0BAQUFADBRMQswCQYDVQQGEwJV
     self.assertTrue(chdir_mock.called)
     self.assertTrue(popenMock.called)
     popen_arg = popenMock.call_args_list[0][0][0]
-    self.assertTrue(popen_arg[0] == "/bin/su")
+    self.assertTrue("; /bin/su" in popen_arg[2])
     self.assertTrue(perform_housekeeping_mock.called)
 
     args = reset_mocks()