What Should You Do when the Apache Mesos Web UI Keeps Refreshing and Sending a Pop-up “Failed to connect to …:5050”?

Problem scenario
You deployed Apache Mesos. The web UI is having problems. You see the error "Failed to connect to x.x.x.x:5050." What should you do?

Solution

  1. Go to the back-end of the Apache Mesos server. Run this command: sudo systemctl stop mesos-master
  2. sudo find / -name mesos-master.sh
  3. Change directory into the parent of the "bin" directory that houses the mesos-master.sh as found above.
  4. Find the internal IP adress (e.g., with ip addr show | grep eth0 | grep inet).
  5. Run this command but substitute x.x.x.x with the internal IP address:
sudo ./bin/mesos-master.sh --ip=x.x.x.x --work_dir=/var/lib/mesos --hostname=x.x.x.x

6. Go back to your web browser. Refresh your web browser.

How Do You Create a REST API Endpoint?

Problem scenario
You want a REST API endpoint. How do you create a URL that is a proof-of-concept to trigger a Python program?

Solution
Prerequisites
i. You have installed Python 3. If you are using CentOS/RHEL/Fedora, run this: sudo yum -y install python3
ii. You need a web server installed. If you do not have one, install Apache web server.
iii. You must have PHP installed. To install it, run this command: sudo yum -y install php

Procedures
1. Create a file in /home/ec2-user/ called good.py with the following content:

# This was adapted from https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

# create a file handler
handler = logging.FileHandler('hello.log')
handler.setLevel(logging.INFO)

# create a logging format
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)

# add the file handler to the logger
logger.addHandler(handler)

logger.info('Hello from contint')

2. Create a file in /var/www/html/ called good.php with the following content:

<html>
<body>

HELLO!

</body>
</html>

<?php

   $command = escapeshellcmd('/usr/bin/python3 /home/ec2-user/good.py');
   $output = shell_exec($command);
   echo $output;

?>

How Do You Write a Java Program to Read in Letters and Numbers?

Problem scenario
You want to create a basic Java program that can read alphanumeric input interactively. How do you write such a program?

Solution
1. Verify the "javac" command works. Run "man javac" to see the man page. If you do not get a man page, install the Java development tools. On a RedHat derivative, run this: sudo yum -y install java-devel

2. Create a contint.java file with the content below. Use the usage instructions in the header comments.

/* This program was written by continualintegraiton.com
You should call it contint.java.  compile it with "javac contint.java" and run the byte code with "java contint"
It shows how to read in letters and numbers into a Java program */

import java.util.Scanner;

public class contint{
    public static void main(String args[]){
    System.out.println("Enter some characters and press enter:");

    Scanner ascanitem= new Scanner(System.in);
    String secondpart= ascanitem.nextLine();
    System.out.println(secondpart);
    System.out.println(" ");
    System.out.println("Enter some numbers and press enter");
    int number= ascanitem.nextInt();
    System.out.println(number);
    }
}

3. Run these commands:
javac contint.java
java contint

In Python, What Are Some Disadvantages to Using os.execlp to Fork a Process?

Question
In Python you are familiar with importing the os module and using different exec variations. What are some reasons that you would not use os.execlp?

Answer
1. If you use os.execlp to call another program, that program is more likely to return "Killed". The resources of the child process are, by default, more limited in part because the fork operation is expensive from a system's resources perspective. Here is an example of two programs (where bar.py calls foo.py). If you run the top program by itself, it will work on a low-powered system:

# Program #1 (foo.py)
import os, datetime, time
t1 = datetime.datetime.now()

def wastetime(n):
  x = 0
  for i in range(n):
    x = x + i

wastetime(30000000)

t2 = datetime.datetime.now()
t3 = t2 - t1
print("Time format is in hours:minutes:seconds:seconds_decimals")
print(t3)
# Program #2 (bar.py)
import os, cProfile

def callprog():
  os.execlp('python', 'python', 'foo.py')

cProfile.run('callprog()')

But if you run the bottom program, when it is in the same directory as the top program, it will not work. The bottom program will returned "Killed" -- even though all it is doing is running the top program. (You may want to read How Do You Fix a Python Program that Returns “Killed”?)

2. You cannot see the output of cProfile with the called program. cProfile will give you statistics on function calls. If you could run the called program directly, you can benefit from seeing the cProfile output. But if the program is invoked from an os.execlp() call, the called program's cProfile output will not display.

Here is a program that will display cProfile output to help illustrate why you would not use os.execlp():

# You can name it test2.py and run it with "python test2.py"
import os, datetime, time, cProfile
t1 = datetime.datetime.now()

def wastetime(n):
  x = 0
  for i in range(n):
    x = x + i

cProfile.run('wastetime(20000000)')

t2 = datetime.datetime.now()
t3 = t2 - t1
print("Time format is in hours:minutes:seconds:seconds_decimals")
print(t3)

# If you have a second program to call that program above, no cProfile output will be visible.

How Do You Install Java so You Can Compile Programs on a RHEL Server?

Problem scenario
You have installed Java. But you cannot use the javac command. You get errors like this: "-bash: javac: command not found"

How do you install Java so you can compile programs on a RedHat Linux server?

Solution
Run this command: sudo yum -y install java-devel

If you want to do this on a Debian or Ubuntu Linux server, see this posting.

How Do You Reclaim Swap Space on a Linux Server?

Problem scenario
You mounted 2 GB of swap space (virtual memory) called 2GB.swap. (You followed these directions. Later you added RAM to the server.) This 2 GB swap space is still mounted. How do you clear it and repurpose it on your hard drive?

Solution
1. Run this command: sudo swapoff -a
2. Modify the /etc/sysctl.conf file. (You may want to back it up before you make a change.) Here is what you need to do to change it:
Run this command: sudo vi /etc/sysctl.conf
# eliminate the "vm.swappiness=10" stanza

3. Modify the /etc/fstab file. (You may want to back it up before you make a change.) Here is what you need to do to change it:
Run this command: sudo vi /etc/fstab
#eliminate the "/mnt/2GB.swap none swap sw 0 0"

4. Run these commands:
cd /mnt
sudo rm -rf 2GB.swap

How Do You Get a Raspberry Pi to Work Again after Two GPIO Pins Were Connected When They Should Not Have Been?

Problem scenario
You recently connected a jumper connector to two GPIO pins accidentally on your Raspberry Pi. Now your Raspberry Pi will not start, and it seems fried. There is a red light that is on. There is no flashing light and no green light. There is no output to the monitor. You are not sure if the Raspberry Pi is wasted.

Solution
1. Remove the jumper connector from the GPIO pins. Either get a MicroSD card from a working Raspberry Pi and skip the rest of these steps (to test the Raspberry Pi), or get a new blank MicroSD card. It may be that the original MicroSD card is not usuable.

2. Open a web browser and go to http://downloads.raspberrypi.org/NOOBS_latest. Download the .zip file. (To download the large zip file to a specific location, see this posting if you have a Windows desktop.)

3. Place the MicroSD card into a card reader so you can access it with the Windows desktop.

4. Put the contents of the zip file (step #2) on to the MicroSD card (step #3).

5. Now the MicroSD card should allow the Raspberry Pi to work.

How Do You Troubleshoot the tar Error “Cannot execute remote shell: No such file or directory”?

Problem scenario
You are using the tar command. You are getting an error when you try to compress a file. This is the message:

"tar (child): Cannot execute remote shell: No such file or directory
Cannot open: Input/output error
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now"

What should you do?

Solution
Eliminate colons in the file. Even quotes around the file name's characters that have ":" colons will not work for some tar functions. We find that tar works fine when there are just letters, numerals, and periods ".".

How Do You Get Ubuntu/Debian Linux to Have Packages That Can Be Updated When the Upgrade Command Did Not Work?

Problem scenario
You are using Ubuntu or a Debian distribution of Linux. You log in and see this (the message of the day):

6 packages can be updated.
6 updates are security updates.

You then run this: sudo apt-get -y upgrade

But it does not work. You see this message:

"0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded."

What can you do to update your Linux server and not be warned about packages that can be updated?

Solution
Run this command: sudo apt -y upgrade

How Do You Get a Script to Execute Every Time You Log in as the User in Linux?

Problem scenario
You want a script to run whenever a user logs in (e.g., when a sudoer uses "su jdoe", you want a script to run before you assume the jdoe user). You are using Linux SUSE or Ubuntu or a Debian distribution. You found that having a script in /etc/profile.d/ does not work. What should you do?

Solution
To have a script automatically run for a given user, create a .bashrc file in the /home/jdoe/ directory (where jdoe is the username). For CentOS/RedHat/Fedora, place a script in /etc/profile.d/.

To have a script automatically run for a given user, create a .bashrc file in the /home/jdoe/ directory (where jdoe is the username). If one exists modify it. Make sure the .bashrc file has this line appended to it (where /home/ubuntu/foobar.sh is the complete path to the shell script):

/bin/bash /home/ubuntu/foobar.sh

For CentOS/RedHat/Fedora, place a script in /etc/profile.d/ (and do not be concerned about a .bashrc file).