RBCloud & DevOpsTHE PRACTICAL LEARNING LIBRARY
By Ravindra BagaleResources

CHAPTER 09 / 60

Packages, repositories, systemd and scheduled tasks

Install software and distinguish a running service from one enabled at boot.

Concept + practical labBy Ravindra Bagale · ~5 min read · lab time additional

Distribution differences

TaskAmazon Linux 2023Ubuntu 24.04 LTS
Package managerdnfapt
Refresh metadatasudo dnf makecachesudo apt update
Install a packagesudo dnf install -y nginxsudo apt install -y nginx
Apache servicehttpdapache2
Default SSH userec2-userubuntu

Package names, versions and repository availability vary. Inspect /etc/os-release, package information and enabled repositories. AL2023 uses versioned repositories; an update within the current release is not automatically a distribution release upgrade. Do not paste Amazon Linux 2 amazon-linux-extras instructions into AL2023.

Service lifecycle

bash
sudo systemctl status nginx --no-pager
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl is-enabled nginx
sudo systemctl reload nginx
sudo journalctl -u nginx -n 50 --no-pager

Start affects this boot; enable configures future boots. Reload asks a service to reread configuration when supported; restart stops and starts it. Run the service-specific config test before either. systemctl daemon-reload rereads unit definitions, not Nginx configuration.

Build a simple systemd service

Create /usr/local/bin/academy-clock with an executable script that prints a timestamp and sleeps in a loop. Create /etc/systemd/system/academy-clock.service:

ini
[Unit]
Description=Academy clock lab
After=network.target

[Service]
ExecStart=/usr/local/bin/academy-clock
User=nobody
Restart=on-failure
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target
bash
printf '#!/bin/sh\nwhile true; do date -Is; sleep 60; done\n' | sudo tee /usr/local/bin/academy-clock >/dev/null
sudo chmod 755 /usr/local/bin/academy-clock
sudo systemctl daemon-reload
sudo systemctl enable --now academy-clock
journalctl -u academy-clock -n 5

Scheduling

Cron uses minute, hour, day-of-month, month and day-of-week fields. 0 2 * * * /absolute/path/backup.sh runs daily at 02:00 in the scheduler's timezone. Cron has a limited environment: use full paths and capture logs. Systemd timers integrate with service logging and can support missed-run handling.

Practice and cleanup

Stop/disable the clock unit, remove only its two files, and run daemon-reload. Explain why enable without --now need not start a service immediately.

Official reference

systemd service documentation

Ravindra’s Tip

Start मतलब अभी चलाओ; enable मतलब boot पर चलाओ। दोनों अलग हैं, इसलिए restart के बाद भी service check करो।

Interview and revision check

What is the difference between reload and daemon-reload?

Service reload asks the application to reread its configuration when supported. systemctl daemon-reload rereads systemd unit definitions.

Ravindra Bagale · Cloud & DevOps Academy · Handbook and project downloads