How Do You Troubleshoot the Error “intx ThreadPriorityPolicy=42 is outside the allowed range [ 0 … 1 ] “?

Problem scenario
You try to start Cassandra but you get this error:

"[0.000s][warning][gc] -Xloggc is deprecated. Will use -Xlog:gc:./bin/../logs/gc.log instead.
intx ThreadPriorityPolicy=42 is outside the allowed range [ 0 ... 1 ]
Improperly specified VM option 'ThreadPriorityPolicy=42'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit."

Possible solution #1
Migrate to Linux SUSE or a Red Hat family version of Linux (e.g., CentOS, RHEL or Fedora).  We have only seen this problem with Ubuntu Linux.

Possible solution #2
Remove Java version 9 and install Java version 8.  To do this (assuming that they were installed via apt-get commands), run these commands:

sudo apt-get -y remove openjdk-9-jre-headless
sudo apt-get -y update
sudo apt -y install openjdk-8-jre-headless gcj-4.8-jre-headless default-jdk

How Do You Use a Generator and the Yield Keyword in Python?

Problem scenario
You want to use a generator in Python.  You also want to use the yield keyword in Python.  How do you use these?

Solution
The short answer to the question about how do you use a generator is to create a function with the yield keyword (source Programiz.com).  "Both yield and return will return some value from a function."  (The source of this quote is Programiz.com.)

A Python generator is in essence a coroutine.  Coroutines enable intelligent control between two different parts of a program (e.g., a cooperative process that interleaves the invocation of one part of the code to return to another section of the code and thus re-enter it with a dynamic value that has been precomputed).  A generator has discrete steps of iteration which can be executed with the "next" keyword.  The "yield" keyword is like a return statement without necessarily being final.  The execution of a generator will provide intermediate values with its yield statement(s) and continue with calls with the "next" keyword.   The "yield" and "next" keywords are important for using the generator feature in Python.  This program below illustrates how to use the "yield" and "next" keywords; this simple program below also demonstrates how to use a generator.

# Call this program gen.py.  Run it with "python gen.py" (with no quotes).
# Examine the output and you will see how yield works like a return statement without the finality.
# This program uses a Python generator.  Note that you do not need the use the word "generator"
# in the function definition.  It can be helpful for readability, but Python knows what to do by merely
# using the word "yield" inside the function.

def continual_generator_func():
  yield 1
  yield 2
  yield 3
  yield 4 
tempobject = continual_generator_func();
a = next(tempobject)
next(tempobject)
next(tempobject)
b = next(tempobject)
print(a)
print(b)

How Do You Create Your Own Dockerfile to Create a Flask Application?

Problem scenario
You want to use Flask inside a Docker container.  You want to build your own image for the Docker container.  How do you create your own Dockerfile to create a Flask application?

Solution
Prerequisite

Install Docker.  See this posting if you need directions.

Procedures
1.  Create a Dockerfile with the following content (you may want to replace "16.04" with "latest" and if you want to change the location of where the .py file is, that may or may not be troublesome):

FROM ubuntu:16.04  

RUN apt-get update
RUN apt-get install -y python3 python-pip
RUN apt-get clean all

RUN pip install flask

ADD hello.py /tmp/hello.py

EXPOSE 5000

CMD ["python","/tmp/hello.py"]  

2.  In the directory that the Dockerfile will go, create a file called hello.py with the following content:

from flask import Flask
app = Flask(__name__)

@app.route('/hi')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

3.  Run this command in the directory with the above files:

docker build -t flask .

(On a server with .5 GB of RAM and 1 shared vCPU, this can take 20 minutes.)

4.  Then run this command:  docker run -d -P flask

5.  Test it from the Docker host.  Run this command:  docker ps -a

Find the result for a recently created container.  The "PORTS" column should have a mapping to the port 5000.  Use the non-5000 port (in the output of the command above) and construct this Linux command below (but replace xxxxx with that port number in the following draft of a command):

curl http://localhost:xxxxx/hi

6.  Run the curl command above once you substitute the xxxxx.  You should see "Hello World!"

How Do You Install Ansible on a Debian Linux Server Running in GCP?

Problem scenario
You are using Google Cloud Platform, and you have a Debian server.  You do not want to configure any PPAs for your system.*  How do you install and configure Ansible on a Debian Linux system?

Solution
Prerequisite

We strongly recommend having 2.5 GB of memory (either in RAM or with a combination of RAM and swap space).   For directions on how to configure swap space in the amount of 2 GB, see this posting.  You can get Ansible installed with 0.6 GB of memory.  But we do not think the performance would be acceptable with this configuration.

Procedures
1.a.  Create a script called ansible.sh in /tmp.

1.b.  Have this as the content:

apt-get -y update
apt-get -y install git python-setuptools gcc python-dev libffi-dev python-openssl make
cd /opt
git clone git://github.com/ansible/ansible.git --recursive
cd ansible
python setup.py build
python setup.py install  

2.  Run this script like this:  sudo bash /tmp/ansible.sh

3.  Test it was successful:  ansible --version

*  If you want to try to configure a PPA on Ubuntu Linux, see this external article (https://www.cyberciti.biz/faq/how-to-install-and-configure-latest-version-of-ansible-on-ubuntu-linux/).  If you want to try to configure a PPA on a Debian Linux system, you can use this external link at your own risk.

How Do You Use GCP’s App Engine?

Problem scenario
You want to leverage GCP's serverless App Engine component with its scalability.  What do you do?

Solution
1.  Go to the cloud shell.  In the web UI of GCP in the upper righthand corner go to the icon that looks like this: ">_" and click on it.  From cloud shell run these commands:

git clone https://github.com/GoogleCloudPlatform/python-docs-samples

cd python-docs-samples/appengine/standard_python37/hello_world

virtualenv --python python3 ~/envs/hello_world

source ~/envs/hello_world/bin/activate

pip install -r requirements.txt

python main.py

2.  In the upper righthand corner there are several icons.  When you hover over each one, a pop-up will say something.  Click the icon for which "Web preview" appears.  Then choose "Preview on port 8080".  If it opens a new web browser tab that says "Hello World!", then it worked.

3.  Back at the cloud shell, hold the control key and tap "c" (ctrl-c).

4.  Run this command: gcloud app create
(Do not be alarmed by the error "already contains an App Engine".  Just proceed to the next step.)

5.a.  Run this command (but replace contint with the ID of your project*):

gcloud app deploy app.yaml --project contint

5.b.  If you are asked if you want to continue, choose "Y" and press enter.

5.c.  Run this command:  gcloud app browse

6.  Click on the URL that appears in the cloud shell.  It should take you to a new tab in the web browser.  It should say "Hello World!"

* If you want to find the ID of your project, from the GCP web UI, go to "My First Project" or something similar at the top middle part of the screen.  Click on it.  The pop up should show the project IDs according to their names.

How Do You Create a Docker Image That Has Java 10 in It?

Problem scenario
You want to create Docker containers with Java 9.  How do you create a Docker image to make containers with Java 9 installed in them?

These directions were updated on 12/26/18.

Solution
Prerequisite

This assumes that you have Docker installed. If you need assistance with this, see these postings depending on your operating system:

Debian/Ubuntu
CentOS/Fedora/RHEL
SUSE

Procedures
1.  Create a filed called Dockerfile with the following content:

FROM ubuntu:latest
MAINTAINER NAME EMAIL

RUN apt-get -y update && apt-get -y upgrade && apt-get install -y build-essential openjdk-11-jre-headless

2.  Run this command: 

docker build -t "java:java" .

# You should see an image ID.  If you need to find out later, use "docker images" to find it.

# You are now done.

3.  This step is optional if you want to create a container and enter it.  Run these commands:

docker create -it <ImageID> bash

# You should see a container ID.  If you need to find out later, use "docker ps -a"

docker start <containerID>

docker exec -it <containerID> bash

If the above directions do not work with RHEL, please post a comment. You do not need to use your real name.

How Do You Troubleshoot the SonarQube Service Not Working with a “vendor preset: disabled” Error?

Problem scenario
The SonarQube service failed to start.  

You see this message:

? sonar.service - SonarQube service
   Loaded: loaded (/etc/systemd/system/sonar.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Mon 2018-05-21 14:34:34 UTC; 12min ago

May 21 14:34:33 sonarserver systemd[1]: Started SonarQube service.
May 21 14:34:34 sonarserver systemd[1]: sonar.service holdoff time over, scheduling restart.
May 21 14:34:34 sonarserver systemd[1]: start request repeated too quickly for sonar.service
May 21 14:34:34 sonarserver systemd[1]: Failed to start SonarQube service.
May 21 14:34:34 sonarserver systemd[1]: Unit sonar.service entered failed state.
May 21 14:34:34 sonarserver systemd[1]: sonar.service failed.

What do you do?

Possible solution #1
1.  Install Java.  If you need assistance, see this posting.

2.  Then run these commands:
sudo systemctl enable sonar
sudo systemctl start sonar

Possible solution #2
Use the "-l" flag when you check the status.   This allows you to see longer lines for details.  Try to resolve the problem based on the verbose output of this command:  sudo systemctl status sonar -l

How Do You Write a BubbleSort Algorithm in Python That Runs in O(n) in a Best Case Scenario?

Problem scenario
You want to use BubbleSort in Python that runs in O(n) time when the list to be sorted is already in perfect order.  How do you write such a program?

Solution
Use this code for BubbleSort with a refinement:

def refinedBubbleSort(coollist):
    needtoswap = True
    x = len(coollist)-1   # x is now the index value of last item in list
    while x > 0 and needtoswap:
       needtoswap = False
       for i in range(x):  # start with leftmost number and iterate to the xth position one space at a time
           if coollist[i] > coollist[i+1]:   # swap if left item in pair is greater than right item
               needtoswap = True
               coollist[i],coollist[i+1] = coollist[i+1],coollist[i]
       x = x-1  # Go through the list from rightmost item until the leftmost item
coollist = [1,2,3,4,5,6,7,8,9,10]
refinedBubbleSort(coollist)
print(coollist)  

How Do You Install Sysdig in an Existing Debian-Based Docker Container?

Problem scenario
You want to monitor Docker containers.  Therefore you want to install Sysdig to try it out.  How do you install Sysdig in a pre-existing Docker container?

Solution
Run these three commands:
apt-get -y update
apt-get -y install curl
curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | bash

How Do You Get a DNS Server That Was Working to Work Again?

Problem scenario
Your DNS server does not seem to be working any more.  What should you do?

Solution
1.  Can you ping it? 
2.  Log into it.  Run these commands to ensure that there is activity on a port:

sudo netstat -anlp | grep :53
nmap -Pn 127.0.0.1

If there is no activity, start the service with this command:
sudo systemctl start named.service