Setting Up a Linux Environment for Decoupled Web Applications
Java Runtime Environment Setup
Transfer the JDK binary package to a temporary workspace and create a dedicated directory under the system partition.
mkdir -p /opt/dev/java
tar -xzf /tmp/deliverables/jdk-8u401-x64.tar.gz -C /opt/dev/java
mv /opt/dev/java/jdk1.8.0_* /opt/dev/java/sdk-root
Configure the execution environment by appending variable declarations to the global profile configuration. Using a dedicated script inside /etc/profile.d/ prevents clutter and isolates language settings.
sudo tee /etc/profile.d/jdk_env.sh > /dev/null << 'SETUP'
JVM_ROOT=/opt/dev/java/sdk-root
export JAVA_HOME="${JVM_ROOT}"
export CLASSPATH=".:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib"
export PATH="${JAVA_HOME}/bin:${PATH}"
SETUP
source /etc/profile.d/jdk_env.sh
Confirm the installation by querying the compiler version.
java -version
Web Container Deployment
Extract the servlet container archive into a cenntralized services directory.
mkdir -p /opt/web/containers
tar -xzf /tmp/deliverables/tomcat-8.5.24.tar.gz -C /opt/web/containers
Launch the container by executing the bootstrap script located in the binaries folder.
cd /opt/web/containers/apache-tomcat-8.5.24/bin
chmod +x *.sh
./startup.sh
Modify the host firewalll policies to permit inbound connections on the default listening port.
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --zone=public --list-ports
To insure the web server initializes automatically following a system reboot, register it as a daemon. Create a management wrapper that defines the container paths and delegates control signals to the native scripts.
#!/bin/bash
# description: Auto-starts Tomcat servlet engine
# chkconfig: 345 85 15
APP_BASE="/opt/web/containers/apache-tomcat-8.5.24"
RUNTIME_DIR="/opt/dev/java/sdk-root"
export JAVA_HOME="${RUNTIME_DIR}"
invoke_action() {
case "${1}" in
start)
"${APP_BASE}/bin/startup.sh"
;;
stop)
"${APP_BASE}/bin/shutdown.sh"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
}
invoke_action "$1"
exit $?
Install the wrapper into the initialization sequence and enable persistent execution.
cp /opt/web/containers/apache-tomcat-8.5.24/bin/daemon_ctl.sh /etc/init.d/tomcat_svc
chmod 755 /etc/init.d/tomcat_svc
chkconfig --add tomcat_svc
chkconfig tomcat_svc on