Chapter 4: Linux Advanced Commands
4.6 Services: service, systemctl and journalctl
Students in my class always ask: "Sir, I installed Nginx – why doesn't the website open after a reboot?" Check the unit’s current activity, startup relationships, and the last boot’s service messages.
माझ्या क्लासमध्ये स्टुडंट्स नेहमी विचारतात: "सर, Nginx इन्स्टॉल केला, रीबूटनंतर वेबसाइट का उघडत नाही?" सर्व्हिसची सध्याची स्थिती, startup साठी केलेली जोडणी आणि boot मधल्या नोंदी वेगवेगळ्या तपासा.
मेरी क्लास में स्टूडेंट्स हमेशा पूछते हैं: "सर, Nginx इंस्टॉल किया, रीबूट के बाद वेबसाइट क्यों नहीं खुलती?" सर्विस की मौजूदा स्थिति, startup के लिए उसकी सेटिंग और boot के संदेश अलग-अलग जाँचें।
Many Linux distributions use systemd to manage background services. Use systemctl to query or control that manager. A distribution may also provide the service wrapper to run init scripts or delegate supported actions. Use the table as a comparison of purposes on an authorized lab host. The precise wrapper behavior depends on the local implementation.
Day-to-day control with service
| Command | Purpose | Direct systemctl equivalent |
|---|---|---|
sudo service nginx start |
Start now | systemctl start nginx |
sudo service nginx stop |
Stop now | systemctl stop nginx |
sudo service nginx restart |
Stop + start | systemctl restart nginx |
sudo service nginx reload |
Request the service-specific reload operation | systemctl reload nginx |
sudo service nginx status |
Report current service status using the wrapper’s supported display | systemctl status nginx |
service --status-all |
Check System V init scripts on wrappers that support this option | — |
Things only systemctl can do
| Command | Purpose |
|---|---|
sudo systemctl enable nginx |
Set up the unit’s configured startup relationships |
sudo systemctl disable nginx |
Remove enablement links without stopping the current unit |
systemctl is-active nginx / systemctl is-enabled nginx |
Check activity and unit-file state separately |
systemctl list-units --type=service --state=running |
Loaded services whose substate is running |
sudo systemctl daemon-reload |
Reread unit files and dependency definitions |
Ravindra Bagale's Tip
Start changes a unit’s runtime state. Enable sets up the unit’s documented startup relationships. Use systemctl is-active and systemctl is-enabled to check those observations separately.
Ravindra Bagale's Tip – मराठी
Start केल्यावर unit ची सध्याची स्थिती बदलते. Enable केल्यावर startup साठी unit ची जोडणी होते. systemctl is-active आणि systemctl is-enabled ने या दोन गोष्टी वेगवेगळ्या तपासा.
Ravindra Bagale's Tip – हिंदी
Start से unit की मौजूदा स्थिति बदलती है। Enable से startup के लिए unit का संबंध जुड़ता है। systemctl is-active और systemctl is-enabled से इन दोनों बातों की अलग-अलग जाँच करें।
service: command not found?
If the compatibility service command is absent on your systemd host, use systemctl directly. The exercises below use that command and need no init-script wrapper installation.
Logs with journalctl
Use journalctl to view the journal records available to your account. Some services also write application logs directly to files.
# Inspect the journal daemon on a Linux host already running systemd
journalctl -b -u systemd-journald.service -n 20 --no-pager
# Current boot, error priority or more urgent
journalctl -b -p err --no-pager
# Show how much journal data is accessible
journalctl --disk-usageLogs on Amazon Linux 2023
Amazon Linux 2023 uses the systemd journal by default, so conventional rsyslog files such as /var/log/messages may be absent. Application logs can still exist at paths configured by each application.
Ravindra Bagale's Tip
For an authorized Nginx change, validate the intended configuration with nginx -t before requesting the unit’s supported reload. With &&, a failed test prevents the next command from running. Verify the actual response after a reload.
Ravindra Bagale's Tip – मराठी
Nginx config बदलण्याची परवानगी असेल तर reload करण्यापूर्वी nginx -t ने ती तपासा. && वापरल्यावर test fail झाला तर पुढची command चालणार नाही. Reload नंतर मिळणारा response तपासा.
Ravindra Bagale's Tip – हिंदी
Nginx config बदलने की अनुमति हो तो reload से पहले nginx -t से उसे जाँचें। && के साथ test विफल हो तो अगली command नहीं चलेगी। Reload के बाद वास्तविक response जाँचें।
Lab
खालील workshop lab मध्ये स्वतःच्या user manager मध्ये दोन तात्पुरत्या units वापरा. एक यशस्वी आणि एक मुद्दाम fail होणारा job चालवा. systemctl ने दोन्ही स्थिती पहा आणि journalctl मध्ये उपलब्ध नोंदी तपासा.
Follow a request from the website to its service
The Mauli workshop hosts a handover page on a small Linux server. On Monday a student starts the web server and confirms the page opens. On Tuesday, after the practice server reboots, a coworker sees a connection error. Three different observations are immediately useful. The installed package files may still be present. The web server process may or may not be running at this moment. The service manager may or may not have instructions to start that program automatically when a boot target is reached. Collect these facts separately before deciding what failed.
A process is a running instance of a program. A program such as Nginx can have several processes, including a parent that manages workers. A background process that provides a continuing function is commonly called a daemon. Rather than asking one student to keep a terminal open to run the daemon, Linux installations using systemd can let a manager start and supervise it. A service unit names the object being managed and describes how the manager runs it. It can contain the executable, readiness behavior, process owner, dependencies, and stop or reload instructions. Different distributions can name and configure the unit differently even when the underlying program is similar.
systemd is the manager in this lesson and systemctl sends instructions or queries to that manager. On a conventional systemd-based machine one instance acts as the system manager and starts early in boot as process one. A user can also have a user service manager for processes under that user's account. The command systemctl --user targets that manager. It needs a working connection to the logged-in user's manager. A container image can contain a systemctl executable without running systemd as its system manager, and a server may have the system manager but no user manager for the current session. The presence of a command only tells you that the client program is installed.
The term unit covers more than services. A socket unit can arrange for work to be activated when a connection arrives. A timer unit can activate a service at a specified time. A target unit can group other units and represent a point in the startup process. When one unit depends on another, systemd can bring them up according to their relationship and ordering rules. This is why it is possible to see a service started even when a direct enable operation was never applied to it. Someone may have started it manually, a dependency may have pulled it in, or a socket or timer may have activated it.
There is also a difference between a manager's state and whether the page works. A service can be active and have an open listening socket but return an error page. Clients could be looking up the wrong address, connecting to a different port, or missing the particular hostname the server expects. In an EC2 case, a security group is one of the controls determining which traffic can reach the instance. The manager can tell you about the local service; a relevant application request tests additional parts of the path. In this lesson you will observe harmless sample units and interpret their results before applying the same thinking to a real service.
Read the current state and the startup policy separately
Start and stop act on the current service instance. Starting a service makes an immediate attempt to activate it. Stopping that service asks the manager to deactivate it, and may terminate its processes depending on the unit's stop behavior. Enable and disable affect installation relationships, commonly links that connect the unit to one or more targets. For a service declaring WantedBy=multi-user.target, enabling the properly installed unit commonly creates a link so that starting that target pulls in the unit. It does not run the service immediately unless combined with --now. The default target and dependencies of the machine determine what is reached during a boot.
Think through a concrete timeline. At 09:00 the workshop machine has an installed web service unit that reports disabled and inactive. At 09:05 the operator starts it for a demonstration. Now it can be active while its enablement status stays disabled. At 09:30 a colleague enables it, preparing the documented target relationship. Its runtime state stays active. At 10:00 the operator stops it after class. Its runtime state is now inactive while the installation relationship is still enabled. On the next boot the target can try to start it if that target is reached. If a required configuration file is invalid, the attempt can fail even though the enablement is correct.
| Action in this scenario | Runtime observation | Unit file observation |
|---|---|---|
| Before the demo | Inactive | Disabled |
| Manual start succeeded | Active | Disabled |
| Enabled while still running | Active | Enabled |
| Manual stop succeeded | Inactive | Enabled |
| Later boot tries an invalid config | Failed | Enabled |
This timeline assumes a regular service with enablement instructions, an appropriate target, and no automatic activation or restart interfering with the timeline. In other cases you may see static for a unit with no installation instructions, masked for a unit intentionally blocked from being started in the manager's active configuration, or transient for a service defined through the manager's runtime interface. A unit that is disabled can still be started. A mask has a stronger and different meaning. When reading the state, write down the complete word the manager reports instead of treating every result as one half of a yes or no pair.
systemctl is-active nginx.service asks about activity. systemctl is-enabled nginx.service reports unit file enablement or another applicable installation state. The exact unit name depends on the installation. For a single regular long-lived service, checking whether the printed value is active can be useful, while the exit status can drive a script. For enablement there are named states besides enabled and disabled. Some special states including transient and static can return success from is-enabled on documented systemd versions. Read the actual string when you need to distinguish them. A status alone is not proof of a boot-time link, and one unit's activity is not necessarily the condition of an application stack.
systemctl enable --now requests both enablement and immediate start. Check the results separately if you use it in an authorized operation. One intended change can succeed while the other fails. For example, installation links may exist but an application cannot read its configuration. disable by itself removes enablement relationships without stopping the running service. A stopped unit can also be triggered later by another active unit. In the training exercises here you will use read-only observation and short user-owned jobs, so no system boot settings will need to change.
Observe a service without changing it
Run these read-only checks from a Bash terminal on a Linux environment intended for this exercise. Standard systemd installations usually have the journal daemon unit. Its service name is independent of whether you use Nginx or Apache. No administrative permission is needed to request ordinary status, although some log details may be unavailable to your account. If the service manager cannot be reached, use the worked output under this block and continue on a Linux lab that actually runs systemd. An ordinary macOS terminal does not run this manager.
ps -p 1 -o comm=
systemctl --no-pager status systemd-journald.service
systemctl show systemd-journald.service \
-p LoadState -p ActiveState -p SubState -p UnitFileState
systemd
LoadState=loaded
ActiveState=active
SubState=running
UnitFileState=static
The example omits the expanded status display and shows one possible set of properties. Ordering and unit file state can differ with the distribution and how the unit is installed. The first command prints the name of process one in your environment. If its name is not systemd, an ordinary system manager query may fail there. In the status display, the load state says whether the manager found and understood the unit definition. The high-level active state describes activation, and the substate adds detail relevant to that kind of unit. A running daemon can be active with substate running. A one-off service can instead be active with substate exited if its successful action is configured to count as complete but active.
The status display is for people. It can show descriptions, processes, and a limited selection of recent log messages and may use a pager. The --no-pager flag prints directly to the terminal. systemctl show emits properties in a form more suited to inspecting the fields individually. Avoid cutting a column out of a human display when a corresponding property is documented, but still handle the possibility that the manager cannot be contacted or the named unit cannot be found. An error message instead of a status is an observation to explain, not a reason to change permissions or install an unrelated package.
Choose the operation that reaches the changed configuration
A service may have two configurations for different readers. Systemd reads its unit file, including settings for the command and dependencies. The application reads its own configuration, which might contain a web root, address, port, and file locations. If you edit the service unit on a machine you manage, systemctl daemon-reload tells the manager to reread unit definitions and rebuild dependency information. It does not by itself restart the unit or cause a running web server to reread its configuration. If you change how the unit starts its process and need the new launch behavior, review when and how to start a new instance after the unit definitions are reloaded.
systemctl reload name.service requests an application reload using the mechanism defined for that unit. Some services have no supported reload operation. Others respond to a signal, an executable command, or a protocol implemented by the application. For Nginx, a successful graceful reload can start new workers with the new configuration and allow existing worker processes to finish current requests. A failed configuration can be rejected while existing workers keep the old configuration. Treat the reload mechanism as service-specific, check its reported result, and verify the new behavior. Changing the application file is a separate step from updating the manager's unit definition.
systemctl restart name.service requests that the unit stop and start. It can create a period of unavailability. A failed start after the stop can leave the service unavailable until the operator repairs the cause. Decide whether you need that transition before using it. If the unit is due for a reviewed config change, first run the application's parser in its configuration-check mode. A command such as nginx -t is designed to test the configuration and attempt to open referred files. Use the relevant install's paths and permissions in an authorized change window. Passing this check is useful evidence about that configuration, while a service's actual application response still needs separate validation.
In a controlled Nginx workflow you can link the config test and reload with &&, which runs the second command only if the first returns zero. Before acting, confirm that both commands refer to the same application installation and configuration. Also keep the previous working config so the plan can recover if the new one changes behavior unexpectedly. An automated invocation should handle a failure in either operation. This lesson's lab makes no Nginx changes and demonstrates transitions using only your own short-lived user service.
The service command is a compatibility entry point on some Linux distributions. It commonly runs a System V style init script or delegates supported operations to the current service manager. Which commands and status details it supports depend on the operating system, platform, and particular service. On some systemd-based installs it forwards familiar actions such as start or status to systemctl. Its inventory option can list init scripts without giving a complete view of native systemd units. For a systemd server, learn the direct equivalents and use documentation for that host instead of assuming that a wrapper is installed or identical everywhere.
The choice of command should be tied to evidence. To ask whether a managed service is currently active, query its state. To identify which choices could pull it into startup, inspect unit file state and dependencies. To know whether people can use it, send an authorized request that exercises the required behavior. A service that is active and disabled might be behaving exactly as intended during a manual lab. One that is enabled and failed requires evidence about its last attempt, which is where the journal comes in.
Read the journal by unit, time, and priority
The systemd journal is a log store managed by the journald service. It accepts records from sources such as service stdout and stderr when configured, operating system messages, and other logging interfaces. Journal records can contain a message along with structured fields such as timestamps, program identity, service unit, and priority. The word structured means those details are stored as fields you can query, rather than only embedded in one long human-formatted line. Reading the journal with journalctl lets you narrow the view before interpreting the events.
For an initial read-only check, choose a recent time window and a known unit name from your lab. The next commands query the journal daemon itself and show retained boot records. A unit may log little or nothing in the selected time window. Your account may not have access to the relevant part of the journal. This read-only exercise does not grant those permissions, and its results legitimately vary by machine.
journalctl -b -u systemd-journald.service -n 10 --no-pager
journalctl -b -u systemd-journald.service --since '30 minutes ago' --no-pager
journalctl --list-boots --no-pager
The -b option with no offset means the current boot. The -u option filters for records associated with that system unit. The -n 10 option limits the first display to the last ten matching entries. The second command uses a time range and can return fewer or more than ten, depending on activity. The boot listing shows boot identifiers and the available time ranges in the retained journal. Some machines keep only volatile logs and therefore have no previous boots available. For a recorded outage, narrow by the timeframe you know and note the server timezone if reporting timestamps to someone on another machine.
For system-wide urgent entries in the current boot, an authorized reader can use journalctl -b -p err --no-pager. The single priority err includes error and more urgent priorities. A range form is available when you need particular levels. Priority is metadata about a log record, not a guarantee that a message containing the word error has a particular priority. If you start with a severe-only query, you can miss the informational lines showing what was attempted just before a failure. Approach a new incident by narrowing the unit and time first, then checking priority once you know which context is relevant.
A follow mode such as journalctl -f displays newly matching records as they arrive. Combine it with a unit filter in a busy environment. Control C stops the viewer, not the service the viewer is observing. For a written review, collecting a bounded recent view makes it clearer exactly which interval you inspected. Use --no-pager when you want to avoid launching the interactive reader. Human status uses short context displays, while a journal query lets you choose a slice that may reveal the cause preceding the final failure line.
Application logging can use separate files. Nginx can write an access log and an error log selected by its configuration, and a filtered view of its systemd unit need not contain those records. On Amazon Linux 2023, rsyslog is not installed by default and the systemd journal is the default system logging interface, so traditional files such as /var/log/messages may be absent. That doesn't remove logs written directly by an application. Learn where each kind of record originates and look there before interpreting absence as a sign that nothing happened.
Run a short user service without installing it
The workshop's first inspection helper simply prints that the worksheet was generated and exits. A one-off supervised job is commonly called a oneshot service. It gives you a way to observe start completion without needing a long-running process, network listener, or new software package. In this exercise you create a transient unit in your own systemd user manager. Transient means its definition is supplied for the current manager at runtime rather than installed as a unit file for later boot. The tool systemd-run sends this unit description and command to the manager.
Before running the lab, check that your Linux user session can contact its manager. The first command below queries general user manager state, which can say running or degraded depending on other units. The second asks for a limited unit listing, which is a read-only test of contact. If you see a message such as Failed to connect to bus, use the model outputs in this lesson or retry on a prepared systemd Linux session. An online shell or many container terminals will not host a user manager. Avoid switching to the system manager or using sudo to work around that prerequisite. A user unit is sufficient for this exercise.
systemctl --user is-system-running
systemctl --user --no-pager list-units --type=service
Once that check works and systemd-run is present, create a unique lab suffix from a new scratch directory. The basename part makes unit names specific to this exercise run. The scratch directory does not hold unit configuration. It only supplies the unique name, and you remove it at cleanup. The unit's command is intentionally one static message through /bin/sh and no real worksheet is produced. The message lets you connect an execution to its journal record.
svc_lab=$(mktemp -d) || exit 1
stamp=${svc_lab##*/}
ready_unit="mauli-ready-$stamp.service"
fail_unit="mauli-fail-$stamp.service"
printf 'Units for this exercise: %s %s\n' "$ready_unit" "$fail_unit"
systemd-run --user --unit="$ready_unit" --remain-after-exit \
--property=Type=oneshot --property=StandardOutput=journal \
--property=StandardError=journal \
/bin/sh -c 'echo "Mauli inspection worksheet generated"'
systemctl --user show "$ready_unit" \
-p LoadState -p ActiveState -p SubState -p UnitFileState -p Result -p ExecMainStatus
LoadState=loaded
ActiveState=active
SubState=exited
UnitFileState=transient
Result=success
ExecMainStatus=0
The manager can print properties in a different order and systemd-run also announces the unit it has started. The important combination is active and exited. Type=oneshot tells the manager to treat the start action as completed after the process finishes. The additional remain-after-exit setting explicitly keeps the unit's successful state active. The exit code of the main process was zero, yet there is no continuously running inspection process. This is a concrete example of why the high-level state needs its substate and why asking for a running daemon is a separate question.
Unit file state should be transient while the unit is loaded because it came from the runtime interface. You can compare the text from systemctl --user is-active "$ready_unit" with systemctl --user is-enabled "$ready_unit". The expected descriptions are active and transient, respectively. The second output is not the enablement of a regular installed unit. This unit was never linked to a target on disk for an automatic future boot. Observe both properties while the unit is still active, since a transient unit may disappear from the loaded unit set after it is stopped.
Read just the messages associated with this particular exercise run. The first flag chooses the user unit, using the same name you stored rather than guessing a suffix. The boot and time filters keep the display short, and the still-unique name makes it clear which job you are examining. One informative message should contain the words printed by the service command if your journal is configured to store them and your account can read the relevant records. The unit manager may also emit messages describing the start and finish.
journalctl --user-unit="$ready_unit" -b --since '15 minutes ago' -n 15 --no-pager
If you return to the example after the time window has passed, remove that time restriction and keep the exact unit filter. If you can reach the user manager but the journal has no corresponding entries, check whether user unit logs are available to your account. Installing a log service or modifying permissions is outside this exercise. You can still reason from Result=success and the main exit code, and document that the log visibility check could not be completed in your environment.
Use a controlled failure to practice diagnosis
A second training helper represents a known validation failure. Its shell prints one diagnostic and exits with status 42. The task is to find that evidence from a manager's status and the journal without guessing which package is missing. The deliberate failure belongs only to this temporary user unit. It does not edit the worksheet, touch a system unit, open a network port, or change startup policy.
if systemd-run --user --unit="$fail_unit" \
--property=Type=oneshot --property=StandardOutput=journal \
--property=StandardError=journal \
/bin/sh -c 'echo "Mauli test: worksheet validation failed" >&2; exit 42'; then
printf 'The start request returned success. Read the unit state next.\n'
else
printf 'The start request reported a problem. Read the unit state next.\n'
fi
systemctl --user show "$fail_unit" \
-p ActiveState -p SubState -p Result -p ExecMainCode -p ExecMainStatus
journalctl --user-unit="$fail_unit" -b -n 15 --no-pager
ActiveState=failed
SubState=failed
Result=exit-code
ExecMainStatus=42
The expected unit properties are shown without the execution code or journal display. The execution code distinguishes the kind of ending, such as ordinary exit instead of a termination signal. Do not assume the return code from the systemd-run command exactly equals the program's exit code. The manager is handling a start job and reports a separate result. The recorded main status is the specific evidence that the process exited with the planned value. The phrase about worksheet validation provides the context if the journal is available. A label such as failed is a category for the outcome, not a detailed explanation on its own.
Comparing the two units is a small diagnostic experiment. Their commands run under the same user's manager, their type is the same, and each gets its own name and journal selection. Only the second command has the deliberate failure outcome. In a real service that fails to start, early evidence could instead be a missing executable, invalid setting, access to a path the service owner lacks, a dependency that failed, or a limit on repeatedly starting the unit. Match the next check to the observed error. For example, a manager report that it could not execute the command sends you to the configured ExecStart and file access. An application message that it rejected a named setting means the application likely ran far enough to open and parse its settings.
The test creates no long-lived workers. Stop the successful unit so the manager can unload it, clear the expected failure for the other by its exact name, and remove the empty scratch directory. The last line clears the variables from the shell so they cannot accidentally refer to a previous run. A transient unit that is already removed can return a not-loaded diagnostic from a cleanup command. Check the name and state and remove only the specific test units you created. Do not reset every failed unit on the host, since they can carry evidence other people still need.
systemctl --user stop "$ready_unit"
systemctl --user reset-failed "$fail_unit"
rmdir -- "$svc_lab"
unset ready_unit fail_unit stamp svc_lab
The commands do not erase journal records. A retained message from this completed exercise is expected until it ages out according to the normal journal policy. A useful record of the exercise includes both generated unit names, their observed states and statuses, and the matched message. Keep those observations separate from application logs that may belong to another run or another service.
Choose your next check from the evidence
Suppose a classmate gives you three observations about the workshop website. The first is that the browser called the page unreachable at 10:12. The second is that the web server unit now reports active. The third is that the unit file state is enabled. Those observations describe different things at different times. They do not say when the unit came up or whether the browser reached the same machine afterward. Write down the observed time for each fact and add tests that answer a more specific question.
Start by identifying the server and exact unit relevant to the report. On a prepared Linux host with a known web service, a read-only systemctl list-unit-files --type=service can help find installed unit names. In a script, explicit names chosen from the deployment configuration are safer than assuming the package and unit names match. The SSH service, for example, may be named ssh.service or sshd.service depending on the distribution and installed configuration. A query for the wrong name can produce a load error even though the intended program exists. Likewise, a query addressed to the user manager sees different units from the system manager.
For an authorized systemd web-service host that actually has nginx.service, the following queries examine runtime and journal evidence without stopping or starting anything. The loopback request is an application test only if you are on that host, the expected service accepts HTTP on port 80, and the default host route serves the intended resource. Skip that request or change it to the known local health route according to the workshop's actual configuration. A Linux practice environment without Nginx can use the earlier journal daemon and user service examples instead.
systemctl --no-pager status nginx.service
systemctl show nginx.service -p LoadState -p ActiveState -p SubState -p Result
journalctl -b -u nginx.service --since '30 minutes ago' -n 30 --no-pager
curl -sS --max-time 3 -o /dev/null \
-w 'http_status=%{http_code}\n' http://127.0.0.1/
A local HTTP status such as 200 is evidence that an HTTP server returned a successful response for that exact request. It does not automatically show that it served the right handover page. Check the expected content in a suitable lab if that is part of the requirement. A status such as 404 is still a response and points you to the selected path and server configuration. The curl command here intentionally displays HTTP status without treating all 4xx or 5xx values as a failure to execute curl. It can also report a transfer error and display no valid HTTP status. That is a reason to check the listener address, protocol, or local environment before drawing a network conclusion.
A loopback request exercises the loopback path on a single machine. It does not cross the client's public ingress route or test DNS resolution for the real website. When the loopback request works but the browser fails, compare the actual scheme, hostname, port, and path the browser used. If relevant, use the configured application hostname, expected TLS setup, and an approved external test point. Do not repair these symptoms by reflexively restarting a service that already answered the appropriate local request. Collect evidence from the boundary where the result changes.
If the current boot query has no message corresponding to the incident, use journalctl --list-boots to see whether earlier boot logs are available. Query a particular retained boot only after confirming the timeline. A changed system time, a journal available only in memory, and a service that writes to its own file can each make the first query appear empty. The absolute time window can be narrowed using both since and until filters. The stronger your time and unit evidence, the less unrelated material you have to inspect.
At this point, consider the most useful next investigation for each result. With LoadState=not-found, verify the manager and exact installed name. With an enabled unit and Result=exit-code, inspect the last start attempt and main process exit status. With active (exited), read the unit type and the intended behavior. If the service is meant to listen on a port, inspect the actual listener and application behavior. Report a conclusion such as “the program ran and rejected a named config setting at 10:12” only when that message exists. A gap in evidence should lead to another observation.
Read a unit definition as a description of a launch
The following example shows a unit someone could write for the workshop's one-off inspection helper. Read it as a model rather than saving it on a live host. The transient lab already ran the same kind of action without installing a file. This definition illustrates how the persistent version would distinguish what runs, how the manager views completion, and which target would want it when it is enabled.
[Unit]
Description=Generate the workshop handover status message
[Service]
Type=oneshot
ExecStart=/bin/echo Workshop handover is ready
RemainAfterExit=yes
[Install]
WantedBy=default.target
In the service section, the first token in ExecStart is the program and the remaining words are arguments according to systemd's command-line rules. A shell is not implicitly available to interpret pipes or shell redirections in this directive. If a unit needs a more complex sequence, write a separate reviewed script and use that script as the named command. The service manager's working directory, environment, and user can differ from your interactive terminal, which explains a program that runs manually while failing inside a unit. Define any required paths and settings explicitly and read the unit from the perspective of the service account.
The install section provides instructions for creating a relationship to the named target when the appropriate manager enables it. The startup target differs by manager and use case. A user manager's default target is not the same operational context as a system service's startup graph. An installation in one manager can work while an apparently identical query in another says unknown. The unit example's type and remain-after-exit logic explain the successful lab's exited substate. A manager called with the proper instance, unit name, and current definition can then provide evidence that this is the unit actually loaded.
To read the files contributing to an existing unit definition, use systemctl cat name.service with the correct manager and observed unit name. It can display the main file along with overriding snippets called drop-ins. The file contents shown on disk may differ from the manager's current loaded settings if a unit changed before a daemon reload. For a troubleshooting case after unit edits, compare the stored configuration, the active definition reported by the manager, and the process that is currently running. Treat these as three stages of applying a change rather than one check.
Review an incident and confirm the recovery signal
For the first task, write the expected runtime and unit file states at each point in the demonstration timeline. Include one case that is active and disabled, one that is enabled and inactive, and one that is enabled and failed. Explain which operations could produce each pair without changing more settings than necessary. The evidence should refer to runtime state and configuration state separately. You can complete this task using the timeline and the read-only observations even when you cannot create a user unit.
For the second task, compare the results from both transient units on a prepared Linux session. Record the main exit status and whether one unique journal message was visible for each. Change the deliberate failure code from 42 to 43 in a fresh lab run and predict the new property. The result category should still describe an exit-code failure while the recorded status changes. Then return to the original test for a known good demonstration. Use unique unit names and the documented targeted cleanup for each run, so journal evidence for each attempt remains distinct.
For the third task, consider a coworker's scenario in which a local website answers with a not-found response. Ask for the expected local host name, path, response, and timestamp. Compare those with the specific request and any evidence in the relevant application access or error log. If the manager says the unit is active with no recent failures, you still need the log or response that addresses the request. A useful handover names the request that was tested and the configuration suspected, instead of applying new enablement or restart settings as a generic fix.
If your worksheet includes actual local logs, choose entries that pertain to the test and review whether they contain personal data, internal paths, or identifiers before sharing. The synthetic messages in this exercise are safe to quote as provided. Ubuntu, Amazon Linux and other distributions can package the journal or service wrapper differently. Record the environment and which commands connected successfully when comparing results with someone else's. That helps a second learner reproduce an observation and understand differences without treating a host's defaults as universal.
Explain the distinction in your own words
Interview question. Can a service be active but disabled?
Yes. A person, a dependency, a timer, or a socket can activate a service. Direct enablement describes relationships that let it participate in automatic startup. A disabled, manually started service can run normally now. Conversely, an enabled service can be stopped or can fail its startup attempt. Check both properties and the source of activation.
Interview question. When would you use daemon-reload?
Use it after reviewed changes to systemd unit files or related definitions so the manager rereads them. It does not read the application config on the application's behalf or replace a currently running process. In a changed Nginx configuration, first validate the application settings, use its supported reload where appropriate, and verify the response separately.
Quiz. The lab unit says active and exited. Is the process still doing ongoing work?
The lab's oneshot start action finished and exited with status zero. The setting to remain active lets systemd retain successful completion as an active state. For a different service, inspect its unit type and substate before deciding whether you should see a continuing process.
Quiz. Which evidence distinguishes the deliberately failed unit from a valid empty log result?
The manager reports result of exit-code and a main exit status of 42. If logging is visible, the message about worksheet validation provides the cause for this fixture. An empty filtered journal can result from timing or access, so keep the unit properties and journal observations separate.
Quiz. A service returns HTTP 404 on a known Linux lab. Which next question follows?
Ask which HTTP endpoint answered and whether the host and requested path are the expected ones. An HTTP answer is evidence about a responder for that request. Check the service configuration and application logs for that route before assuming a failure to start.
Revision cards
Activity is a runtime fact
Read the active state and substate together. Use both to tell a running daemon from a completed one-off unit that remains active.
Enablement is a startup relationship
Confirm the unit file state, expected target, and likely activation source. A start job can still fail after enablement.
Pick the log's scope
Choose the correct manager and unit, then inspect the needed boot and time interval. Check the application's own log when it writes events outside the journal.
Primary references
- Systemd systemctl manual for unit commands and states
- Systemd service unit documentation
- Systemd documentation for transient service units
- Systemd manual for journal usage and filters
- Amazon Linux 2023 documentation for system logging
- Nginx documentation for graceful reload
- Nginx documentation for configuration checks
- Systemd unit file format and installation settings
- Debian service command and wrapper behavior