<commit_before>#!/bin/sh
# chkconfig: 2345 20 80
# description: Handle tomcat instance <%= tomcat_name %>

# file managed by puppet

. /lib/lsb/init-functions

SHUTDOWN_WAIT=30

export JAVA_HOME=<%= @javahome %>
export CATALINA_HOME=<%= @catalinahome %>
export CATALINA_BASE=<%= @basedir %>
export CATALINA_PID=<%= @basedir %>/temp/tomcat.pid

# For SELinux we need to use 'runuser' not 'su'
if [ -x "/sbin/runuser" ]; then
    SU="/sbin/runuser -s /bin/sh"
else
    SU="su -s /bin/sh"
fi

start() {
  isrunning

  if [ "$?" = 0 ]; then
    echo "tomcat-<%= @tomcat_name %> already running"
    return 0
  fi

  # Change directory to prevent path problems
  cd <%= @basedir %>
<% if @tomcat_version_str == '5.5_package' -%>
  # Source JVM parameters
  test -r <%= @basedir %>/bin/setenv.sh && . <%= @basedir %>/bin/setenv.sh
<% end -%>

  # Remove pidfile if still around
  test -f $CATALINA_PID && rm -f $CATALINA_PID

  $SU <%= @owner %> -c "umask 0002; $CATALINA_HOME/bin/catalina.sh start" > /dev/null
}

stop() {
  isrunning

  if [ "$?" = 1 ]; then
    echo "tomcat-<%= @tomcat_name %> already stopped"
    rm -f $CATALINA_PID # remove pidfile if still around
    return 0
  fi

  echo -n "Waiting for tomcat-<%= @tomcat_name %> to exit (${SHUTDOWN_WAIT} sec.): "

  count=0
  until [ "$pid" = "" ] || [ $count -gt $SHUTDOWN_WAIT ]; do
    $SU <%= @owner %> -c "$CATALINA_HOME/bin/catalina.sh stop -force" > /dev/null
    findpid

    echo -n "."
    sleep 3
    count=$((count+3))
  done

  echo ""

  if [ "$count" -gt "$SHUTDOWN_WAIT" ]; then
    echo "Forcing tomcat-<%= @tomcat_name %> to stop"
    /bin/kill -9 $pid && sleep 5
  fi

  # check if tomcat is still around, this will be our exit status
  ! isrunning
}

findpid() {
  pid=""
  pid=$(pgrep -U tomcat -f "^$JAVA_HOME/bin/java.*catalina.base=<%= basedir %>")

  # validate output of pgrep
  if ! [ "$pid" = "" ] && ! [ "$pid" -gt 0 ]; then
    log_failure_msg "Unable to determine if tomcat-<%= @tomcat_name %> is running"
    exit 1
  fi
}

isrunning() {
  findpid

  if [ "$pid" = "" ]; then
    return 1
  elif [ "$pid" -gt 0 ]; then
    return 0
  fi
}

case "$1" in
  start)
    start
    RETVAL=$?

    if [ "$RETVAL" = 0 ]; then
      log_success_msg "Started tomcat-<%= @tomcat_name %>"
    else
      log_failure_msg "Not able to start tomcat-<%= @tomcat_name %>"
    fi
    ;;

  stop)
    stop
    RETVAL=$?

    if [ "$RETVAL" = 0 ]; then
      log_success_msg "Stopped tomcat-<%= @tomcat_name %>"
    else
      log_failure_msg "Not able to stop tomcat-<%= @tomcat_name %>"
    fi
  ;;

  restart)
    stop
    sleep 5
    start
    RETVAL=$?

    if [ "$RETVAL" = 0 ]; then
      log_success_msg "Restarted tomcat-<%= @tomcat_name %>"
    else
      log_failure_msg "Not able to restart tomcat-<%= @tomcat_name %>"
    fi
  ;;

  status)
    isrunning
    RETVAL=$?

    if [ "$RETVAL" = 0 ]; then
      echo "tomcat-<%= @tomcat_name %> (pid $pid) is running..."
    else
      echo "tomcat-<%= @tomcat_name %> is stopped"
      RETVAL=3
    fi
  ;;

  *)
    echo "Usage: $0 {start|stop|restart|status}."
  ;;

esac

exit $RETVAL
<commit_msg>switched hardcoded tomcat proc owner with <=% owner => in findpid()<commit_after>#!/bin/sh
# chkconfig: 2345 20 80
# description: Handle tomcat instance <%= tomcat_name %>

# file managed by puppet

. /lib/lsb/init-functions

SHUTDOWN_WAIT=30

export JAVA_HOME=<%= @javahome %>
export CATALINA_HOME=<%= @catalinahome %>
export CATALINA_BASE=<%= @basedir %>
export CATALINA_PID=<%= @basedir %>/temp/tomcat.pid

# For SELinux we need to use 'runuser' not 'su'
if [ -x "/sbin/runuser" ]; then
    SU="/sbin/runuser -s /bin/sh"
else
    SU="su -s /bin/sh"
fi

start() {
  isrunning

  if [ "$?" = 0 ]; then
    echo "tomcat-<%= @tomcat_name %> already running"
    return 0
  fi

  # Change directory to prevent path problems
  cd <%= @basedir %>
<% if @tomcat_version_str == '5.5_package' -%>
  # Source JVM parameters
  test -r <%= @basedir %>/bin/setenv.sh && . <%= @basedir %>/bin/setenv.sh
<% end -%>

  # Remove pidfile if still around
  test -f $CATALINA_PID && rm -f $CATALINA_PID

  $SU <%= @owner %> -c "umask 0002; $CATALINA_HOME/bin/catalina.sh start" > /dev/null
}

stop() {
  isrunning

  if [ "$?" = 1 ]; then
    echo "tomcat-<%= @tomcat_name %> already stopped"
    rm -f $CATALINA_PID # remove pidfile if still around
    return 0
  fi

  echo -n "Waiting for tomcat-<%= @tomcat_name %> to exit (${SHUTDOWN_WAIT} sec.): "

  count=0
  until [ "$pid" = "" ] || [ $count -gt $SHUTDOWN_WAIT ]; do
    $SU <%= @owner %> -c "$CATALINA_HOME/bin/catalina.sh stop -force" > /dev/null
    findpid

    echo -n "."
    sleep 3
    count=$((count+3))
  done

  echo ""

  if [ "$count" -gt "$SHUTDOWN_WAIT" ]; then
    echo "Forcing tomcat-<%= @tomcat_name %> to stop"
    /bin/kill -9 $pid && sleep 5
  fi

  # check if tomcat is still around, this will be our exit status
  ! isrunning
}

findpid() {
  pid=""
  pid=$(pgrep -U <%= @owner %> -f "^$JAVA_HOME/bin/java.*catalina.base=<%= basedir %>")

  # validate output of pgrep
  if ! [ "$pid" = "" ] && ! [ "$pid" -gt 0 ]; then
    log_failure_msg "Unable to determine if tomcat-<%= @tomcat_name %> is running"
    exit 1
  fi
}

isrunning() {
  findpid

  if [ "$pid" = "" ]; then
    return 1
  elif [ "$pid" -gt 0 ]; then
    return 0
  fi
}

case "$1" in
  start)
    start
    RETVAL=$?

    if [ "$RETVAL" = 0 ]; then
      log_success_msg "Started tomcat-<%= @tomcat_name %>"
    else
      log_failure_msg "Not able to start tomcat-<%= @tomcat_name %>"
    fi
    ;;

  stop)
    stop
    RETVAL=$?

    if [ "$RETVAL" = 0 ]; then
      log_success_msg "Stopped tomcat-<%= @tomcat_name %>"
    else
      log_failure_msg "Not able to stop tomcat-<%= @tomcat_name %>"
    fi
  ;;

  restart)
    stop
    sleep 5
    start
    RETVAL=$?

    if [ "$RETVAL" = 0 ]; then
      log_success_msg "Restarted tomcat-<%= @tomcat_name %>"
    else
      log_failure_msg "Not able to restart tomcat-<%= @tomcat_name %>"
    fi
  ;;

  status)
    isrunning
    RETVAL=$?

    if [ "$RETVAL" = 0 ]; then
      echo "tomcat-<%= @tomcat_name %> (pid $pid) is running..."
    else
      echo "tomcat-<%= @tomcat_name %> is stopped"
      RETVAL=3
    fi
  ;;

  *)
    echo "Usage: $0 {start|stop|restart|status}."
  ;;

esac

exit $RETVAL

{'fraction_non_alphanumeric': 0.16542662656324206, 'fraction_numerical': 0.012031027386417602, 'mean_word_length': 2.6626086956521737, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 61, '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': '3364015', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2380, 'n_words': 660}