RHCSA (027): Season 2 - Scenario 2 of 25: Application Directory Cleanup and Re-structuring

Executive Summary

This Episode 27 RHCSA GNU/Linux Lab is focused on essential file system management and application deployment tasks. The primary scenario involves addressing a failed application deployment located in /var/tmp/failed_deploy. The lab's core objectives test the administrator's ability to create, move, and edit files and directories (Objectives 1.8, 1.7) and to properly integrate the application into the system using hard and soft links (Objective 1.9).

The solution process begins by creating a new, standardized directory structure at /opt/webapp with distinct subdirectories for binaries, configuration, and documentation. The administrator must then migrate the relevant application files from the failed deployment, such as app.bin and config.xml, into this new structure and subsequently remove the original temporary directory. A critical step involves reconfiguring the application by editing its configuration file with vim to update a database endpoint from db.old.internal to db.prod.internal.

To complete the deployment, the administrator must ensure the new database is reachable by modifying the /etc/hosts file to resolve db.prod.internal to its correct IP address (Objective 8.2). Finally, the application is integrated into the system by creating a symbolic link to its binary in /usr/local/bin for easy execution and a hard link to its configuration file in /etc for system-wide access. The lab concludes with a verification sequence that confirms the links are correct by checking their properties and inode numbers, and that name resolution is functional by successfully pinging the new database hostname.

Keywords: RHCSA, GNU/Linux, Application Directory, File Cleanup, File Re-structuring, File System Management, /var/tmp, /opt, mkdir, mv, rm, vim, /etc/hosts, hard link, soft link, symbolic link, ln, Linux deployment, CLI, root user, file verification

+-- Acronyms & General Terms
|
|-- CLI: Command-Line Interface; a text-based user interface.
|-- GNU/Linux: A family of open-source Unix-like operating systems.
|-- Inode: A data structure storing metadata about a file.
|-- IP Address: A numerical label for a device on a network.
|-- RHCSA: Red Hat Certified System Administrator.
|-- root: The administrative superuser account with full privileges.
|\-- ssh: Secure Shell; a protocol for secure remote login.
|
+-- Commands
|
|-- echo: Prints text to the terminal or redirects it to a file.
|-- grep: Searches text for a specific pattern.
|-- ln: Creates hard or soft (symbolic) links between files.
|-- ls: Lists directory contents and file information.
|-- mkdir: Creates a new directory.
|-- mv: Moves or renames files and directories.
|-- ping: Tests network connectivity to a specific host.
|-- rm: Removes (deletes) files or directories.
|-- sed: A stream editor for filtering and transforming text.
|-- touch: Creates an empty file or updates its timestamp.
|\-- vim: A modal text editor used for creating and editing files.
|
\-- File System Concepts & Paths
|
|-- /etc/hosts: A system file that maps hostnames to IP addresses.
|-- /opt: A directory for installing optional, third-party software.
|-- /usr/local/bin: A directory for executables not part of the base OS.
|-- /var/tmp: A directory for temporary files that persist between reboots.
|-- Hard Link: A directory entry that associates a name with a file's inode.
|\-- Soft Link (Symlink): A special file that acts as a pointer to another file's path.

Objectives: 1.8, 1.7, 1.9 (Primary); 8.2, 1.11 (Secondary)
Lab: RHCSA: Application Directory Lab (S2, Ep 27). Focus: Clean failed /var/tmp/ deploy, create /opt/ structure, move files, edit config (vim), update /etc/hosts, create hard/soft links.

Note: Before performing this lab, I need to ssh into my Linode as the root user. On my Linode, I run this command to do so:
ssh root@rhcsa-lab-server

├── Part 1: Lab Setup (Perform as 'root' - Mission: Create "failed deployment")
│ ├── 1. Create Dir: mkdir -p /var/tmp/failed_deploy
│ ├── 2. Create Junk: touch /var/tmp/failed_deploy/core.dump; touch /var/tmp/failed_deploy/debug.log
│ ├── 3. Create App Bin: echo "This is the app binary" > /var/tmp/failed_deploy/app.bin
│ ├── 4. Create App Docs: echo "This is the README" > /var/tmp/failed_deploy/README.md
│ ├── 5. Create App Config: echo "<config><database>db.old.internal</database></config>" > /var/tmp/failed_deploy/config.xml
│ └── 6. Verify: ls -l /var/tmp/failed_deploy

└── Part 2: Lab Problem (Perform as 'root' - Mission: Clean up & re-deploy to /opt/)
├── 1. Create New Structure: /opt/webapp/bin, /opt/webapp/etc, /opt/webapp/docs
├── 2. Migrate & Clean: Move app.bin->bin/, config.xml->etc/, README.md->docs/. Delete /var/tmp/failed_deploy/
├── 3. Reconfigure App: Edit /opt/webapp/etc/config.xml (vim): 'db.old.internal' -> 'db.prod.internal'
├── 4. Configure Name Resolution: Edit /etc/hosts: Map '10.0.5.100' to 'db.prod.internal'
└── 5. Create Links: Symlink: /usr/local/bin/webapp -> /opt/webapp/bin/app.bin. Hard Link: /etc/webapp.conf -> /opt/webapp/etc/config.xml


Solution & Cleanup Steps (Scenario 2) 
(Note: Please make sure you’ve done all setup steps of Step 1 on the previous page before performing the solution below.)

├── ➡️ Solution Steps (Perform as 'root')
│   │
│   ├── 1. Create New Structure
│   │   └── mkdir -p /opt/webapp/{bin,etc,docs}
│   │
│   ├── 2. Migrate Files
│   │   ├── mv /var/tmp/failed_deploy/app.bin /opt/webapp/bin/
│   │   ├── mv /var/tmp/failed_deploy/config.xml /opt/webapp/etc/
│   │   └── mv /var/tmp/failed_deploy/README.md /opt/webapp/docs/
│   │
│   ├── 3. Cleanup
│   │   └── rm -rf /var/tmp/failed_deploy
│   │
│   ├── 4. Reconfigure Application (using vim)
│   │   ├── vim /opt/webapp/etc/config.xml
│   │   └── (Inside vim: :%s/db.old.internal/db.prod.internal/g, then :wq)
│   │
│   ├── 5. Configure Name Resolution
│   │   └── echo '10.0.5.100 db.prod.internal' >> /etc/hosts
│   │
│   └── 6. Create System-Wide Links
│       ├── ln -s /opt/webapp/bin/app.bin /usr/local/bin/webapp
│       └── ln /opt/webapp/etc/config.xml /etc/webapp.conf

├── 🕵️ Verification Sequence (Perform as 'root')
│   │
│   ├── 1. Verify Links
│   │   ├── ls -l /usr/local/bin/webapp     -> Shows symlink
│   │   └── ls -i /etc/webapp.conf          -> Note inode number
│   │
│   ├── 2. Verify Hard Link Integrity
│   │   ├── ls -i /opt/webapp/etc/config.xml  -> Verify inode matches
│   │   └── grep 'db.prod' /etc/webapp.conf -> Verify content
│   │
│   └── 3. Verify Name Resolution
│       └── ping -c 1 db.prod.internal        -> Verifies 10.0.5.100
           Type CTRL+C to end the ping after verification.

└── 🧹 Lab Cleanup (Perform as 'root')
    │
    ├── 1. Remove Application Directory
    │   └── rm -rf /opt/webapp
    │
    ├── 2. Remove System-Wide Links
    │   ├── rm /usr/local/bin/webapp
    │   └── rm /etc/webapp.conf
    │
    ├── 3. Clean /etc/hosts File
    │   └── sed -i '/db.prod.internal/d' /etc/hosts
    │
    └── 4. Verification (Optional)
        ├── ls /opt/webapp                      -> (Should fail)
        ├── ls /usr/local/bin/webapp            -> (Should fail)
        └── grep 'db.prod.internal' /etc/hosts  -> (Should return no output)
         Hit CTRL+C (if needed) to end grep search when it returns no output.
         
Episode 27: Application Directory Cleanup and Re-structuring
|
+-- 1. Prerequisites & Objectives
|   |-- Access Lab: ssh root@rhcsa-lab-server
|   \-- Primary Objectives: 1.8 (Move/Copy), 1.7 (Edit), 1.9 (Links)
|
+-- 2. Lab Setup (Create Failed Deployment)
|   |-- 1. Create Dir: mkdir -p /var/tmp/failed_deploy
|   |-- 2. Create Junk: touch /var/tmp/failed_deploy/core.dump; .../debug.log
|   |-- 3. Create App Bin: echo "..." > /var/tmp/failed_deploy/app.bin
|   |-- 4. Create App Docs: echo "..." > /var/tmp/failed_deploy/README.md
|   |-- 5. Create App Config: echo "<config>...db.old.internal..." > .../config.xml
|   \-- 6. Verify Setup: ls -l /var/tmp/failed_deploy
|
+-- 3. Lab Solution (Clean Up & Re-deploy)
|   |-- 1. Create New Structure
|   |   \-- mkdir -p /opt/webapp/{bin,etc,docs}
|   |
|   |-- 2. Migrate Files
|   |   |-- mv /var/tmp/failed_deploy/app.bin /opt/webapp/bin/
|   |   |-- mv /var/tmp/failed_deploy/config.xml /opt/webapp/etc/
|   |   \-- mv /var/tmp/failed_deploy/README.md /opt/webapp/docs/
|   |
|   |-- 3. Cleanup Old Dir
|   |   \-- rm -rf /var/tmp/failed_deploy
|   |
|   |-- 4. Reconfigure Application
|   |   |-- vim /opt/webapp/etc/config.xml
|   |   \-- (In vim): :%s/db.old.internal/db.prod.internal/g (then :wq)
|   |
|   |-- 5. Configure Name Resolution
|   |   \-- echo '10.0.5.100 db.prod.internal' >> /etc/hosts
|   |
|   \-- 6. Create System-Wide Links
|       |-- Symlink: ln -s /opt/webapp/bin/app.bin /usr/local/bin/webapp
|       \-- Hard Link: ln /opt/webapp/etc/config.xml /etc/webapp.conf
|
+-- 4. Verification Sequence
|   |-- 1. Verify Links
|   |   |-- ls -l /usr/local/bin/webapp (Check -> points to source)
|   |   \-- ls -i /etc/webapp.conf (Note the inode number)
|   |
|   |-- 2. Verify Hard Link Integrity
|   |   |-- ls -i /opt/webapp/etc/config.xml (Verify inode matches)
|   |   \-- grep 'db.prod' /etc/webapp.conf (Verify content)
|   |
|   \-- 3. Verify Name Resolution
|       \-- ping -c 1 db.prod.internal (Verify it pings 10.0.5.100)
|
\-- 5. Lab Cleanup
    |-- 1. Remove App Directory
    |   \-- rm -rf /opt/webapp
    |
    |-- 2. Remove System-Wide Links
    |   |-- rm /usr/local/bin/webapp
    |   \-- rm /etc/webapp.conf
    |
    |-- 3. Clean /etc/hosts File
    |   \-- sed -i '/db.prod.internal/d' /etc/hosts
    |
    \-- 4. (Optional) Verify Cleanup
        |-- ls /opt/webapp (Should fail)
        |-- ls /usr/local/bin/webapp (Should fail)
        \-- grep 'db.prod.internal' /etc/hosts (Should be empty)

You should also read:

RHCSA Series (005): Providing User Interfaces

Mind Map RHCSA_Series_5_Providing_User_Interfaces_Mind_Map │ ├── Alphabetical_List_of_Abbreviations │ ├── CLI = Command-Line Interface │ ├── CSCI = Computer Science │ ├── CSH = C…

RHCSA Series (004): Managing Memory

Mind Map RHCSA_Series_4_Managing_Memory_Mind_Map │ ├── Alphabetical_List_of_Abbreviations │ ├── CPU = Central Processing Unit │ ├── cron = Chron Table (scheduler) │ ├── dstat…