All lessons in Cloud Engineering: Deploy, Operate, and Recover

Diagnose a Linux Service

Separate process, socket, permission, resource, and dependency failures using bounded observations.

35 minutes · Free lesson

What you will learn

  • Distinguish a running process from a reachable and useful service.
  • Select observations that separate permissions, listener, capacity, and dependency faults.
  • Produce a reproducible diagnostic transcript without exposing credentials.

The status service works in your terminal but fails after it is started by a runtime. Reinstalling packages or opening every port changes too much at once. First compare the conditions under which the process runs: user identity, working directory, configuration, filesystem access, listener address, and resource limits.

This is a targeted operating-systems bridge. The goal is to locate the failing boundary and justify a narrow correction. Use only the course's local service or a learner-owned sandbox; a diagnostic command against a shared host can affect or disclose unrelated workloads.

Observe the process and its environment

Establish which process is supposed to run and whether it stays running. On Linux, a bounded ps inspection can identify the user, command, parent, and elapsed time. A process that exits immediately suggests a different investigation from one that remains alive while every request times out.

Check the runtime's recorded exit status and application logs. A missing file, unsupported argument, or bind failure can explain a crash directly. Avoid inferring the cause from an exit number alone when the runtime can supply a more specific event. Restart loops can obscure the first useful message, so preserve the earliest relevant failure.

Do not print an entire environment to diagnose one setting. Record whether the required variable is present and which configuration source supplied it, while keeping secrets out of transcripts. A developer shell may have a variable that the service manager never received. Its absence is a configuration difference, not evidence that the program needs administrative privileges.

Separate a listener from the route to it

A listener binds an address and port. On a Linux sandbox, ss -ltn shows listening TCP sockets; on a Mac, an appropriately scoped lsof -nP -iTCP:PORT -sTCP:LISTEN can answer a similar question. Command availability differs, so retain the tool and platform in the transcript.

Binding to loopback makes a process reachable from its own network namespace. A process inside a container bound only to its own loopback may be unreachable through the container's published interface. Conversely, the course's local diagnostic service deliberately binds to host loopback to keep its exercise interface local.

Test from the same position as the failing caller. A host request, a container-internal request, and a request through ingress traverse different boundaries. State where each command ran. A successful request from inside the application container does not establish that ingress can reach its target port.

Check permissions without broadening them blindly

Identify the runtime user and the exact file or directory operation that failed. Reading a file requires appropriate access to the file and traversal of its parent directories. An image built as an administrator can create artifacts that a non-root runtime cannot read. Correct ownership or the narrow required permission instead of making the entire tree writable.

The familiar read/write/execute bits are only part of effective access. Mount options, access-control lists, runtime confinement, and the filesystem's state can also matter. Treat a simplified permission exercise as a starting hypothesis and inspect the relevant platform control when it does not explain the observation.

Keep runtime data separate from immutable application files. A service that unexpectedly writes to its installation directory can fail after a move to a read-only image. Decide whether the write is necessary and which dedicated path should own it before loosening the filesystem boundary.

Worked example

Isolate a listener mismatch

  1. The deployment expects HTTP on container port 8080. The process log says it is listening on 127.0.0.1:8000 inside the container.
  2. A container-internal request to port 8000 succeeds. A request from the ingress path to port 8080 fails.
  3. Two contract mismatches are visible: the target port differs, and the listener is bound only to the container's loopback interface.
  4. Configure the sandbox process to bind the intended container interface and port, then repeat the internal and ingress-path checks without changing unrelated firewall rules.
  5. Keep the old and new listener observations plus a status-response assertion. A healthy process alone would not reveal whether the corrected route delivers useful data.

Recognize resource pressure and dependency waits

A slow process may be waiting for CPU, memory, disk, or a remote dependency. Inspect a short, bounded sample rather than drawing conclusions from a single instantaneous value. On a Linux sandbox, tools such as top, df -h, and df -i can help separate CPU activity, storage capacity, and inode exhaustion.

Low CPU does not prove spare service capacity. Threads may be waiting on a dependency or blocked on a bounded connection pool. High CPU does not prove the host is the only bottleneck. Relate resource observations to request rate, latency, queueing, and dependency timing before deciding what to scale.

A health probe can also change the observed behavior. A restart caused by a failing liveness probe may destroy useful diagnostic state. The Container Apps probe guide distinguishes startup, readiness, and liveness purposes; use that distinction when mapping local observations to a managed runtime.

Diagnose a live process and a missing file

Start the service using the two-terminal setup in the first lesson. In terminal B run these commands in order:

  1. Find the selected listener on macOS: lsof -nP -iTCP:8765 -sTCP:LISTEN. On Linux use ss -ltnp 'sport = :8765'. Inspect only the matching process.

  2. Inspect the data permissions: ls -ld .work and ls -l .work/status.json.

  3. Check the useful request: curl --max-time 5 -i http://127.0.0.1:8765/status/DOC-100.

  4. Remove the dependency from its configured path: mv .work/status.json .work/status.saved.json.

  5. Compare curl --max-time 5 -i http://127.0.0.1:8765/healthz with curl --max-time 5 -i http://127.0.0.1:8765/readyz.

  6. Restore it: mv .work/status.saved.json .work/status.json, then run python3 probe.py.

Health remains 200 while readiness becomes 503; the listener's PID stays the same. Restoration should make the probe pass without restarting. If readiness never fails, check the service command: it may be reading the original fixture instead of .work/status.json.

For a permission variant, run chmod 000 .work/status.json, request readiness, then restore access with chmod 600 .work/status.json. A normal non-root process should receive a data-access failure. A root process may bypass ordinary mode-bit restrictions; check the listener's owner before interpreting the result. Do not change parent folders or unrelated files.

Exercise

The process is alive and its health endpoint succeeds, but all status requests fail. Name two observations that can distinguish likely causes.

Check your answer

Inspect the status handler's dependency error and test the configured data source under the runtime identity. Compare readiness with process liveness and verify the requested status ID. A healthy process does not establish correct data configuration or permission.

Exercise

A service reads a file as your user but fails as its non-root runtime user. Why is changing every file to world-writable an inadequate fix?

Check your answer

It grants unrelated write authority and may not address the actual failure. Check the exact operation, ownership, file read permissions, parent-directory traversal, and runtime/mount restrictions. Correct only the required boundary and repeat the read as the runtime user.

Exercise

The listener exists and health is 200. After renaming .work/status.json, readiness is still 200. What command and observation would identify the likely mistake?

Check your answer

Read the process command with ps -p PID -o pid=,user=,args=, substituting the PID shown by lsof or ss. Check its --data argument. If it points to fixtures/status.json, renaming the .work copy does not affect the selected dependency. Restart with --data .work/status.json and repeat the experiment.

Summary

Inspect the runtime conditions and failing boundary before changing controls. A process, listener, route, permission, and useful response are separate observations; preserve their relationships in a bounded transcript.

Next action

Organize the Azure sandbox so that resources, access scopes, ownership, and cleanup can be reviewed before deployment.

Choose another lesson