Why Do You Have a Discrepancy between the Maximum Number of File Descriptors between Your /etc/security/limits.conf File and What You Are Seeing in the Logs?

Problem scenario
You run a ulimit -Hn command.  You see the limit of the file descriptors to be what you expect.  But in the logs of an application, there is a discrepancy.  Why is one log reporting that the limit to file descriptors is different from the output of a "ulimit -Hn" or "ulimit -Sn" command?

Solution
Root cause
The ulimit -Hn and ulimit -Sn commands do not show the whole story.  Other application logs may be reporting true limits based on the user who started the service or the .service file associated with the application itself.

Procedures
1.  Go to this directory:  /etc/security/limits.d/

2.  Look at various files here.  These .conf files can override the global system setting.  Also note that .service files in /etc/systemd/system/ can have stanzas that will override the override setting in /etc/security/limits.d/ .conf files.

How Do You Enter Data into a Cassandra Table?

Problem scenario
You want to insert data into a Cassandra table.  How do you do this?

Solution
Prerequisites

Install and configure Cassandra.  If you do not know how, click on this link and go to "Possible Solution #5" at the bottom to determine the distribution of Linux that you have.

Procedures
1.  Create the table with this command:
CREATE TABLE contint(
   contint_id int PRIMARY KEY,
   contint_name text,
   contint_city text,
   contint_sal varint,
   contint_phone varint
   );

2.  Run this command:
insert into contint (contint_id, contint_city, contint_name, contint_phone) VALUES (1, 'San Francisco', 'Mark Zuckerberg', 4151234567) ;

How Do You Install Gradle on Any Type of Linux?

Problem scenario
You want to be able to install Gradle on a Debian/Ubuntu Linux server, a Red Hat derivative of Linux (e.g., CentOS/RHEL/Fedora), or Linux SUSE.  How do you do this with the same script?

Prerequisites
i.  Install Java.  If you need directions, see this posting.
ii.  Install unzip. 

  • If you are using Debian or Ubuntu, run this command: sudo apt-get -y install unzip
  • If you are using a Red Hat deriviative (e.g., CentOS/RHEL/Fedora), run this command:  sudo yum -y install unzip
  • If you are using Linux SUSE, run this command:  sudo zypper -n install unzip

Procedures
1.  Create a script.  Call it gradle.sh and place it in the /tmp/ directory.  Here is the content:

# This script will work with any type of Linux.
# If you are using Debian/Ubuntu and have your repositories configured, it may be as simple as running:
# sudo apt -y install gradle  # But this script below allows you to change the version.

version=4.7
curl -L https://services.gradle.org/distributions/gradle-$version-bin.zip > /tmp/gradle-$version-bin.zip
mkdir /opt/gradle
unzip -d /opt/gradle /tmp/gradle-$version-bin.zip
echo 'PATH="$PATH":/opt/gradle/gradle-'$version'/bin' > /etc/profile.d/gradle.sh
echo "run this command below:"
echo "export PATH=$PATH:/opt/gradle/gradle-"$version"/bin "
echo "#to get Gradle to work"
echo "*** The installation script has finished. *** "
echo "to test the installation, run 'gradle -v'"

2.  Run it like this:  sudo bash /tmp/gradle.sh

How Do You Troubleshoot a GitLab Webhook Failing Because of “Execution expired”?

Problem scenario
You try to test an Integration, specifically a Webhook, in GitLab.  The URL is for Jenkins.  You get "Execution expired."  What could be wrong?

Possible solution #1
See if the GitLab's IP address or hostname changed.  If the external_url stanza in /etc/gitlab/gitlab.rb uses an old IP address or FQDN, then that may need to be updated.  You may need to run "sudo gitlab-ctl reconfigure" again.  Then you may want to reboot your server.

Possible solution #2
Is there a firewall blocking connectivity over port 8080 (or whichever port your Jenkins server listens on)?

Possible solution #3
To find out more, go to the webhook job, click on "Edit."  At the lower portion of the screen you may find more about the job.

How Do You Write a Java Program to Accept Text from the Command Terminal and Print It Back Out?

Problem scenario
You want to write a basic Java program to test it out.  How do you write a program to accept user input, specifically a alphanumeric input, and print it back to the screen?

Solution
1.  Install the Java Development Kit if you have not installed it yet.  If you are not sure you have it, run "javac -version".  If it says that the command is not found, you need to install the Java Development Kit.  If you do not know how, see this posting.

2.  Create this file named acceptText.java:

import java.util.Scanner;

public class acceptText {

public static void main(String[] args) {
   System.out.println("Please enter text, then press enter: ");
   Scanner x = new Scanner(System.in);
   String var1 = x.next();
   System.out.println(var1);
  }
 }

3.  Run this command: javac acceptText.java

4.  Run this command: java acceptText

How Do You Troubleshoot the Ansible Error “Syntax Error while loading YAML expected <block end>, but found ‘-‘”?

Problem scenario
You are trying to run an Ansible playbook with the "become: yes" stanza.  You get this error after your ansible-playbook command:

"ERROR! Syntax Error while loading YAML.
  expected <block end>, but found '-'

The error appears to have been in '/home/cooluser/good.yaml': line 4, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  become: yes
  - copy:
  ^ here"

How do you get your playbook to run?

Solution
Put the "become: yes" stanza under the module -- not under the "tasks:" statement.

Here is an example of an incorrect order:

- hosts: all
  tasks:
  become: yes
  - copy:
      src: /home/cooluser/swapspace.sh
      dest: /home/cooluser/swapspace.sh
      owner: cooluser
      group: wheel
      mode: 0644

Here is an example of a correct order:

- hosts: all
  tasks:
  - copy:
      src: /home/cooluser/swapspace.sh
      dest: /home/cooluser/swapspace.sh
      owner: cooluser
      group: wheel
      mode: 0644
    become: yes

In Python, How Do You Call an Unbound Function as a New Thread with the thread Module?

Problem scenario
You want to write a program to call a unbound function in a new thread with the threading module. How do you do this?

Solution
Run this program (e.g., python foobar.py):

import _thread as thread
def contint():
  print("Hello!")

#if name == "main":
foobar = thread.start_new_thread(contint, () )
print("thread finished exiting")

How Do You Troubleshoot the Bash Script Error “line 5: $’\r’: command not found”?

Problem scenario
You drafted a Bash script on a Windows computer.  You then uploaded it to Google Cloud Platform via a web browser feature.  When you run the bash script on a Linux server (e.g., in GCP), you get this error "line 5: $'\r': command not found".  You do not want to install dos2unix or any new packages.  What should you do?

Solution
The file needs to be modified or "cleaned up."  Special characters were introduced with the way it was transferred over to the Linux system.  Assuming the file is called foo.txt, run this command:

perl -p -i -e "s/\r//g" foo.txt

How Do You Install Jira When You Get an Error about Not Having a Graphical UI or an Error about Using the -c Flag to Use the “console” to Install Jira?

Problem scenario
You are trying to install Jira on a RHEL server (e.g., in AWS).  You run this:

sudo ./atlassian-jira-software-7.8.1-x64.bin

But it gives you an error.  You see a message about not being able to connect to an X server and the -c option will invoke a console method.  You try using the -c flag when invoking the .bin script to install Jira.  The problem keeps happening.  What should you do?

Solution
1.  Run these two commands:
sudo yum groupinstall "X Window System"
sudo yum groupinstall 'Server with GUI'

2.  Reboot the server.

How Do You Troubleshoot “ERROR! ‘service’ is not a valid attribute for a Play”?

Problem scenario
You are trying to use the "service" Ansible playbook reserved word.  You want a service to be started.  But when you run the Ansible playbook, you get "ERROR! 'service' is not a valid attribute for a Play".  How do you fix this?

Solution
Change the formatting of the playbook.  Eliminate spaces and make sure indentation aligns with other sections of the playbook.