← Back to trackModule: Linux Essentials (Week 1)

BEGINNER · Medium · 60m

Services and logs (systemd basics)

Foundations Bootcamp

Lesson notes

Goal

Control services confidently and read logs like an operator.

What systemd is (simple)

systemd is the service manager on most modern Linux distros. It starts services, restarts them, manages dependencies, and records logs in the journal.

Core Commands (must know)

Service status

systemctl status nginx
systemctl is-active nginx
systemctl is-enabled nginx

Start/stop/restart

sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx

Enable on boot

sudo systemctl enable nginx
sudo systemctl disable nginx

Logs with journalctl

Follow logs (tail)

sudo journalctl -u nginx -f

Last 200 lines

sudo journalctl -u nginx -n 200 --no-pager

Logs since a time window

sudo journalctl -u nginx --since "1 hour ago" --no-pager

Where are logs stored?

Depends on the service:

  • journal (systemd): journalctl
  • files: commonly /var/log/ (nginx, auth, syslog)

Quick lookup:

ls -lah /var/log

The Unit File (what runs)

Check how systemd starts the service:

systemctl cat nginx

Look for:

  • ExecStart= (the actual command)
  • Environment= (important variables)
  • User= (permission issues!)
  • WorkingDirectory=

Debugging a Failing Service (playbook)

  1. Check status (read the last lines)
systemctl status myservice --no-pager
  1. Follow logs
journalctl -u myservice -f
  1. Confirm config and ports
ss -lntp
curl -v http://localhost:PORT
  1. If service starts then dies, read ExecStart and try running it manually.

Exercises

Exercise A: Create a tiny service

  1. Create a script:
sudo tee /usr/local/bin/hello-service >/dev/null <<'EOF'
#!/usr/bin/env bash
while true; do
  echo "hello from systemd: $(date -Iseconds)"
  sleep 5
done
EOF
sudo chmod +x /usr/local/bin/hello-service
  1. Create a unit file:
sudo tee /etc/systemd/system/hello.service >/dev/null <<'EOF'
[Unit]
Description=Hello demo service

[Service]
ExecStart=/usr/local/bin/hello-service
Restart=always

[Install]
WantedBy=multi-user.target
EOF
  1. Start it:
sudo systemctl daemon-reload
sudo systemctl start hello
sudo journalctl -u hello -f

Next Step

Once you can manage services and logs, you can operate real deployments: nginx, docker, and app processes become predictable.

View full outline

Outline

Use the outline to jump to any topic.

Track tools

Search lessons, continue where you left off, and track completion.

Modules

3

Lessons

9

Estimated Time

515m

Completion

0%

0/9 lessons

Your progress: 0%

Complete a lesson to increase progress

Outline

Open a lesson for full notes. Mark completed to update your progress.

Goal: By the end of this lesson you will be able to move around any Linux server quickly, understand where you are, and find what you need without guessing. This is not about memorizing commands. It is about building a m…

Goal: Understand Linux permissions well enough to fix "permission denied" problems quickly and safely. The Mental Model Every file/folder has: an owner (user) a group permissions for user/group/others Read it as: first c…

Goal: Control services confidently and read logs like an operator. What systemd is (simple) systemd is the service manager on most modern Linux distros. It starts services, restarts them, manages dependencies, and record…

Goal: Use Git the way teams actually work: small commits, feature branches, pull requests, reviews, and safe merges. The Workflow (end to end) Steps: 1. Sync with main 2. Create a branch 3. Commit small changes 4. Push b…

Goal: Recover from Git mistakes without losing work or breaking shared history. The Rule If the commit is already pushed and others might have it: prefer git revert (safe) If it is only local (not pushed): git reset is f…

Goal: Understand common branching strategies and when to use each. Strategy 1: Trunk based (recommended for fast teams) Idea: main stays deployable; branches are short lived. Pattern: small branches frequent merges featu…

Goal: Understand the minimum networking needed to debug real production issues: DNS, ports, HTTP, and TLS. The 4 step model When a request fails, check: 1. DNS: can we resolve the name? 2. Network: can we reach the IP/po…

Goal: Turn messy logs into clear answers using grep/awk/sed and a few patterns you will reuse forever. grep (search) Tips: n : show line number R : recursive E : regex i : case insensitive awk (extract columns) Common us…

Goal: Write a safe, reusable script that checks a service, collects logs, and prints a clean summary. Script building blocks variables functions exit codes strict mode (optional) Example: service health script Make it ex…