<commit_before>
import uuid
import subprocess
import unittest
import tornado.testing
import paasmaker
import tempfile
import shutil
import os
import logging
import time
import signal
from paasmaker.thirdparty.pika import TornadoConnection
import pika

from ..common.testhelpers import TestHelpers
from manageddaemon import ManagedDaemon, ManagedDaemonError

class ManagedRabbitMQError(ManagedDaemonError):
	pass

class ManagedRabbitMQ(ManagedDaemon):
	RABBITMQ_SERVER_CONFIG = """
[
    {rabbit, [{tcp_listeners, [%(RABBITMQ_PORT)s]}]}
].
"""

	def configure(self, working_dir, port, bind_host, nodepurpose=None):
		"""
		Configure this instance.
		"""
		# TODO: Allow authentication.
		self.parameters['working_dir'] = working_dir
		self.parameters['port'] = port
		self.parameters['host'] = bind_host
		if nodepurpose:
			self.parameters['nodename'] = '%s-paasmaker@localhost' % nodepurpose
		else:
			self.parameters['nodename'] = 'paasmaker@localhost'
		self.parameters['pidfile'] = os.path.join(working_dir, self.parameters['nodename'] + '.pid')
		self.parameters['logfile'] = os.path.join(working_dir, 'rabbitmq.log')

		environment = {}
		environment['HOME'] = working_dir
		environment['RABBITMQ_BASE'] = working_dir
		environment['RABBITMQ_HOME'] = working_dir
		environment['RABBITMQ_MNESIA_BASE'] = working_dir
		environment['RABBITMQ_LOG_BASE'] = working_dir
		environment['RABBITMQ_NODENAME'] = self.parameters['nodename']
		environment['RABBITMQ_PORT'] = str(self.parameters['port'])
		environment['RABBITMQ_CONFIG_FILE'] = self.get_configuration_path(working_dir)

		self.parameters['environment'] = environment

		# Create the working dir. If this fails, let it bubble up.
		if not os.path.exists(working_dir):
			os.makedirs(working_dir)

		self.save_parameters()

	def get_pid_path(self):
		return self.parameters['pidfile']

	def start(self, callback, error_callback):
		"""
		Start up the server for this instance.
		"""
		# Write out the configuration.<commit_msg>Improved the detection of the Managed RabbitMQ is running feature.<commit_after>
import uuid
import subprocess
import unittest
import tornado.testing
import paasmaker
import tempfile
import shutil
import os
import logging
import time
import signal
from paasmaker.thirdparty.pika import TornadoConnection
import pika

from ..common.testhelpers import TestHelpers
from manageddaemon import ManagedDaemon, ManagedDaemonError

class ManagedRabbitMQError(ManagedDaemonError):
	pass

class ManagedRabbitMQ(ManagedDaemon):
	RABBITMQ_SERVER_CONFIG = """
[
    {rabbit, [{tcp_listeners, [%(RABBITMQ_PORT)s]}]}
].
"""

	def configure(self, working_dir, port, bind_host, nodepurpose=None):
		"""
		Configure this instance.
		"""
		# TODO: Allow authentication.
		self.parameters['working_dir'] = working_dir
		self.parameters['port'] = port
		self.parameters['host'] = bind_host
		if nodepurpose:
			self.parameters['nodename'] = '%s-paasmaker@localhost' % nodepurpose
		else:
			self.parameters['nodename'] = 'paasmaker@localhost'
		self.parameters['pidfile'] = os.path.join(working_dir, self.parameters['nodename'] + '.pid')
		self.parameters['logfile'] = os.path.join(working_dir, 'rabbitmq.log')

		environment = {}
		environment['HOME'] = working_dir
		environment['RABBITMQ_BASE'] = working_dir
		environment['RABBITMQ_HOME'] = working_dir
		environment['RABBITMQ_MNESIA_BASE'] = working_dir
		environment['RABBITMQ_LOG_BASE'] = working_dir
		environment['RABBITMQ_NODENAME'] = self.parameters['nodename']
		environment['RABBITMQ_PORT'] = str(self.parameters['port'])
		environment['RABBITMQ_CONFIG_FILE'] = self.get_configuration_path(working_dir)

		self.parameters['environment'] = environment

		# Create the working dir. If this fails, let it bubble up.
		if not os.path.exists(working_dir):
			os.makedirs(working_dir)

		self.save_parameters()

	def get_pid_path(self):
		return self.parameters['pidfile']

	def is_running(self, keyword=None):
		return super(ManagedRabbitMQ, self).is_running('rabbitmq')

	def start(self, callback, error_callback):
		"""
		Start up the server for this instance.
		"""
		# Write out the configuration.
{'fraction_non_alphanumeric': 0.11644832605531295, 'fraction_numerical': 0.0, 'mean_word_length': 5.894648829431438, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '502188', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1301, 'n_words': 282}