Explorar o código

AMBARI-8957. Non-root install: Ganglia Monitor Install issue (aonishuk)

Andrew Onishuk %!s(int64=10) %!d(string=hai) anos
pai
achega
b4c48c262f

+ 8 - 12
ambari-agent/src/test/python/resource_management/TestMonitorWebserverResource.py

@@ -31,11 +31,9 @@ class TestMonitorWebserverResource(TestCase):
     with Environment(test_mode=True) as env:
     with Environment(test_mode=True) as env:
       MonitorWebserverProvider(MonitorWebserver("start")).action_start()
       MonitorWebserverProvider(MonitorWebserver("start")).action_start()
     defined_resources = env.resource_list
     defined_resources = env.resource_list
-    expected_resources = "[MonitorWebserver['start'], " \
-                         "Execute['grep -E 'KeepAlive (On|Off)' /etc/httpd/conf/httpd.conf" \
-                         " && sed -i 's/KeepAlive Off/KeepAlive On/' /etc/httpd/conf/httpd.conf" \
-                         " || echo 'KeepAlive On' >> /etc/httpd/conf/httpd.conf']," \
-                         " Execute['/etc/init.d/httpd start']]"
+    expected_resources = "[MonitorWebserver['start'], Execute['grep -E 'KeepAlive (On|Off)' /etc/httpd/conf/httpd.conf && " \
+    "/usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E sed -i 's/KeepAlive Off/KeepAlive On/' /etc/httpd/conf/httpd.conf || " \
+    "echo 'KeepAlive On' | /usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E tee --append /etc/httpd/conf/httpd.conf > /dev/null'], Execute['('/etc/init.d/httpd', 'start')']]"
     self.assertEqual(str(defined_resources), expected_resources)
     self.assertEqual(str(defined_resources), expected_resources)
 
 
   @patch.object(System, "os_family", new='suse')
   @patch.object(System, "os_family", new='suse')
@@ -43,11 +41,9 @@ class TestMonitorWebserverResource(TestCase):
     with Environment(test_mode=True) as env:
     with Environment(test_mode=True) as env:
       MonitorWebserverProvider(MonitorWebserver("start")).action_start()
       MonitorWebserverProvider(MonitorWebserver("start")).action_start()
     defined_resources = env.resource_list
     defined_resources = env.resource_list
-    expected_resources = "[MonitorWebserver['start'], " \
-                         "Execute['grep -E 'KeepAlive (On|Off)' /etc/apache2/httpd.conf " \
-                         "&& sed -i 's/KeepAlive Off/KeepAlive On/' /etc/apache2/httpd.conf " \
-                         "|| echo 'KeepAlive On' >> /etc/apache2/httpd.conf']," \
-                         " Execute['/etc/init.d/apache2 start']]"
+    expected_resources = "[MonitorWebserver['start'], Execute['grep -E 'KeepAlive (On|Off)' /etc/apache2/httpd.conf && /usr/bin/sudo [RMF_ENV_PLACEHOLDER] " \
+    "-H -E sed -i 's/KeepAlive Off/KeepAlive On/' /etc/apache2/httpd.conf || echo 'KeepAlive On' | " \
+    "/usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E tee --append /etc/apache2/httpd.conf > /dev/null'], Execute['('/etc/init.d/apache2', 'start')']]"
     self.assertEqual(str(defined_resources), expected_resources)
     self.assertEqual(str(defined_resources), expected_resources)
 
 
   @patch.object(System, "os_family", new='redhat')
   @patch.object(System, "os_family", new='redhat')
@@ -56,7 +52,7 @@ class TestMonitorWebserverResource(TestCase):
       MonitorWebserverProvider(MonitorWebserver("stop")).action_stop()
       MonitorWebserverProvider(MonitorWebserver("stop")).action_stop()
     defined_resources = env.resource_list
     defined_resources = env.resource_list
     expected_resources = "[MonitorWebserver['stop'], " \
     expected_resources = "[MonitorWebserver['stop'], " \
-                         "Execute['/etc/init.d/httpd stop']]"
+                         "Execute['('/etc/init.d/httpd', 'stop')']]"
     self.assertEqual(str(defined_resources), expected_resources)
     self.assertEqual(str(defined_resources), expected_resources)
 
 
   @patch.object(System, "os_family", new='suse')
   @patch.object(System, "os_family", new='suse')
@@ -65,5 +61,5 @@ class TestMonitorWebserverResource(TestCase):
       MonitorWebserverProvider(MonitorWebserver("stop")).action_stop()
       MonitorWebserverProvider(MonitorWebserver("stop")).action_stop()
     defined_resources = env.resource_list
     defined_resources = env.resource_list
     expected_resources = "[MonitorWebserver['stop'], " \
     expected_resources = "[MonitorWebserver['stop'], " \
-                         "Execute['/etc/init.d/apache2 stop']]"
+                         "Execute['('/etc/init.d/apache2', 'stop')']]"
     self.assertEqual(str(defined_resources), expected_resources)
     self.assertEqual(str(defined_resources), expected_resources)

+ 10 - 4
ambari-common/src/main/python/resource_management/libraries/providers/monitor_webserver.py

@@ -29,12 +29,16 @@ class MonitorWebserverProvider(Provider):
     self.get_serivice_params()
     self.get_serivice_params()
     self.enable_keep_alive()
     self.enable_keep_alive()
     service_name = self.service_name
     service_name = self.service_name
-    Execute(format("/etc/init.d/{service_name} start"))
+    Execute((format('/etc/init.d/{service_name}'), 'start'),
+      sudo = True,        
+    )
 
 
   def action_stop(self):
   def action_stop(self):
     self.get_serivice_params()
     self.get_serivice_params()
     service_name = self.service_name
     service_name = self.service_name
-    Execute(format("/etc/init.d/{service_name} stop"))
+    Execute((format('/etc/init.d/{service_name}'), 'stop'),
+      sudo = True,        
+    )
 
 
   def action_restart(self):
   def action_restart(self):
     self.action_stop()
     self.action_stop()
@@ -49,7 +53,9 @@ class MonitorWebserverProvider(Provider):
       self.service_name = "httpd"
       self.service_name = "httpd"
       self.httpd_conf_dir = '/etc/httpd/conf'
       self.httpd_conf_dir = '/etc/httpd/conf'
 
 
+  # "tee --append /etc/apt/sources.list > /dev/null"
   def enable_keep_alive(self):
   def enable_keep_alive(self):
     httpd_conf_dir = self.httpd_conf_dir
     httpd_conf_dir = self.httpd_conf_dir
-    Execute(format(
-      "grep -E 'KeepAlive (On|Off)' {httpd_conf_dir}/httpd.conf && sed -i 's/KeepAlive Off/KeepAlive On/' {httpd_conf_dir}/httpd.conf || echo 'KeepAlive On' >> {httpd_conf_dir}/httpd.conf"))
+    command = format("grep -E 'KeepAlive (On|Off)' {httpd_conf_dir}/httpd.conf && " + as_sudo(('sed',  '-i','s/KeepAlive Off/KeepAlive On/', format("{httpd_conf_dir}/httpd.conf"))) + " || echo 'KeepAlive On' | ") + as_sudo(('tee', '--append', format('{httpd_conf_dir}/httpd.conf'))) + " > /dev/null" 
+    Execute(command
+    )

+ 11 - 7
ambari-server/src/main/resources/common-services/GANGLIA/3.5.0/package/files/setupGanglia.sh

@@ -46,7 +46,8 @@ function instantiateGmetadConf()
   # gmetad utility library.
   # gmetad utility library.
   source ./gmetadLib.sh;
   source ./gmetadLib.sh;
 
 
-  generateGmetadConf > ${GMETAD_CONF_FILE};
+  generateGmetadConf > ${TMP_GANGLIA_FILE};
+  sudo -H -E cp ${TMP_GANGLIA_FILE} ${GMETAD_CONF_FILE}
 }
 }
 
 
 function instantiateGmondConf()
 function instantiateGmondConf()
@@ -63,19 +64,22 @@ function instantiateGmondConf()
     createDirectory "${GANGLIA_CONF_DIR}/${gmondClusterName}/conf.d";
     createDirectory "${GANGLIA_CONF_DIR}/${gmondClusterName}/conf.d";
     
     
     # Always blindly generate the core gmond config - that goes on every box running gmond. 
     # Always blindly generate the core gmond config - that goes on every box running gmond. 
-    generateGmondCoreConf ${gmondClusterName} > `getGmondCoreConfFileName ${gmondClusterName}`;
+    generateGmondCoreConf ${gmondClusterName} > ${TMP_GANGLIA_FILE};
+    sudo -H -E cp ${TMP_GANGLIA_FILE} `getGmondCoreConfFileName ${gmondClusterName}`;
 
 
     isMasterGmond=${2};
     isMasterGmond=${2};
 
 
     # Decide whether we want to add on the master or slave gmond config.
     # Decide whether we want to add on the master or slave gmond config.
     if [ "0" -eq "${isMasterGmond}" ]
     if [ "0" -eq "${isMasterGmond}" ]
     then
     then
-      generateGmondSlaveConf ${gmondClusterName} > `getGmondSlaveConfFileName ${gmondClusterName}`;
+      generateGmondSlaveConf ${gmondClusterName} > ${TMP_GANGLIA_FILE};
+      sudo -H -E cp ${TMP_GANGLIA_FILE} `getGmondSlaveConfFileName ${gmondClusterName}`;
     else
     else
-      generateGmondMasterConf ${gmondClusterName} > `getGmondMasterConfFileName ${gmondClusterName}`;
+      generateGmondMasterConf ${gmondClusterName} > ${TMP_GANGLIA_FILE}
+      sudo -H -E cp ${TMP_GANGLIA_FILE} `getGmondMasterConfFileName ${gmondClusterName}`;
     fi
     fi
 
 
-    chown -R ${3}:${4} ${GANGLIA_CONF_DIR}/${gmondClusterName}
+    sudo -H -E chown -R ${3}:${4} ${GANGLIA_CONF_DIR}/${gmondClusterName}
 
 
   else
   else
     echo "No gmondClusterName passed in, nothing to instantiate";
     echo "No gmondClusterName passed in, nothing to instantiate";
@@ -118,8 +122,8 @@ done
 createDirectory ${GANGLIA_CONF_DIR};
 createDirectory ${GANGLIA_CONF_DIR};
 createDirectory ${GANGLIA_RUNTIME_DIR};
 createDirectory ${GANGLIA_RUNTIME_DIR};
 # So rrdcached can drop its PID files in here.
 # So rrdcached can drop its PID files in here.
-chmod -R o+rw ${GANGLIA_RUNTIME_DIR};
-chown ${owner}:${group} ${GANGLIA_CONF_DIR};
+sudo -H -E chmod -R o+rw ${GANGLIA_RUNTIME_DIR};
+sudo -H -E chown ${owner}:${group} ${GANGLIA_CONF_DIR};
 
 
 if [ -n "${gmondClusterName}" ]
 if [ -n "${gmondClusterName}" ]
 then
 then

+ 13 - 6
ambari-server/src/main/resources/common-services/GANGLIA/3.5.0/package/scripts/functions.py

@@ -20,12 +20,19 @@ from resource_management import *
 
 
 def turn_off_autostart(service):
 def turn_off_autostart(service):
   if System.get_instance().os_family == "ubuntu":
   if System.get_instance().os_family == "ubuntu":
-    Execute(format("update-rc.d {service} disable"),
-            path='/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'
+    Execute(('update-rc.d', service, 'disable'),
+            path='/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin',
+            sudo = True
+    )
+    Execute(('service', service, 'stop'),
+            sudo = True,
+            ignore_failures=True,
+    )
+    File(format('/etc/init/{service}.override'), # disable upstart job
+         content = 'manual',
     )
     )
-    Execute(format("service {service} stop"), ignore_failures=True)
-    Execute(format("echo 'manual' > /etc/init/{service}.override")) # disbale upstart job
   else:
   else:
-    Execute(format("chkconfig {service} off"),
-            path='/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'
+    Execute(('chkconfig', service, 'off'),
+            path='/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin',
+            sudo = True,
     )
     )

+ 2 - 3
ambari-server/src/main/resources/common-services/GANGLIA/3.5.0/package/scripts/ganglia_monitor_service.py

@@ -20,8 +20,7 @@ from resource_management import *
 
 
 
 
 def monitor(action=None):# 'start' or 'stop'
 def monitor(action=None):# 'start' or 'stop'
-  Execute(
-    format(
-      "service hdp-gmond {action} >> /tmp/gmond.log  2>&1 ; /bin/ps auwx | /bin/grep [g]mond  >> /tmp/gmond.log  2>&1"),
+  service_start_command = as_sudo(('service', 'hdp-gmond', action))
+  Execute(format("{service_start_command} >> /tmp/gmond.log  2>&1 ; /bin/ps auwx | /bin/grep [g]mond  >> /tmp/gmond.log  2>&1"),
     path='/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'
     path='/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'
   )
   )

+ 3 - 1
ambari-server/src/main/resources/common-services/GANGLIA/3.5.0/package/scripts/ganglia_server.py

@@ -88,7 +88,9 @@ def change_permission():
             mode=0755,
             mode=0755,
             recursive=True
             recursive=True
   )
   )
-  Execute(format("chown -R {web_user} {dwoo_path}"))
+  Execute(('chown', '-R', params.web_user, params.dwoo_path),
+          sudo = True,
+  )
 
 
 def server_files():
 def server_files():
   import params
   import params

+ 2 - 2
ambari-server/src/main/resources/common-services/GANGLIA/3.5.0/package/scripts/ganglia_server_service.py

@@ -20,8 +20,8 @@ from resource_management import *
 
 
 
 
 def server(action=None):# 'start' or 'stop'
 def server(action=None):# 'start' or 'stop'
-  command = "service hdp-gmetad {action} >> /tmp/gmetad.log  2>&1 ; /bin/ps auwx | /bin/grep [g]metad  >> /tmp/gmetad.log  2>&1"
-  Execute(format(command),
+  command = as_sudo(('service', 'hdp-gmetad', action)) + " >> /tmp/gmetad.log  2>&1 ; /bin/ps auwx | /bin/grep [g]metad  >> /tmp/gmetad.log  2>&1"
+  Execute(command,
           path='/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'
           path='/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'
   )
   )
   MonitorWebserver("restart")
   MonitorWebserver("restart")

+ 2 - 1
ambari-server/src/main/resources/common-services/GANGLIA/3.5.0/package/templates/gangliaLib.sh.j2

@@ -46,6 +46,7 @@ RRDCACHED_WRITE_THREADS={{rrdcached_write_threads}}
 RRDCACHED_TIMEOUT={{rrdcached_timeout}}
 RRDCACHED_TIMEOUT={{rrdcached_timeout}}
 RRDCACHED_FLUSH_TIMEOUT={{rrdcached_flush_timeout}}
 RRDCACHED_FLUSH_TIMEOUT={{rrdcached_flush_timeout}}
 RRDCACHED_DELAY={{rrdcached_delay}}
 RRDCACHED_DELAY={{rrdcached_delay}}
+TMP_GANGLIA_FILE="/tmp/ganglia_tmp_file"
 
 
 # This file contains all the info about each Ganglia Cluster in our Grid.
 # This file contains all the info about each Ganglia Cluster in our Grid.
 GANGLIA_CLUSTERS_CONF_FILE=./gangliaClusters.conf;
 GANGLIA_CLUSTERS_CONF_FILE=./gangliaClusters.conf;
@@ -56,7 +57,7 @@ function createDirectory()
 
 
     if [ "x" != "x${directoryPath}" ]
     if [ "x" != "x${directoryPath}" ]
     then
     then
-        mkdir -p ${directoryPath};
+        sudo -H -E mkdir -p ${directoryPath};
     fi
     fi
 }
 }
 
 

+ 8 - 6
ambari-server/src/test/python/stacks/2.0.6/GANGLIA/test_ganglia_monitor.py

@@ -60,7 +60,7 @@ class TestGangliaMonitor(RMFTestCase):
     )
     )
     self.assert_configure_default()
     self.assert_configure_default()
     self.assert_gmond_master_conf_generated()
     self.assert_gmond_master_conf_generated()
-    self.assertResourceCalled('Execute', 'service hdp-gmond start >> /tmp/gmond.log  2>&1 ; /bin/ps auwx | /bin/grep [g]mond  >> /tmp/gmond.log  2>&1',
+    self.assertResourceCalled('Execute', '/usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E service hdp-gmond start >> /tmp/gmond.log  2>&1 ; /bin/ps auwx | /bin/grep [g]mond  >> /tmp/gmond.log  2>&1',
         path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
         path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
     )
     )
     self.assertNoMoreResources()
     self.assertNoMoreResources()
@@ -74,9 +74,9 @@ class TestGangliaMonitor(RMFTestCase):
                        hdp_stack_version = self.STACK_VERSION,
                        hdp_stack_version = self.STACK_VERSION,
                        target = RMFTestCase.TARGET_COMMON_SERVICES
                        target = RMFTestCase.TARGET_COMMON_SERVICES
     )
     )
-    self.assertResourceCalled('Execute', 'service hdp-gmond stop >> /tmp/gmond.log  2>&1 ; /bin/ps auwx | /bin/grep [g]mond  >> /tmp/gmond.log  2>&1',
-                              path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
-                              )
+    self.assertResourceCalled('Execute', '/usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E service hdp-gmond stop >> /tmp/gmond.log  2>&1 ; /bin/ps auwx | /bin/grep [g]mond  >> /tmp/gmond.log  2>&1',
+        path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
+    )
     self.assertNoMoreResources()
     self.assertNoMoreResources()
 
 
 
 
@@ -90,11 +90,13 @@ class TestGangliaMonitor(RMFTestCase):
     )
     )
     self.assert_configure_default()
     self.assert_configure_default()
     self.assert_gmond_master_conf_generated()
     self.assert_gmond_master_conf_generated()
-    self.assertResourceCalled('Execute', 'chkconfig gmond off',
+    self.assertResourceCalled('Execute', ('chkconfig', 'gmond', 'off'),
         path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
         path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
+        sudo = True,
     )
     )
-    self.assertResourceCalled('Execute', 'chkconfig gmetad off',
+    self.assertResourceCalled('Execute', ('chkconfig', 'gmetad', 'off'),
         path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
         path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
+        sudo = True,
     )
     )
     self.assertNoMoreResources()
     self.assertNoMoreResources()
 
 

+ 9 - 7
ambari-server/src/test/python/stacks/2.0.6/GANGLIA/test_ganglia_server.py

@@ -45,9 +45,9 @@ class TestGangliaServer(RMFTestCase):
                        target = RMFTestCase.TARGET_COMMON_SERVICES
                        target = RMFTestCase.TARGET_COMMON_SERVICES
     )
     )
     self.assert_configure_default()
     self.assert_configure_default()
-    self.assertResourceCalled('Execute', 'service hdp-gmetad start >> /tmp/gmetad.log  2>&1 ; /bin/ps auwx | /bin/grep [g]metad  >> /tmp/gmetad.log  2>&1',
-                              path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
-                              )
+    self.assertResourceCalled('Execute', '/usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E service hdp-gmetad start >> /tmp/gmetad.log  2>&1 ; /bin/ps auwx | /bin/grep [g]metad  >> /tmp/gmetad.log  2>&1',
+        path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
+    )
     self.assertResourceCalled('MonitorWebserver', 'restart',
     self.assertResourceCalled('MonitorWebserver', 'restart',
                               )
                               )
     self.assertNoMoreResources()
     self.assertNoMoreResources()
@@ -60,9 +60,9 @@ class TestGangliaServer(RMFTestCase):
                        hdp_stack_version = self.STACK_VERSION,
                        hdp_stack_version = self.STACK_VERSION,
                        target = RMFTestCase.TARGET_COMMON_SERVICES
                        target = RMFTestCase.TARGET_COMMON_SERVICES
     )
     )
-    self.assertResourceCalled('Execute', 'service hdp-gmetad stop >> /tmp/gmetad.log  2>&1 ; /bin/ps auwx | /bin/grep [g]metad  >> /tmp/gmetad.log  2>&1',
-                              path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
-                              )
+    self.assertResourceCalled('Execute', '/usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E service hdp-gmetad stop >> /tmp/gmetad.log  2>&1 ; /bin/ps auwx | /bin/grep [g]metad  >> /tmp/gmetad.log  2>&1',
+        path = ['/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin'],
+    )
     self.assertResourceCalled('MonitorWebserver', 'restart',
     self.assertResourceCalled('MonitorWebserver', 'restart',
                               )
                               )
     self.assertNoMoreResources()
     self.assertNoMoreResources()
@@ -176,7 +176,9 @@ class TestGangliaServer(RMFTestCase):
         recursive = True,
         recursive = True,
         mode = 0755,
         mode = 0755,
     )
     )
-    self.assertResourceCalled('Execute', 'chown -R wwwrun /var/lib/ganglia-web/dwoo',)
+    self.assertResourceCalled('Execute', ('chown', '-R', 'wwwrun', '/var/lib/ganglia-web/dwoo'),
+        sudo = True,
+    )
     self.assertResourceCalled('Directory', '/srv/www/cgi-bin',
     self.assertResourceCalled('Directory', '/srv/www/cgi-bin',
         recursive = True,
         recursive = True,
     )
     )