Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RokkuCode/b2986ec4b4aed8e82e28 to your computer and use it in GitHub Desktop.
Save RokkuCode/b2986ec4b4aed8e82e28 to your computer and use it in GitHub Desktop.

Revisions

  1. pyloor revised this gist Jan 8, 2016. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions Apache Tomcat 8 Start stop script init.d script
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,19 @@
    #
    # Release Updates
    # + add autodetect home dir of installed java
    #

    ### BEGIN INIT INFO
    # Provides: tomcat
    # Required-Start: $local_fs $remote_fs $network
    # Required-Stop: $local_fs $remote_fs $network
    # Should-Start: $named
    # Should-Stop: $named
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Start Tomcat.
    # Description: Start the Tomcat servlet engine.
    ### END INIT INFO


    #Location of JAVA_HOME (bin files)
  2. pyloor revised this gist Jan 6, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Apache Tomcat 8 Start stop script init.d script
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,9 @@
    # Initially forked from: gist.github.com/valotas/1000094
    # Forked from: gist.github.com/miglen/5590986
    # Source: https://gist.github.com/pyloor/b2986ec4b4aed8e82e28
    #
    # Release Updates
    # + add autodetect home dir of installed java


    #Location of JAVA_HOME (bin files)
  3. pyloor revised this gist Jan 6, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Apache Tomcat 8 Start stop script init.d script
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    # processname: tomcat
    # chkconfig: 234 20 80
    #
    #
    # Copyright (C) 2016 Holger Schramm
    # Copyright (C) 2014 Miglen Evlogiev
    #
    # This program is free software: you can redistribute it and/or modify it under
    @@ -21,7 +21,7 @@
    #
    # Initially forked from: gist.github.com/valotas/1000094
    # Forked from: gist.github.com/miglen/5590986
    # Source:
    # Source: https://gist.github.com/pyloor/b2986ec4b4aed8e82e28


    #Location of JAVA_HOME (bin files)
  4. pyloor revised this gist Jan 6, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Apache Tomcat 8 Start stop script init.d script
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,8 @@
    # this program. If not, see <http://www.gnu.org/licenses/>.
    #
    # Initially forked from: gist.github.com/valotas/1000094
    # Source: gist.github.com/miglen/5590986
    # Forked from: gist.github.com/miglen/5590986
    # Source:


    #Location of JAVA_HOME (bin files)
  5. pyloor revised this gist Jan 6, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Apache Tomcat 8 Start stop script init.d script
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,7 @@ export PATH=$JAVA_HOME/bin:$PATH
    export CATALINA_HOME=/usr/share/tomcat

    #CATALINA_BASE is the location of the configuration files of this instance of Tomcat
    export CATALINA_BASE=/var/apphome/tomcat-node-1
    export CATALINA_BASE=$CATALINA_HOME

    #TOMCAT_USER is the default user of tomcat
    export TOMCAT_USER=tomcat
  6. pyloor revised this gist Jan 6, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Apache Tomcat 8 Start stop script init.d script
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@


    #Location of JAVA_HOME (bin files)
    export JAVA_HOME=/usr/java/latest
    export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

    #Add Java binary files to PATH
    export PATH=$JAVA_HOME/bin:$PATH
  7. @miglen miglen revised this gist Sep 3, 2015. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions Apache Tomcat 8 Start stop script init.d script
    Original file line number Diff line number Diff line change
    @@ -73,8 +73,11 @@ start() {

    status(){
    pid=$(tomcat_pid)
    if [ -n "$pid" ]; then echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m"
    else echo -e "\e[00;31mTomcat is not running\e[00m"
    if [ -n "$pid" ]
    then echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m"
    else
    echo -e "\e[00;31mTomcat is not running\e[00m"
    return 3
    fi
    }

    @@ -132,6 +135,7 @@ case $1 in
    ;;
    status)
    status
    exit $?
    ;;
    kill)
    terminate
  8. @miglen miglen revised this gist Aug 26, 2015. No changes.
  9. @miglen miglen revised this gist Aug 26, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Apache Tomcat 8 Start stop script init.d script
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/bin/bash
    #
    # description: Apache Tomcat control script
    # description: Apache Tomcat init script
    # processname: tomcat
    # chkconfig: 234 20 80
    #
  10. @miglen miglen revised this gist Aug 26, 2015. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Apache Tomcat 8 Start stop script init.d script
    Original file line number Diff line number Diff line change
    @@ -63,6 +63,7 @@ start() {
    then
    /bin/su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
    else
    echo -e "\e[00;31mTomcat user $TOMCAT_USER does not exists. Starting with $(id)\e[00m"
    sh $CATALINA_HOME/bin/startup.sh
    fi
    status
  11. @miglen miglen revised this gist Aug 26, 2015. 1 changed file with 18 additions and 10 deletions.
    28 changes: 18 additions & 10 deletions Apache Tomcat 8 Start stop script init.d script
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,27 @@
    #!/bin/bash
    #
    # description: Tomcat Start Stop Restart
    # description: Apache Tomcat control script
    # processname: tomcat
    # chkconfig: 234 20 80
    #
    # Tomcat 8 start/stop/status init.d script
    # Initially forked from: https://gist.github.com/valotas/1000094
    # @author: Miglen Evlogiev <[email protected]>
    #
    # Release updates:
    # Updated method for gathering pid of the current proccess
    # Added usage of CATALINA_BASE
    # Added coloring and additional status
    # Added check for existence of the tomcat user
    # Added termination proccess
    # Copyright (C) 2014 Miglen Evlogiev
    #
    # This program is free software: you can redistribute it and/or modify it under
    # the terms of the GNU General Public License as published by the Free Software
    # Foundation, either version 3 of the License, or (at your option) any later
    # version.
    #
    # This program is distributed in the hope that it will be useful, but WITHOUT
    # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License along with
    # this program. If not, see <http://www.gnu.org/licenses/>.
    #
    # Initially forked from: gist.github.com/valotas/1000094
    # Source: gist.github.com/miglen/5590986


    #Location of JAVA_HOME (bin files)
    export JAVA_HOME=/usr/java/latest
  12. @miglen miglen revised this gist Aug 26, 2015. No changes.
  13. @miglen miglen revised this gist Aug 26, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Apache Tomcat 8 Start stop script init.d script
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,9 @@
    #!/bin/bash
    #
    # description: Tomcat Start Stop Restart
    # processname: tomcat
    # chkconfig: 234 20 80
    #
    # Tomcat 8 start/stop/status init.d script
    # Initially forked from: https://gist.github.com/valotas/1000094
    # @author: Miglen Evlogiev <[email protected]>
  14. @miglen miglen renamed this gist Sep 4, 2014. 1 changed file with 36 additions and 34 deletions.
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,18 @@
    #!/bin/bash
    #
    # Tomcat 7 start/stop/status script
    # Forked from: https://gist.github.com/valotas/1000094
    # Tomcat 8 start/stop/status init.d script
    # Initially forked from: https://gist.github.com/valotas/1000094
    # @author: Miglen Evlogiev <[email protected]>
    #
    # Release updates:
    # Updated method for gathering pid of the current proccess
    # Added usage of CATALINA_BASE
    # Added coloring and additional status
    # Added check for existence of the tomcat user
    #
    # Added termination proccess

    #Location of JAVA_HOME (bin files)
    export JAVA_HOME=/usr/java/jdk1.7.0_21
    export JAVA_HOME=/usr/java/latest

    #Add Java binary files to PATH
    export PATH=$JAVA_HOME/bin:$PATH
    @@ -21,13 +21,13 @@ export PATH=$JAVA_HOME/bin:$PATH
    export CATALINA_HOME=/usr/share/tomcat

    #CATALINA_BASE is the location of the configuration files of this instance of Tomcat
    export CATALINA_BASE=/usr/share/tomcat5
    export CATALINA_BASE=/var/apphome/tomcat-node-1

    #TOMCAT_USER is the default user of tomcat
    export TOMCAT_USER=tomcat

    #TOMCAT_USAGE is the message if this script is called without any options
    TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"
    TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;31mkill\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"

    #SHUTDOWN_WAIT is wait time in seconds for java proccess to stop
    SHUTDOWN_WAIT=20
    @@ -46,10 +46,10 @@ start() {
    echo -e "\e[00;32mStarting tomcat\e[00m"
    #ulimit -n 100000
    #umask 007
    #/bin/su -p -s /bin/sh tomcat
    #/bin/su -p -s /bin/sh $TOMCAT_USER
    if [ `user_exists $TOMCAT_USER` = "1" ]
    then
    su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
    /bin/su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
    else
    sh $CATALINA_HOME/bin/startup.sh
    fi
    @@ -64,13 +64,18 @@ status(){
    else echo -e "\e[00;31mTomcat is not running\e[00m"
    fi
    }


    terminate() {
    echo -e "\e[00;31mTerminating Tomcat\e[00m"
    kill -9 $(tomcat_pid)
    }

    stop() {
    pid=$(tomcat_pid)
    if [ -n "$pid" ]
    then
    echo -e "\e[00;31mStoping Tomcat\e[00m"
    #/bin/su -p -s /bin/sh tomcat
    #/bin/su -p -s /bin/sh $TOMCAT_USER
    sh $CATALINA_HOME/bin/shutdown.sh

    let kwait=$SHUTDOWN_WAIT
    @@ -83,8 +88,8 @@ stop() {
    done

    if [ $count -gt $kwait ]; then
    echo -n -e "\n\e[00;31mkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\e[00m"
    kill -9 $pid
    echo -n -e "\n\e[00;31mkilling processes didn't stop after $SHUTDOWN_WAIT seconds\e[00m"
    terminate
    fi
    else
    echo -e "\e[00;31mTomcat is not running\e[00m"
    @@ -102,27 +107,24 @@ user_exists(){
    }

    case $1 in

    start)
    start
    ;;

    stop)
    stop
    ;;

    restart)
    stop
    start
    ;;

    status)
    status

    ;;

    *)
    echo -e $TOMCAT_USAGE
    ;;
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    stop
    start
    ;;
    status)
    status
    ;;
    kill)
    terminate
    ;;
    *)
    echo -e $TOMCAT_USAGE
    ;;
    esac
    exit 0
  15. @miglen miglen renamed this gist May 16, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  16. @miglen miglen revised this gist May 16, 2013. 1 changed file with 90 additions and 64 deletions.
    154 changes: 90 additions & 64 deletions tomcat.sh
    Original file line number Diff line number Diff line change
    @@ -1,102 +1,128 @@
    #!/bin/bash
    #
    # tomcat7 This shell script takes care of starting and stopping Tomcat
    # Tomcat 7 start/stop/status script
    # Forked from: https://gist.github.com/valotas/1000094
    # @author: Miglen Evlogiev <[email protected]>
    #
    # chkconfig: - 80 20
    # Release updates:
    # Updated method for gathering pid of the current proccess
    # Added usage of CATALINA_BASE
    # Added coloring and additional status
    # Added check for existence of the tomcat user
    #
    ### BEGIN INIT INFO
    # Provides: tomcat7
    # Required-Start: $network $syslog
    # Required-Stop: $network $syslog
    # Default-Start:
    # Default-Stop:
    # Description: Release implementation for Servlet 2.5 and JSP 2.1
    # Short-Description: start and stop tomcat
    ### END INIT INFO

    ## Source function library.
    #. /etc/rc.d/init.d/functions
    export JAVA_HOME=/usr/java/default
    export JAVA_OPTS="-Dfile.encoding=UTF-8 \
    -Dcatalina.logbase=/var/log/tomcat7 \
    -Dnet.sf.ehcache.skipUpdateCheck=true \
    -XX:+DoEscapeAnalysis \
    -XX:+UseConcMarkSweepGC \
    -XX:+CMSClassUnloadingEnabled \
    -XX:+UseParNewGC \
    -XX:MaxPermSize=128m \
    -Xms512m -Xmx512m"

    #Location of JAVA_HOME (bin files)
    export JAVA_HOME=/usr/java/jdk1.7.0_21

    #Add Java binary files to PATH
    export PATH=$JAVA_HOME/bin:$PATH
    TOMCAT_HOME=/usr/share/tomcat7

    #CATALINA_HOME is the location of the bin files of Tomcat
    export CATALINA_HOME=/usr/share/tomcat

    #CATALINA_BASE is the location of the configuration files of this instance of Tomcat
    export CATALINA_BASE=/usr/share/tomcat5

    #TOMCAT_USER is the default user of tomcat
    export TOMCAT_USER=tomcat

    #TOMCAT_USAGE is the message if this script is called without any options
    TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"

    #SHUTDOWN_WAIT is wait time in seconds for java proccess to stop
    SHUTDOWN_WAIT=20

    tomcat_pid() {
    echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
    echo `ps -fe | grep $CATALINA_BASE | grep -v grep | tr -s " "|cut -d" " -f2`
    }

    start() {
    pid=$(tomcat_pid)
    if [ -n "$pid" ]
    if [ -n "$pid" ]
    then
    echo "Tomcat is already running (pid: $pid)"
    echo -e "\e[00;31mTomcat is already running (pid: $pid)\e[00m"
    else
    # Start tomcat
    echo "Starting tomcat"
    ulimit -n 100000
    umask 007
    /bin/su -p -s /bin/sh tomcat $TOMCAT_HOME/bin/startup.sh
    echo -e "\e[00;32mStarting tomcat\e[00m"
    #ulimit -n 100000
    #umask 007
    #/bin/su -p -s /bin/sh tomcat
    if [ `user_exists $TOMCAT_USER` = "1" ]
    then
    su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
    else
    sh $CATALINA_HOME/bin/startup.sh
    fi
    status
    fi


    return 0
    }


    status(){
    pid=$(tomcat_pid)
    if [ -n "$pid" ]; then echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m"
    else echo -e "\e[00;31mTomcat is not running\e[00m"
    fi
    }

    stop() {
    pid=$(tomcat_pid)
    if [ -n "$pid" ]
    then
    echo "Stoping Tomcat"
    /bin/su -p -s /bin/sh tomcat $TOMCAT_HOME/bin/shutdown.sh

    echo -e "\e[00;31mStoping Tomcat\e[00m"
    #/bin/su -p -s /bin/sh tomcat
    sh $CATALINA_HOME/bin/shutdown.sh

    let kwait=$SHUTDOWN_WAIT
    count=0;
    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
    do
    echo -n -e "\nwaiting for processes to exit";
    echo -n -e "\n\e[00;31mwaiting for processes to exit\e[00m";
    sleep 1
    let count=$count+1;
    done

    if [ $count -gt $kwait ]; then
    echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
    echo -n -e "\n\e[00;31mkilling processes which didn't stop after $SHUTDOWN_WAIT seconds\e[00m"
    kill -9 $pid
    fi
    else
    echo "Tomcat is not running"
    echo -e "\e[00;31mTomcat is not running\e[00m"
    fi

    return 0
    }


    user_exists(){
    if id -u $1 >/dev/null 2>&1; then
    echo "1"
    else
    echo "0"
    fi
    }

    case $1 in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    stop
    start
    ;;
    status)
    pid=$(tomcat_pid)
    if [ -n "$pid" ]
    then
    echo "Tomcat is running with pid: $pid"
    else
    echo "Tomcat is not running"
    fi
    ;;

    start)
    start
    ;;

    stop)
    stop
    ;;

    restart)
    stop
    start
    ;;

    status)
    status

    ;;

    *)
    echo -e $TOMCAT_USAGE
    ;;
    esac
    exit 0
  17. @valotas valotas created this gist May 31, 2011.
    102 changes: 102 additions & 0 deletions tomcat.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,102 @@
    #!/bin/bash
    #
    # tomcat7 This shell script takes care of starting and stopping Tomcat
    #
    # chkconfig: - 80 20
    #
    ### BEGIN INIT INFO
    # Provides: tomcat7
    # Required-Start: $network $syslog
    # Required-Stop: $network $syslog
    # Default-Start:
    # Default-Stop:
    # Description: Release implementation for Servlet 2.5 and JSP 2.1
    # Short-Description: start and stop tomcat
    ### END INIT INFO

    ## Source function library.
    #. /etc/rc.d/init.d/functions
    export JAVA_HOME=/usr/java/default
    export JAVA_OPTS="-Dfile.encoding=UTF-8 \
    -Dcatalina.logbase=/var/log/tomcat7 \
    -Dnet.sf.ehcache.skipUpdateCheck=true \
    -XX:+DoEscapeAnalysis \
    -XX:+UseConcMarkSweepGC \
    -XX:+CMSClassUnloadingEnabled \
    -XX:+UseParNewGC \
    -XX:MaxPermSize=128m \
    -Xms512m -Xmx512m"
    export PATH=$JAVA_HOME/bin:$PATH
    TOMCAT_HOME=/usr/share/tomcat7
    SHUTDOWN_WAIT=20

    tomcat_pid() {
    echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
    }

    start() {
    pid=$(tomcat_pid)
    if [ -n "$pid" ]
    then
    echo "Tomcat is already running (pid: $pid)"
    else
    # Start tomcat
    echo "Starting tomcat"
    ulimit -n 100000
    umask 007
    /bin/su -p -s /bin/sh tomcat $TOMCAT_HOME/bin/startup.sh
    fi


    return 0
    }

    stop() {
    pid=$(tomcat_pid)
    if [ -n "$pid" ]
    then
    echo "Stoping Tomcat"
    /bin/su -p -s /bin/sh tomcat $TOMCAT_HOME/bin/shutdown.sh

    let kwait=$SHUTDOWN_WAIT
    count=0;
    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
    do
    echo -n -e "\nwaiting for processes to exit";
    sleep 1
    let count=$count+1;
    done

    if [ $count -gt $kwait ]; then
    echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
    kill -9 $pid
    fi
    else
    echo "Tomcat is not running"
    fi

    return 0
    }

    case $1 in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    stop
    start
    ;;
    status)
    pid=$(tomcat_pid)
    if [ -n "$pid" ]
    then
    echo "Tomcat is running with pid: $pid"
    else
    echo "Tomcat is not running"
    fi
    ;;
    esac
    exit 0