Infrastructure as code homework #1
Tags: linux, devops
Published: 2020-10-01 17:16:24

---
title: Infrastructure as code homework #1
published: true
date: 2020-09-21 15:00:00 UTC
tags: linux, devops
canonical_url: https://katiekodes.com/sysadmin-studies-01/
---

I’d like to get involved in a project at work that involves taking a tool comprised of a lot of databases and web servers _(running Java in Apache Tomcat)_ and putting them into “the cloud” using best-practice architectures for installation, upgrade, maintenance, patching, backup, & recovery considerations.  
  
After reading [this helpful background about Tomcat](https://secureanycloud.com/tomcat-technical-support-cloud-help-azure-aws-opensource-cognosys/) by Secure Any Cloud, I think I’ve just come up with my first “hello world” homework assignment.

## The plan

- Rent a machine from a cloud service with which I have some free credits.    
  - Always use Terraform to control working with the cloud service; avoid cloud-service-specific tools & GUIs as much as possible.
- Install & run Linux, Java, & Tomcat hosting [Apache’s `sample.war` file](https://tomcat.apache.org/tomcat-8.0-doc/appdev/sample/) on a non-8080 port.    
  - Always use Git & continuous integration/deployment tools _(Ansible? Jenkins?)_ & container images _(Kubernetes? Docker?)_ rather than SSHing / SFTPing into the rented machine’s CLI or clicking around in GUI configuration panels when possible.
- Make sure `sample` has a public IP address – maybe even a public domain name to be snazzy.    
  - Continue to pay attention to tooling & automation / infrastructure-as-code.
- Visit `http://...:xxxx/sample/` from my home computer to confirm it’s alive and on the web.
- Kill the server & deallocate any IP / domain names gracefully.    
  - Always use Terraform to control working with the cloud service; avoid cloud-service-specific tools & GUIs as much as possible.

## The accomplishment

According to one of my colleagues, the jargon I can say I’m studying is:

1. Provisioning a server in the cloud
2. Deploying an application to that server

It’s nice to have goals & a plan.

* * *

## Misc

Some notes I took from Secure Any Cloud’s article that led to me making this plan:

- A lot of what a 3rd-party vendor will be providing my workplace is WAR files for services running Apache Tomcat.
- Tomcat’s been around since 1998.
- Tomcat operates only on the HTTP protocol.
- Tomcat processes _(provides a runtime environment for the Java code within)_ Java servlets, encapsulating code & business logic to define how requests & responses should be handled by a server.    
  - “Servlet” is an API from the Java Platform Enterprise Engine designed to work _with_ web servers.
  - Monitoring a server for incoming client requests is the web server’s job, not hte servlet’s.
  - “web.xml” maps servlet classes to incoming cloient requests.
  - Servlets are responsible for providing responses back to Tomcat as JSP pages.
- Tomcat processes JSP pages.    
  - Java is a server-side view rendering technology _(Salesforce Visualforce Pages are based off of it, I believe)_.
  - Tomcat returns responses back to a client by rendering the JSP pages that servlets hand off to it.
- As a developer, our 3rd-party vendor would’ve written the servlets or JSP’s and let Tomcat handle routing.
- Tomcat provides a port 8080 connector _(Coyote engine?)_ for serving stuff over HTTP; can’t tell if that’s related to all this.
- On Windows, you’d install a JDK and then GUI-install Tomcat, pointing it at your JRE & detailing some things like port 8080 for HTTP during install.    
  - It would likely install to `C:\Tomcat8`, which is where you’d likely think of `CATALINA_HOME` and `CATALINA_BASE` referring to in documentation.
- Look in `server.xml` to be sure what the “application base directory” _(e.g. `CATALINA_HOME/webapps`)_ is – likely `C:\Tomcat8\webapps`.    
  - That’s wher you’ll drop `.war` files _(with the server stopped)_.
- There’s a file in `CATALINA_BASE/conf/` _(on Windows, likely `C:\Tomcat8\conf\`)_ called `tomcat-users.xml` that it seems you can add data to to make web sites present an authentication wall _(again, edit with the server stopped)_.
- As with most web servers, the typical way to see if they’re reunning well is to visit `http://localhost:XXXX/whatever/` in a web browser from the same box.

All this sounds like I’ve had to manage the installion/upgrade/configuration of:

1. An operating system
2. Java
3. Apache Tomcat

_(Some sort of driver for talking to a database, like JDBC, would probably be #4 in a more real-world-like setup. More to explore later.)_

Infrastructure as code / containerization with Docker/Kubernetes can help. Or so I’d think.

Note: per some GitHub repos I was looking at, containers can be configured themselves to be direct-connected to or to be behind a load balancer. More to explore for another day.