Skip to content

Instantly share code, notes, and snippets.

@imesh
Last active August 20, 2017 11:32
Show Gist options
  • Select an option

  • Save imesh/c8f5ca82b193130611289b05d162fa9d to your computer and use it in GitHub Desktop.

Select an option

Save imesh/c8f5ca82b193130611289b05d162fa9d to your computer and use it in GitHub Desktop.

Revisions

  1. imesh revised this gist Aug 20, 2017. No changes.
  2. imesh created this gist Aug 20, 2017.
    46 changes: 46 additions & 0 deletions install-tomcat.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #!/bin/bash

    sudo apt-get update
    sudo apt-get install default-jdk
    sudo groupadd tomcat
    sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

    wget http://www-eu.apache.org/dist/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz
    sudo tar -xzvf apache-tomcat-8.5.20.tar.gz
    mv apache-tomcat-8.5.20 /opt/tomcat

    sudo chgrp -R tomcat /opt/tomcat
    sudo chown -R tomcat /opt/tomcat
    sudo chmod -R 755 /opt/tomcat

    cat > /etc/systemd/system/tomcat.service <<EOF
    [Unit]
    Description=Apache Tomcat Web Server
    After=network.target
    [Service]
    Type=forking
    Environment=JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/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=/opt/tomcat/bin/shutdown.sh
    User=tomcat
    Group=tomcat
    UMask=0007
    RestartSec=15
    Restart=always
    [Install]
    WantedBy=multi-user.target
    EOF

    sudo systemctl daemon-reload
    sudo systemctl start tomcat
    sudo systemctl status tomcat