<commit_before>#! /bin/bash

# source function library
#. /etc/rc.d/init.d/functions

COLOR_G="\x1b[0;32m"  # green
COLOR_R="\x1b[1;31m"  # red
RESET="\x1b[0m"
STR_ERR="[Oops! Error occurred! Please see the message upside!]"
STR_OK="[Job done!]"
MSG_ERR=$COLOR_R$STR_ERR$RESET
MSG_OK=$COLOR_G$STR_OK$RESET
isexit()
{
	if [[ $1 -eq 0 ]];then
		echo -e $MSG_OK
	else
		echo -e $MSG_ERR
		exit 1
	fi
}

DIALUP_PID=$KE_HOME/bin/ke.pid
start()
{
    echo -n $"Starting $prog: "
    echo "Ke service check ..."
    
    if [ "$KE_HOME" = "" ]; then
  		echo "Error: KE_HOME is not set."
  		exit 1
	fi
	
	if [ "$JAVA_HOME" = "" ]; then
  		echo "Error: JAVA_HOME is not set."
  		exit 1
	fi

	bin=`dirname "$0"`
	export KE_HOME=`cd $bin/../; pwd`

	KE_HOME_CONF_DIR=$KE_HOME/conf
	CLASSPATH="${KE_HOME_CONF_DIR}"

	for f in $KE_HOME/lib/*.jar; do
  		CLASSPATH=${CLASSPATH}:$f;
	done

	LOG_DIR=${KE_HOME}/logs
	
	cd ${KE_HOME}
	CLASS=com.smartloli.kafka.eagle.plugins.main.TomcatServerListen
	${JAVA_HOME}/bin/java -classpath "$CLASSPATH" $CLASS > ${LOG_DIR}/ke.out 2>&1
	echo "*******************************************************************"
    echo "* Listen port has successed! *"
	echo "*******************************************************************"
	sleep 5
	rm -rf ${KE_HOME}/kms/logs/*
	chmod +x ${KE_HOME}/kms/bin/*.sh
	nohup ${KE_HOME}/kms/bin/startup.sh > ${LOG_DIR}/ke.out 2>&1
	ret=$?
	echo "Status Code["$ret"]"
	isexit $ret
	echo "*******************************************************************"
    	echo "* KE service has started success! *"
    	echo "* Welcome, Now you can visit 'http://<your_host_or_ip>:port/ke' *"
	echo "*******************************************************************"
	ps -ef | grep ${KE_HOME}/kms/bin/ | grep -v grep | awk '{print $2}' > $DIALUP_PID
	rm -rf ${LOG_DIR}/ke_console.out
	ln -s ${KE_HOME}/kms/logs/catalina.out ${LOG_DIR}/ke_console.out
}

stop()
{

	 if [ -f $KE_HOME/bin/ke.pid ];then
                    SPID=`cat $KE_HOME/bin/ke.pid`
					  if [ "$SPID" != "" ];then
                         ${KE_HOME}/kms/bin/shutdown.sh
                         kill -9  $SPID
						 echo  > $DIALUP_PID
						 echo "stop success"
					  fi
	 fi
}

stats()
{
	echo "===================== TCP Connections Count  =========================="
	netstat -natp|awk '{print $7}'|sort|uniq -c|sort -rn
	
	echo "===================== ESTABLISHED/TIME_OUT Status  ===================="
	netstat -nat|grep ESTABLISHED|awk '{print$5}'|awk -F : '{print$1}'|sort|uniq -c|sort -rn
	
	echo "===================== Connection Number Of Different States ==========="
	netstat -an | awk '/^tcp/ {++y[$NF]} END {for(w in y) print w, y[w]}'
	
	echo "===================== End ============================================="
}

CheckProcessStata()<commit_msg>fixed start bash & stats pid<commit_after>#! /bin/bash

# source function library
#. /etc/rc.d/init.d/functions

COLOR_G="\x1b[0;32m"  # green
COLOR_R="\x1b[1;31m"  # red
RESET="\x1b[0m"
STR_ERR="[Oops! Error occurred! Please see the message upside!]"
STR_OK="[Job done!]"
MSG_ERR=$COLOR_R$STR_ERR$RESET
MSG_OK=$COLOR_G$STR_OK$RESET
isexit()
{
	if [[ $1 -eq 0 ]];then
		echo -e $MSG_OK
	else
		echo -e $MSG_ERR
		exit 1
	fi
}

DIALUP_PID=$KE_HOME/bin/ke.pid
start()
{
    echo -n $"Starting $prog: "
    echo "Ke service check ..."
    
    if [ "$KE_HOME" = "" ]; then
  		echo "Error: KE_HOME is not set."
  		exit 1
	fi
	
	if [ "$JAVA_HOME" = "" ]; then
  		echo "Error: JAVA_HOME is not set."
  		exit 1
	fi

	bin=`dirname "$0"`
	export KE_HOME=`cd $bin/../; pwd`

	KE_HOME_CONF_DIR=$KE_HOME/conf
	CLASSPATH="${KE_HOME_CONF_DIR}"

	for f in $KE_HOME/lib/*.jar; do
  		CLASSPATH=${CLASSPATH}:$f;
	done

	LOG_DIR=${KE_HOME}/logs
	
	cd ${KE_HOME}
	CLASS=com.smartloli.kafka.eagle.plugins.main.TomcatServerListen
	${JAVA_HOME}/bin/java -classpath "$CLASSPATH" $CLASS > ${LOG_DIR}/ke.out 2>&1
	echo "*******************************************************************"
    echo "* Listen port has successed! *"
	echo "*******************************************************************"
	sleep 5
	rm -rf ${KE_HOME}/kms/logs/*
	chmod +x ${KE_HOME}/kms/bin/*.sh
	nohup ${KE_HOME}/kms/bin/startup.sh > ${LOG_DIR}/ke.out 2>&1
	ret=$?
	echo "Status Code["$ret"]"
	isexit $ret
	echo "*******************************************************************"
    	echo "* KE service has started success! *"
    	echo "* Welcome, Now you can visit 'http://<your_host_or_ip>:port/ke' *"
	echo "*******************************************************************"
	ps -ef | grep ${KE_HOME}/kms/bin/ | grep -v grep | awk '{print $2}' > $DIALUP_PID
	rm -rf ${LOG_DIR}/ke_console.out
	ln -s ${KE_HOME}/kms/logs/catalina.out ${LOG_DIR}/ke_console.out
}

stop()
{
	 if [ -f $KE_HOME/bin/ke.pid ];then
                    SPID=`cat $KE_HOME/bin/ke.pid`
					  if [ "$SPID" != "" ];then
                         ${KE_HOME}/kms/bin/shutdown.sh
                         kill -9  $SPID
						 echo  > $DIALUP_PID
						 echo "stop success"
					  fi
	 fi
}

stats()
{
	if [ -f $KE_HOME/bin/ke.pid ];then
                    SPID=`cat $KE_HOME/bin/ke.pid`
					  if [ "$SPID" != "" ];then
						echo "===================== TCP Connections Count  =========================="
						netstat -natp|awk '{print $7}'|sort|uniq -c|sort -rn|grep $SPID
					  fi
	fi
	
	echo "===================== ESTABLISHED/TIME_OUT Status  ===================="
	netstat -nat|grep ESTABLISHED|awk '{print$5}'|awk -F : '{print$1}'|sort|uniq -c|sort -rn
	
	echo "===================== Connection Number Of Different States ==========="
	netstat -an | awk '/^tcp/ {++y[$NF]} END {for(w in y) print w, y[w]}'
	
	echo "===================== End ============================================="
}

CheckProcessStata()
{'fraction_non_alphanumeric': 0.30568596765779865, 'fraction_numerical': 0.009041905755520779, 'mean_word_length': 3.550632911392405, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '4501151', 'n_tokens_mistral': 2271, 'n_tokens_neox': 2040, 'n_words': 455}