How Do You Browse .eml Files?

Problem scenario
You have some .eml files (e.g., emails from a web-based email account) that you want to view. How do you display them for free?

Solution

  1. Install Thunderbird (e.g., on Windows or Linux).
  2. Configure Thunderbird with an email account (e.g., gmail). It seems to work when you configure it with any old email account. Without an email account, I do not know if it will work.
  3. Create a special folder under the Inbox section.
  4. Place your .eml files in this new folder.

How Do You Set up Nginx as an HTTP Load Balancer So Client Requests (from Web Browsers) Do Not Go to Certain Nginx Servers unless Others Are Down?

Problem scenario
You have a web server running Nginx that acts as a reverse proxy server.  On occasion your regular web (Nginx) servers go down.  You want to have one or two web (Nginx) servers that are  reserved as backups exclusively.  You do not want traffic going to these servers unless the main Nginx servers are unavailable (either due to network or server failure).  You can allocate RAM and CPU to these reserved servers on demand.  To save money the business wants these servers with few resources unless they are brought online.  How do you have Nginx convey traffic to other Nginx  servers only when the main Nginx servers are down?

Solution
Prerequisite

You must have configured Nginx as a an HTTP load balancer (or reverse proxy server).  To do this, see this article which will actually work for Nginx distributing traffic to regular Nginx websites, Apache websites, or Nginx  websites running in Docker containers. 

Procedures
In the default.conf file, use the "backup" directive near the servers' FQDNs or IP addresses as they appear in the "upstream backend" clause (within the braces of "upstream backend {}").

This "backup" designation is performed with Nginx in Docker containers the same way it is done with Nginx running directly on a server.  Arguably one difference would be that the IP address you use in the default.conf file is an internal IP address associated with the user defined Docker network.

To find the IP address that would be ideal when you know the container ID of the Nginx instance you want to be a back up, you could use this command:

docker inspect <containerID> | grep IPAddress | tail -n 1

That would give you the internal IP address of the Docker container of your Nginx instance.

The Nginx instance with the landing page should have a default.conf file (in /etc/nginx/conf.d/default.conf).  Here is an example of two Nginx servers reserved as "backup" in the default.conf file:

upstream backend {
  server 10.10.10.10;
  server 10.10.10.11;
  server 10.10.10.12 backup;
  server 10.10.10.13 backup;
}

These "backup" keywords do take take effect until you stop Nginx services and restart them.  These keywords work with Nginx running in Docker no differently from Nginx running directly on a server.

FFR
If you want to need to troubleshoot problems with your Nginx load balancer, see this link.

In Linux without the Internet, How Do You Enter Left Double Quotes (“) or Right Double Quotes (”)?

Problem scenario
You are trying to search a file for left double quotes and right double quotes (e.g., using a Linux command terminal or a vi editor). How do you enter left double quotes or right double quotes using a keyboard (without copying the apparently italicized double quotes from a web page)?

Solution
Hold Alt, and then enter the sequence 8220 for left double quotes.

Hold Alt, and then enter the sequence 8221 for right double quotes.

How Do You Write a Python Program to Test if a Word is a Substring of Another Word?

Problem scenario
You want to write a program that will test if a pattern is in another word. You are looking for the SQL equivalent of "contains" in Python. How do you test if a string is a substring of another word?

Solution
Use this program:

# Change "micro" and "microsoft" to the substring and string to be searched respectively:

a = "micro"
b = "microsoft"
if a in b:
  print(a + " is in " + b)
else:
  print(a + " is NOT in " + b)

How Do You Find the URL of Your Kubernetes Cluster?

Problem scenario
You want to view the website that is powered by Kubernetes. But you do not know which URL to go to. What should you do from the back-end server with kubectl?

Solution

1. Run this: kubectl get services
With the resulting output, find a name that you want the URL for. (Services have names.) Let's assume the name was "foobar".

2. Run this command: kubectl get service foobar -o wide

The resulting output should include an "EXTERNAL-IP" value that you can use.

How Do You Troubleshoot the Error “Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock”?

Problem scenario
You try to run a Docker command, but you get this error: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.29/containers/json?all=1: dial unix /var/run/docker.sock: connect: permission denied

What should you do?

Solution
Have you added the user who was trying to execute the command to the "docker" group?

This command would add the user jdoe to the "docker" group:
sudo usermod -aG docker jdoe

If you ran the above command as the jdoe user, log out and log back in.

It is not advisable to run "docker" commands with "sudo " before them. In rare cases it may be necessary to use it to get the "docker" command to work.

For troubleshooting similar errors you may want to click on one of the following:

How Do You Get a PHP Script to Invoke a Bash Command?

Problem scenario
You are trying to get a PHP file to invoke a bash script. When you run it from the command line with "php foobar.php" you just see the content of the PHP file. What do you do to get PHP to invoke a bash script?

Solution
Make sure you have the correct header and closing symbols. Here is the content of foobar.php:

<?php
exec('bash /var/www/html/testScript.sh');
?>

To run it, do this: php foobar.php

What Is a docker-compose.yml File?

Question
What is a docker-compose.yml file?

Answer
It is a file used by the docker-compose utility which orchestrates the creation of multiple containers. For microservices, SOA and various stacks of applications (e.g., the LAMP stack), container orchestration is useful. Here are some quotes which help elucidate what docker-compose does:

"Compose is a tool for defining and running multi-container Docker applications." (Taken from Docker's website.)

"In order to do something useful with containers, they have to be arranged as part of a project, usually referred to as an ‘application’. This is what a docker-compose.yml file does, specifying what images are required, what ports they need to expose, whether the have access to the host filesystem, what commands should be run, and so on." (Taken from Divio.com.)

"A docker-compose.yml file is a YAML file that defines how Docker containers should behave in production." (Taken from Docker's website.)

The docker-compose is "a command-line utility to define and run multicontainer applications with Docker." taken from page 198 from The Docker Cookbook by Goasguen.

The docker-compose utility looks for and uses a docker-compose.yml file in the directory that you run the "docker-compose" command. This utility supports the keyword "depends" in the docker-compose.yml file. This "depends" conditions a container starting on another container starting. If you run "docker-compose up foobar" (where foobar is a service in the docker-compose.yml file), the command will start the services that "foobar" depends on, as designated in the docker-compose.yml file. Without specifying a service name, the docker-compose up command will start all of the services.

Here is an example of a docker-compose.yml file:

version: '3'
 services:
   db:
      image: mysql
      container_name: mysql_db
      restart: always
      environment:
         - MYSQL_ROOT_PASSWORD="secret"
   web:
     image: apache
     build: ./webapp
     depends_on:
        - db
     container_name: apache_web
     restart: always
     ports:
       - "8080:80"

The above was taken from from Tecadmin.net.

If you want to try a docker-compose.yml file out, see this posting.

To learn more about the file itself and its reserved words, see this.

How Do You Troubleshoot Jenkins Pipelines Not Running when You Try to Execute Them?

Problem scenario
Your Jenkins pipeline jobs will not run. You see "Build Scheduled" when you click on the "Build now" link. But nothing happens. You see an error that your /var/lib/jenkins/ is running low on disk space. You have no access to the back-end of the server that runs Jenkins. What should you do?

Solution
Look at the dashboard view. Next to the date and time of the most recent success of the job (build, project or pipeline) will be an integer number (e.g., 1, 53, 840 etc.). Find a job that has the largest integer value. See if you can delete the previous builds -- or more efficiently, delete the entire project. It may take 30 minutes, but eventually this will free up disk space.

How Do You Use a PowerShell Command to Stop an Azure VM?

Problem scenario
You have a server in Azure you want to turn off. What should you do to stop it?

Solution
Prerequisite
You need to know the server's name and resource group. You can do this by finding the server in the Azure Portal.

Procedures
Run this command:

Stop-AzureRmVM -ResourceGroupName $nameOfResourceGroup -Name $nameOfVM

# Replace $nameOfResourceGroup with the name of the Resource Group.  Replace $nameOfVM with the name of the the VM.