<commit_before>#!/bin/bash
ulimit -n 1024

HOSTNAME=$(hostname)
PID_FILE="/storage/mnesia/rabbit\@$HOSTNAME.pid"

function run_cmd()
{
        su rabbitmq -s /bin/sh -c "$1"
}

function start()
{
	if [ -z "$CLUSTERED" ]; then
		# Not clustered, just start
        	/usr/sbin/rabbitmq-server >/dev/null &
	else
		if [ -z "$CLUSTERED_WITH" ]; then
			# Is clustered, but not specified who to cluster with
        		/usr/sbin/rabbitmq-server >/dev/null &
		else
               		/usr/sbin/rabbitmq-server -detached
                	rabbitmqctl stop_app
                	if [ -z "$RAM_NODE" ]; then
                        	rabbitmqctl join_cluster rabbit@$CLUSTERED_WITH
                	else
                        	rabbitmqctl join_cluster --ram rabbit@$CLUSTERED_WITH
                	fi
                	rabbitmqctl start_app

		fi
	fi
	rabbitmqctl wait $PID_FILE
	tail -f /storage/log/rabbit\@$HOSTNAME.log &
	parent=$!
}

function stop()
{
        /usr/sbin/rabbitmqctl stop
	kill -TERM $parent
        exit 0
}

function restart()
{
        /usr/sbin/rabbitmqctl restart
}

trap stop TERM INT
trap restart SIGHUP

start<commit_msg>Better startup script and traps<commit_after>#!/bin/bash
set -e
ulimit -n 1024

HOSTNAME=$(hostname)
PID_FILE=/storage/mnesia/rabbit\@$HOSTNAME.pid
LOG_FILE=/storage/log/rabbit\@$HOSTNAME.log

function run_cmd()
{
        su rabbitmq -s /bin/sh -c "$1"
}

function start()
{
	mkdir -p /storage/log
	touch $LOG_FILE
	if [ -z "$CLUSTERED" ]; then
		# Not clustered, just start
        	/usr/sbin/rabbitmq-server &
	else
		if [ -z "$CLUSTERED_WITH" ]; then
			# Is clustered, but not specified who to cluster with
        		/usr/sbin/rabbitmq-server &
		else
               		/usr/sbin/rabbitmq-server -detached
                	rabbitmqctl stop_app
                	if [ -z "$RAM_NODE" ]; then
                        	rabbitmqctl join_cluster rabbit@$CLUSTERED_WITH
                	else
                        	rabbitmqctl join_cluster --ram rabbit@$CLUSTERED_WITH
                	fi
                	rabbitmqctl start_app

		fi
	fi
	echo Waiting for RabbitMQ to start...
	while [ ! -f $PID_FILE ]; do 
		sleep 1
		echo Waiting for PID file...
	done
	PID=`cat $PID_FILE`
	echo PID file detected, waiting for PID $PID to start...
	while [ ! kill -0 $PID > /dev/null 2>&1 ]; do
		sleep 1
		echo Waiting for Process to start...
	done 
	echo "Started (PID: $PID)! Tailing $LOG_FILE"
	tail -f $LOG_FILE &
	TAIL_PID=$!
}

function stop()
{
 	echo Stopping RabbitMQ...
        /usr/sbin/rabbitmqctl stop
	if [ -z "$TAIL_PID" ]; then
		kill -TERM $TAIL_PID
	fi
	echo Stopped!
        exit 0
}

function restart()
{
        /usr/sbin/rabbitmqctl restart
}

trap stop TERM INT
trap restart SIGHUP

start
{'fraction_non_alphanumeric': 0.10545587696814354, 'fraction_numerical': 0.006224826071036251, 'mean_word_length': 2.049107142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5318110', 'n_tokens_mistral': 1053, 'n_tokens_neox': 940, 'n_words': 252}