Quiz Module 8 - Services and Daemons
Instructions
This quiz contains 30 multiple-choice questions to validate your understanding of Module 8.
Tip: Answer each question before revealing the answer. The answers are hidden just after each question.
Question 1
Which command is used to manage systemd services on Ubuntu 24.04?
See explanation
Correct answer: systemctl
Explanation: systemctl is the main command to manage systemd services. Examples: systemctl start service, systemctl stop service, systemctl status service, systemctl enable service, systemctl restart service.
Question 2
Which command is used to start a service?
See explanation
Correct answer: systemctl start service
Explanation: sudo systemctl start service starts a service. Other commands: stop (stop), restart (restart), reload (reload config), status (view status).
Question 3
Which command is used to enable a service at startup?
See explanation
Correct answer: systemctl enable service
Explanation: sudo systemctl enable service enables a service at startup (creates a symbolic link). systemctl disable service disables. systemctl is-enabled service checks if enabled.
Question 4
Which command is used to view the status of a service?
See explanation
Correct answer: systemctl status service
Explanation: systemctl status service displays the detailed status of a service: active/inactive, running, recent logs, etc. Very useful for diagnosing issues.
Question 5
Where are the systemd service files located?
See explanation
Correct answer: /etc/systemd/system/ or /lib/systemd/system/
Explanation: The systemd .service files are in /lib/systemd/system/ (provided by packages) and /etc/systemd/system/ (custom, prioritized). After modification, run sudo systemctl daemon-reload.
Question 6
Which command is used to view the logs of a service?
See explanation
Correct answer: journalctl -u service
Explanation: journalctl -u service displays the logs of a specific service. Options: -f (follow in real-time), -n 50 (last 50 lines), --since today, --since "1 hour ago".
Question 7
Which command reloads the systemd configuration after modifying a service file?
See explanation
Correct answer: systemctl daemon-reload
Explanation: sudo systemctl daemon-reload reloads the systemd configuration after modifying a .service file. Necessary before starting/restarting a modified service. Do not confuse with systemctl reload service which reloads a running service's config.
Question 8
Which directory contains the system cron jobs (for all users)?
See explanation
Correct answer: /etc/cron.d/
Explanation: /etc/cron.d/ contains the system crontab files (for all users). Similar format to user crontab but with a user field. Files must have correct permissions (no execution).
Question 9
What is anacron?
See explanation
Correct answer: A system that executes periodic tasks even if the system was off
Explanation: anacron executes tasks from /etc/cron.daily/, /etc/cron.weekly/, /etc/cron.monthly/ even if the system was off at the scheduled time. Useful for systems that are not always on.
Question 10
What is the modern alternative to cron with systemd?
See explanation
Correct answer: systemd timers
Explanation: systemd.timer units are the modern alternative to cron. They offer more flexibility, better integration with systemd, and logging via journalctl. Format: .timer file + associated .service file.
Question 11
Which command is used to view all active services?
See explanation
Correct answer: systemctl list-units --type=service --state=running
Explanation: systemctl list-units --type=service lists all services. --state=running filters only the active ones. systemctl list-units --type=service --all also shows inactive ones.
Question 12
Which command is used to view active systemd timers?
See explanation
Correct answer: systemctl list-timers
Explanation: systemctl list-timers displays all systemd timers with their next execution. systemctl list-timers --all also shows inactive ones. Useful for viewing scheduled systemd tasks.
Question 13
Which command is used to view system logs in real-time?
See explanation
Correct answer: journalctl -f
Explanation: journalctl -f follows logs in real-time (like tail -f). journalctl -u service -f follows logs of a specific service. Ctrl+C to stop.
Question 14
Which command is used to view logs since the last boot?
See explanation
Correct answer: journalctl -b
Explanation: journalctl -b displays logs since the last boot. journalctl -b -1 shows logs from the previous boot. journalctl --list-boots lists all available boots.
Question 15
Which command is used to mask a service at startup?
See explanation
Correct answer: systemctl mask service
Explanation: sudo systemctl mask service completely prevents a service from starting (even manually). Creates a symbolic link to /dev/null. systemctl unmask service removes the mask. Stronger than disable.
Question 16
Which command is used to view a service's dependencies?
See explanation
Correct answer: systemctl list-dependencies service
Explanation: systemctl list-dependencies service displays the dependency tree of a service (required services). --reverse shows services that depend on it. Useful for understanding startup order.
Question 17
Which command is used to view cron job logs on Ubuntu 24.04?
See explanation
Correct answer: journalctl -u cron or grep CRON /var/log/syslog
Explanation: journalctl -u cron displays cron service logs. grep CRON /var/log/syslog searches for cron entries in system logs. Logs show executions and errors of cron jobs.
Question 18
Which command is used to create a custom systemd service?
See explanation
Correct answer: Create a .service file in /etc/systemd/system/
Explanation: To create a custom service, create a file /etc/systemd/system/my-service.service with the configuration. Then sudo systemctl daemon-reload and sudo systemctl enable my-service. The file must follow the systemd unit format.
Question 19
What is the syntax to run a cron job every day at 2:00 AM?
See explanation
Correct answer: 0 2 * * *
Explanation: 0 2 * * * means: minute 0, hour 2, every day, every month, every day of the week = every day at 2:00 AM. Format: minute hour day month weekday command.
Question 20
Which command is used to view systemd timers with their next executions?
See explanation
Correct answer: systemctl list-timers
Explanation: systemctl list-timers displays all active timers with their last and next execution. systemctl list-timers --all also shows inactive ones. Format: NEXT (next), LEFT (time left), LAST (last).
Question 21
Which command is used to restart a service?
See explanation
Correct answer: systemctl restart service
Explanation: sudo systemctl restart service stops and then restarts a service. systemctl reload service reloads the configuration without restarting (if the service supports it). restart is safer but may interrupt the service.
Question 22
Which command is used to check if a service is enabled at startup?
See explanation
Correct answer: systemctl is-enabled service
Explanation: systemctl is-enabled service returns "enabled", "disabled", or "masked". Useful in scripts to check the state. systemctl is-active service checks if the service is currently active.
Question 23
Which directory contains scripts executed daily by cron/anacron?
See explanation
Correct answer: /etc/cron.daily
Explanation: /etc/cron.daily/ contains scripts executed daily. Similar: /etc/cron.hourly/, /etc/cron.weekly/, /etc/cron.monthly/. These scripts are executed by run-parts or anacron.
Question 24
Which command is used to view a service's logs from the past hour?
See explanation
Correct answer: journalctl -u service --since "1 hour ago"
Explanation: journalctl -u service --since "1 hour ago" displays logs from the past hour. Other formats: --since today, --since "2024-12-01 10:00:00", --until "1 hour ago". Very flexible for time filtering.
Question 25
Which command is used to view all failed services?
See explanation
Correct answer: systemctl --failed
Explanation: systemctl --failed or systemctl list-units --state=failed displays all failed services. Useful for diagnosing startup issues. Then check with systemctl status service to see the error.
Question 26
What is the crontab syntax to run a task every Monday at 9:00 AM?
See explanation
Correct answer: 0 9 * * 1
Explanation: 0 9 * * 1 = minute 0, hour 9, every day, every month, Monday (1). Days of the week: 0 or 7 = Sunday, 1 = Monday, 2 = Tuesday, ..., 6 = Saturday.
Question 27
Which command is used to view system logs from today?
See explanation
Correct answer: journalctl --since today
Explanation: journalctl --since today displays logs since midnight today. Other options: --since yesterday, --since "2024-12-01", --since "1 hour ago". Very useful for filtering recent logs.
Question 28
Which command is used to reload a service's configuration without restarting it?
See explanation
Correct answer: systemctl reload service
Explanation: systemctl reload service reloads a service's configuration without stopping it (if the service supports it). Gentler than restart as it does not interrupt active connections. Not all services support reload.
Question 29
Which command is used to view systemd units of type timer?
See explanation
Correct answer: systemctl list-units --type=timer
Explanation: systemctl list-units --type=timer lists all systemd timers. systemctl list-timers is a shorter alias that also shows next executions. Useful for viewing all scheduled systemd tasks.
Question 30
Which command is used to start a systemd timer?
See explanation
Correct answer: systemctl start timer.timer
Explanation: sudo systemctl start my-timer.timer starts a systemd timer. systemctl enable my-timer.timer enables it at startup. The timer must have an associated .service file containing the command to execute.
Quiz Result
Congratulations on completing the Module 8 quiz!
Score:
- 25-30 correct answers: Excellent! You master service management and advanced cron.
- 20-24 correct answers: Very good! Review the concepts where you had difficulties.
- 15-19 correct answers: Good! Review the chapters on services and cron.
- Less than 15: Recommended to review the module before continuing.
Next Steps
Now that you have validated your knowledge:
Module 9: System Security
Practical Labs: Practice services and cron with Module 8 labs
Quiz created on: December 2024 - Tested on Ubuntu 24.04