Skip to main content

Lab 10: App Admin

Published

2026-11-06

WarningCaution

This section is being revised. Thank you for your patience.

This lab covers installing Linux packages, daemonizing an application with systemd, and working with text files and editors from the command line.

Comprehension questions

“What are two different ways to install Linux applications, and what are the commands?”

My instance is Amazon Linux 2, so the system package manager is yum, not Ubuntu’s apt:

  • sudo yum install <package> pulls a package (and its dependencies) from AL2’s configured repositories.

    • sudo yum update keeps everything already installed current.
  • For software that isn’t in the repos, I download the package myself with wget <url> and install it directly:

    sudo yum localinstall <package>.rpm
    # or
    sudo rpm -i <package>.rpm
    • No dependency resolution beyond what’s already on the box, so this is my second choice, not my first.

“What does it mean to daemonize a Linux application? What programs and commands are used to do so?”

Daemonizing an application means running it as a background service that starts on boot, restarts if it crashes, and keeps running independent of any login session, instead of a process that dies the moment I close my SSH connection.

On AL2, systemd is the program that manages this, and systemctl is how I talk to it:

%%{init: {'theme': 'base', 'look': 'classic', 'themeVariables': {'fontFamily': 'monospace', "fontSize":"12px"}}}%%

graph TD
    subgraph Unit["Unit File"]
        DotService["<strong>/etc/systemd/system/*.service</strong>"]
    end
    Reload("<strong>systemctl daemon-reload</strong>")
    Enable("<strong>systemctl enable</strong><br/><em>starts on boot</em>")
    Start("<strong>systemctl start</strong>")
    Status("<strong>systemctl status</strong>")

    Unit --> Reload --> Enable --> Start --"<em>running now</em>"--> Status

    style DotService stroke:#fff,stroke-width:1px,color:#000,font-family:monospace,font-size:11px
    style Unit fill:#1B2A41,stroke:#fff,stroke-width:1px,color:#fff
    style Reload fill:#2A6F77,stroke:#fff,stroke-width:1px,color:#fff,font-family:monospace,font-size:14px
    style Enable fill:#2A6F77,stroke:#fff,stroke-width:1px,color:#fff,font-family:monospace
    style Start fill:#5B8C5A,stroke:#fff,stroke-width:1px,color:#fff,font-family:monospace
    style Status fill:#E8A33D,stroke:#000,stroke-width:1px,color:#000,font-family:monospace

Daemonizing with systemd

Once the unit file exists, systemctl restart and systemctl stop manage it going forward, and systemctl disable stops it from starting on boot.

Anatomy of a unit file

A unit file is a short INI style text file with three sections:

[Unit]
Description=<what this service is>
After=network.target

[Service]
User=<service account>
WorkingDirectory=<app directory>
ExecStart=<absolute path to the executable> <arguments>
Restart=on-failure

[Install]
WantedBy=multi-user.target

[Unit] describes the service and what it waits for (After=network.target holds it until networking is up). [Service] says how to run it: which account it runs as (User=), where it starts (WorkingDirectory=), the exact command (ExecStart=), and what to do when it exits (Restart=). [Install] says when to start it on boot; multi-user.target is the normal booted state of a server.

systemd runs ExecStart directly, with no shell, no PATH search, and no virtual environment activation. Anything an interactive session quietly provides has to be spelled out in the unit file, which is why the path is always absolute.

After systemctl enable --now <name>, I never assume the service is running. systemctl status <name> shows the state (active (running)) and whether it starts on boot (enabled), and journalctl -u <name> shows the service’s output when something goes wrong. Installing a Real Application walks through all of this for a real app, from the unit file to reading a failed start.

“How do you know if you’ve opened Nano or Vim? How would you exit them if you didn’t mean to?”

Nano tells me right away: the bottom of the screen fills with a menu of keybindings (^X Exit, ^O Write Out, etc.), and I can just start typing. Vim gives no such hints: it opens in normal mode, the screen is otherwise blank (empty lines marked with ~), and typing does nothing useful until I switch to insert mode. That silence is usually how I know I’ve landed in Vim by accident.

To back out without changing anything:

Nano: Ctrl + X, then answer N if it asks whether to save

Vim: press Esc first to make sure I’m in normal mode (not typing into the file), then type :q! and hit Enter to quit and discard any changes.

“What are four commands to read text files?”

cat, less, head, and tail. I reach for cat on short files, less for anything long enough to scroll, head when I only need the first lines, and tail -f when I want to watch a log file update in real time.

“How would you create a file called secrets.txt, open it with Vim, write something in, close and save it, and make it so that only you can read it?”

vim secrets.txt

From there:

  1. Press i to enter insert mode and type the content.
  2. Press Esc to return to normal mode.
  3. Type :wq and hit Enter to write (save) and quit.

Then lock it down so only I can read it:

chmod 600 secrets.txt

600 gives the owner read/write and removes every permission for group and other; it’s the same restriction I already use on .ssh/authorized_keys in Linux Users.

Recap

  1. On Amazon Linux 2, sudo yum install pulls a package and its dependencies from the configured repositories. A downloaded .rpm installed with yum localinstall or rpm -i is my second choice, because it can’t lean on the repositories for dependencies.

  2. Daemonizing hands the app to systemd: write a unit file in /etc/systemd/system, then run systemctl daemon-reload and systemctl enable --now. User=, an absolute ExecStart path, and Restart=on-failure do most of the work, because systemd runs the command with no shell.

  3. enable --now only means systemd tried. I confirm with systemctl status (looking for active (running) and enabled) and read journalctl -u <name> when it fails.

  4. Nano shows its keybindings and exits with Ctrl + X; Vim opens silently in normal mode and exits without saving with Esc, then :q!. chmod 600 makes a file like secrets.txt readable only by its owner.

Install Apps covers PATH and installing language runtimes into /opt, and Installing a Real Application installs baseball-trajectory and runs it as a systemd service.