DevOps Engineering: Foundations to Reliable Delivery / Start Here: Linux and a Running Service

Keep a service running and read its evidence

Lesson 5 of 72. Open to read. No account needed.

Give the Process a Name

Remembering a PID works for a short sleep, but not for a service that can stop and start again. A service manager starts a named program using recorded configuration and tracks its lifecycle. Ubuntu uses systemd. Its unit file describes what to run; the running process is a separate thing.

We will serve one synthetic text file on this guest only. A client sends an HTTP request asking for a path; the server replies with a status and content. HTTP is the application protocol used here, not a synonym for the network. Python's small built-in server is a learning fixture, not a production server.

Use Bash as ordinary ubuntu in the vecta-devops guest. The normal guest login must have a working user service manager. Check it before creating files:

id -un
systemctl --user list-units --type=service --no-pager

--user selects your service manager, not the system-wide root manager. --no-pager prints directly instead of opening an interactive viewer. A list with no services can be valid. Failed to connect to bus is not: re-enter the guest through its normal login and resolve the missing user session before continuing. Do not substitute sudo systemctl and accidentally change scope.

Install the two Ubuntu packages inside the disposable guest, with the owner's installation permission and internet access:

sudo apt-get update
sudo apt-get install --no-install-recommends python3 curl
python3 --version
curl --version

apt-get update refreshes the package index; install changes the guest by installing packages. It does not install anything on the host. Ubuntu 24.04's Python 3.12 series is the route used here; record the actual patch version. curl is a command-line HTTP client. No Python package download is required.

If installation reports that another process holds the package lock, stop at that message. Ubuntu may be installing automatic updates after boot. In the guest, inspect systemctl status apt-daily-upgrade.service --no-pager; an inactive result may return nonzero. Wait for the named update to finish before retrying the failed installation. Do not remove lock files, kill the updater or disable automatic updates to make this exercise proceed. If the owner in the error is a different process or updates keep failing, keep the exact error and resolve that issue before creating the service files.

Supply the Data and Unit

First-time setup, from your confirmed course directory:

cd "$HOME/vecta-devops"
pwd -P
mkdir linux-service
mkdir linux-service/site
printf '%s\n' 'Release Board practice' > linux-service/site/index.txt
mkdir -p "$HOME/.config/systemd/user"

Stop on an unexpected existing linux-service; resume your own files instead of overwriting them. The -p for the configuration directory accepts its known parent directories because systemd stores other user units there too. It is not permission to replace another unit. Check that vecta-board.service is not already someone else's configuration before creating it.

The following complete file is written with a here-document. Bash sends the lines between <<'UNIT' and the final UNIT into cat, which writes them to the named file. The quoted delimiter prevents shell expansion inside the text. The closing delimiter must be alone on its line.

cat > "$HOME/.config/systemd/user/vecta-board.service" <<'UNIT'
[Unit]
Description=Vecta local practice board

[Service]
Type=exec
WorkingDirectory=%h/vecta-devops/linux-service/site
ExecStart=/usr/bin/python3 -u -m http.server 8800 --bind 127.0.0.1
Restart=no
UNIT

[Unit] describes the unit; [Service] configures its process. %h is a systemd specifier for this user's home, not a Bash variable. The working directory supplies the files the server can read. ExecStart selects the absolute Python program; -m runs its http.server module and -u avoids delayed buffered output. Port 8800 identifies this listener. Binding to 127.0.0.1, the guest's loopback address, prevents other machines connecting directly. It does not make the host's loopback the same as the guest's.

Type=exec tracks whether execution could start; it does not prove an HTTP response is ready. Restart=no leaves failures visible for this exercise. There is no [Install] section or boot-enablement instruction: start it when practising and stop it when finished. It runs with your unprivileged user's permissions; it is not a separate privileged account.

The user manager reads the unit and starts Python, which reads the site file. A local client checks the HTTP response while the process sends logs to the journal.

Separate control from evidence: the manager starts the process, the client tests behavior, and the journal explains what the process reported.

Start, Observe, Ask for a Response

In the same guest, any directory:

systemctl --user daemon-reload
systemctl --user start vecta-board.service
systemctl --user status vecta-board.service --no-pager
curl --noproxy '*' --connect-timeout 1 --max-time 2 \
  --retry 5 --retry-connrefused --retry-delay 1 --retry-max-time 10 \
  --fail -i http://127.0.0.1:8800/index.txt
journalctl --user-unit=vecta-board.service -n 20 --no-pager

daemon-reload rereads unit definitions; it does not restart a running process. start requests the process. In status, look for active (running) and its current PID. A running process may still be preparing its listener, so check HTTP readiness with a short, bounded retry rather than assuming start means ready. curl -i includes response headers; --noproxy '*' avoids an inherited proxy for this local exercise. Expect HTTP 200 and Release Board practice. Header timestamps vary.

--connect-timeout 1 allows one second for connection setup; --max-time 2 limits each transfer to two seconds. --retry 5 permits at most five retries after the initial attempt. --retry-connrefused includes a listener that is not ready yet, and --retry-delay 1 waits one second between attempts. --retry-max-time 10 stops starting retries after the ten-second retry window; an attempt already underway can finish afterward. --fail makes an HTTP error such as 404 fail the command too. This is a read-only check, not permission to retry purchases or other operations that change data.

A brief connection-refused message can precede a successful retry. If the command exhausts its budget, stop here and inspect current status and the journal below; do not continue by repeatedly pasting the command. To inspect an HTTP error's headers during diagnosis, use the single-request command from the investigation lesson, without --fail. The request path /index.txt selects the file relative to the configured site directory. A 404 means a responding server did not find that path.

The journal command selects this user unit's last 20 records. Associate the timestamp, requested path and response status; do not treat an old error as the latest state. Logs are evidence, not necessarily a diagnosis by themselves.

systemctl --user show vecta-board.service -p MainPID -p MemoryCurrent
free -h
df -h "$HOME"

MainPID is the manager's current process. MemoryCurrent is accounted memory in bytes, not the guest's total; it may be unavailable when accounting is not supported. free and df describe the wider guest resources. A service can be running while the filesystem is almost full. Do not fill the disk to practise this: reason from the Avail field and inspect owned data before any deletion.

Stop Deliberately

systemctl --user stop vecta-board.service
systemctl --user is-active vecta-board.service

Expect inactive and a nonzero result from is-active. That is correct after an intentional stop. Keep the unit and data for later lessons. On return, re-enter the guest normally, start the same unit, and repeat the HTTP check. User services are not promised to survive logout or VM shutdown in this setup. Do not enable lingering or boot startup merely to keep this lab alive.

For complete removal later, stop the service first, remove only your unit with rm -i, run daemon-reload, and inspect the owned data before removing it. Never remove the shared .config/systemd/user directory.

Diagnose a Different Result

ObservationInvestigate next
Failed to connect to busUser login/session, not the Python source.
Failed start, working-directory errorUnit path, directory existence and traversal permissions.
Address already in useAnother listener may own 8800; inspect it, do not terminate unknown processes.
Active but 404Requested path and site contents; process state is not content correctness.
Readiness retries exhaustedCheck current status/journal and the configured address/port; do not repeat indefinitely.

Explain the Evidence

Why are both status and a request needed? After changing ExecStart, does daemon-reload alone launch the changed command? What survives stopping?

Answer and Reasoning

Status describes the managed process; the request checks the served behavior. Rereading the unit does not replace an already running process. After reviewing and reloading a deliberate unit change, systemctl --user restart vecta-board.service stops and starts that named service. Stopping preserves the unit and site files, but removes its running process.

References

67 more lessons in the full course

Course access opens every lesson and adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 199 plus 18% GST. 90 days of online access. No auto-renewal.

Get the full course

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy