Installing Tomcat as a service

Talend Real-time Big Data Platform Installation Guide for Linux

EnrichVersion
6.4
EnrichProdName
Talend Real-Time Big Data Platform
task
Installation and Upgrade
EnrichPlatform
Talend Artifact Repository
Talend Log Server
Talend Data Stewardship
Talend Administration Center
Talend Studio
Talend SAP RFC Server
Talend DQ Portal
Talend CommandLine
Talend Installer
Talend ESB
Talend Runtime
Talend Repository Manager
Talend Data Preparation
Talend JobServer
Talend Activity Monitoring Console
Talend Identity Management
Talend Project Audit

Installing the service on RedHat/CentOS 7 Systems

All the following commands have to be executed with super-user privileges.

  1. Create the service file with the following command:

    touch /etc/systemd/system/tomcat.service

  2. Assign the relevant rights to the file you created:

    chmod 664 /etc/systemd/system/tomcat.service

  3. Paste the following content in the file while adapting it to your configuration:

    [Unit]
    Description=Apache Tomcat Web Application Container
    After=syslog.target network.target
    
    [Service]
    Type=forking
    
    Environment=JAVA_HOME=/usr/lib/jvm/jre
    Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
    Environment=CATALINA_HOME=/opt/tomcat
    Environment=CATALINA_BASE=/opt/tomcat
    Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
    Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
    
    ExecStart=/opt/tomcat/bin/startup.sh
    ExecStop=/bin/kill -15 $MAINPID
    
    [Install]
    WantedBy=multi-user.target
  4. Reload the service daemon:

    systemctl daemon-reload

  5. Start the service:

    systemctl start tomcat.service

Installing the service on RedHat/CentOS 6 and Ubuntu Systems

  1. Create/Copy the following script to the /etc/init.d/tomcat file:

    # chkconfig: 345 91 10
    # description: Starts and stops the Tomcat daemon.
    #
    
    # Source function library.
    . /etc/rc.d/init.d/functions
    
    # Get config.
    . /etc/sysconfig/network
    
    # Check that networking is up.
    [ "${NETWORKING}" = "no" ] && exit 0
    
    user=cxp
    tomcat=/u/bin/Tomcat/apache-tomcat-8.0.33/
    startup=$tomcat/bin/startup.sh
    shutdown=$tomcat/bin/shutdown.sh
    #export JAVA_HOME=/usr/local/java
    
    status(){
    ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start"
    | awk '{printf $1 " "}' | wc | awk
    '{print $2}' > /tmp/tomcat_process_count.txt
    read line < /tmp/tomcat_process_count.txt
    if [ $line -gt 0 ]; then
    echo -n "tomcat ( pid "
    ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start"
    | awk '{printf $1 " "}'
    echo -n ") is running..."
    echo
    else
    echo "Tomcat is stopped"
    fi
    }
    
    start(){
     echo -n $"Starting Tomcat service: "
     #daemon -c
     su - $user -c "$startup" 
     RETVAL=$?
     echo
    }
    
    stop(){
     action $"Stopping Tomcat service: " su - $user "$shutdown"
     RETVAL=$?
     echo
    }
    
    restart(){
      stop
      start}

    # See how we were called.
    case "$1" in
    start)
     start
     ;;
    stop)
     stop
     ;;
    status)
          
     status tomcat
     ;;
    restart)
     restart
     ;;
    *)
     echo $"Usage: $0 {start|stop|status|restart}"
     exit 1
    esac
    
    exit 0

  2. Edit the user and tomcat variable values in the script to match your configuration.

  3. To make sure that the script is executable, type:

    # chmod 0755 /etc/init.d/tomcat

  4. Type in:

    chkconfig --list

    chkconfig --add tomcat

    Now, you can test this self-defined service.