Exemple #1
0
	def execute_command(self, cmd, no_wait = False):
		"""
		Run cmd on the remote host.

		cmd is either a string or a sequence of strings
		other parameters are the same as in subprocess.Popen
		
		Returns tuple (int, string) of child exit code and child's output to
		stdout and stderr as string
		"""
		if self.log:
			self.log.info('SSH: execute_command "%s"' % cmd)
		return run_command(self._build_cmd(cmd), log = self.log,
			no_wait = no_wait, stdout = PIPE, stderr = PIPE, stdin = sys.stdin)
Exemple #2
0
    def execute_command(self, cmd, no_wait=False):
        """
		Run cmd on the remote host.

		cmd is either a string or a sequence of strings
		other parameters are the same as in subprocess.Popen
		
		Returns tuple (int, string) of child exit code and child's output to
		stdout and stderr as string
		"""
        if self.log:
            self.log.info('SSH: execute_command "%s"' % cmd)
        return run_command(self._build_cmd(cmd),
                           log=self.log,
                           no_wait=no_wait,
                           stdout=PIPE,
                           stderr=PIPE,
                           stdin=sys.stdin)
Exemple #3
0
def configure_hadoop(primary='127.0.0.1', secondary=[]):
    """Configure Hadoop
    """
    with open('/etc/cyclozzo/hadoop-env.sh', 'w') as f:
        f.write('export JAVA_HOME=/usr/lib/jvm/java-6-sun\n')
    
    with open('/etc/cyclozzo/hdfs-site.xml', 'w') as f:
        f.write(HDFS_SITE_TEMPLATE)
    
    with open('/etc/cyclozzo/core-site.xml', 'w') as f:
        f.write(CORE_SITE_TEMPLATE % primary)
    
    with open('/etc/cyclozzo/masters', 'w') as f:
        f.write(primary +'\n')
        
    with open('/etc/cyclozzo/slaves', 'w') as f:
        f.write(primary +'\n')
        for s in secondary:
            f.write(s + '\n')

    print 'Creating links for DFS to /var/cyclozzo'
    from cyclozzo.runtime.lib.cmnd import run_command
    rc, out = run_command(['rm', '-f' , '/usr/lib/hadoop/logs'])
    if rc != 0:
        print 'Failed to configure DFS, code = %s : %s' % (rc, out)
        sys.exit(-1)
    rc, out = run_command(['rm', '-f' , '/usr/lib/hadoop/pids'])
    if rc != 0:
        print 'Failed to configure DFS, code = %s : %s' % (rc, out)
        sys.exit(-1)
    rc, out = run_command(['rm', '-f' , '/usr/lib/hadoop/conf'])
    if rc != 0:
        print'Failed to configure DFS, code = %s : %s' % (rc, out)
        sys.exit(-1)
    
    rc, out = run_command(['ln', '-s' , '/var/cyclozzo/logs/', '/usr/lib/hadoop/logs'])
    if rc != 0:
        print 'Failed to configure DFS, code = %s : %s' % (rc, out)
        sys.exit(-1)
    rc, out = run_command(['ln', '-s' , '/var/cyclozzo/logs/', '/usr/lib/hadoop/pids'])
    if rc != 0:
        print 'Failed to configure DFS, code = %s : %s' % (rc, out)
        sys.exit(-1)
    rc, out = run_command(['ln', '-s' , '/etc/cyclozzo/', '/usr/lib/hadoop/conf'])
    if rc != 0:
        print 'Failed to configure DFS, code = %s : %s' % (rc, out)
        sys.exit(-1)
Exemple #4
0
                exc_info = sys.exc_info()
                info_string = '\n'.join(traceback.format_exception(*exc_info))
                log.error('Error encountered:\n%s\nNow terminating.',
                          info_string)
                sys.exit(-3)

        elif yaml.runtime == 'java':
            java_util_path = os.path.join(sys.path[0], 'java_util.sh')
            if not os.path.exists(java_util_path):
                log.error('java utility module is not found at %s' %
                          java_util_path)
                sys.exit(-2)

            log.debug('spawning java utility script from %s' % java_util_path)
            rc, out = run_command(['sh', java_util_path],
                                  stderr=PIPE,
                                  stdout=PIPE)
            if rc != 0:
                log.error('Failed to start java application, code: %d, %s' %
                          (rc, out))
            else:
                log.info('Java application was spawned successfully.')
            sys.exit(rc)

        else:
            log.fatal('Runtime %s is NOT supported' % yaml.runtime)
            sys.exit(-5)

    def run(self):
        log.debug('--------- application %s started on %s -----------' %
                  (self.app_path, datetime.datetime.now()))
Exemple #5
0
				log.info('Server interrupted by user, terminating')
				self.stop_application()
			except:
				exc_info = sys.exc_info()
				info_string = '\n'.join(traceback.format_exception(*exc_info))
				log.error('Error encountered:\n%s\nNow terminating.', info_string)
				sys.exit(-3)

		elif yaml.runtime == 'java':
			java_util_path = os.path.join(sys.path[0], 'java_util.sh')
			if not os.path.exists(java_util_path):
				log.error('java utility module is not found at %s' % java_util_path)
				sys.exit(-2)

			log.debug('spawning java utility script from %s' % java_util_path)
			rc, out = run_command(['sh', java_util_path], stderr = PIPE, stdout = PIPE)
			if rc != 0:
				log.error('Failed to start java application, code: %d, %s' % (rc, out) )
			else:
				log.info('Java application was spawned successfully.')
			sys.exit(rc)

		else:
			log.fatal('Runtime %s is NOT supported' % yaml.runtime)
			sys.exit(-5)

	def run(self):
		log.debug('--------- application %s started on %s -----------'
				% ( self.app_path, datetime.datetime.now()) )
		self.run_application()