Skip to content

Commit cc615a0

Browse files
m-horkyhenrywang
authored andcommitted
docs: Clarify first boot registration service
The original text roughly contained the steps to set up a service to register with on the next (first) boot, but contained some minor issues. Aside from typos/phrasing: - It talked of 'startup' and 'next boot', but effectively this would only get executed on first boot. - Command `touch .run_next_boot` was contained twice. Signed-off-by: mhorky <[email protected]>
1 parent 809b18b commit cc615a0

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

docs/src/building/management-services.md

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,45 @@
22

33
When running a fleet of systems, it is common to use a central management service. Commonly, these services provide a client to be installed on each system which connects to the central service. Often, the management service requires the client to perform a one time registration.
44

5-
The following example shows how to install the client into a bootc image and run it at startup to register the system. This example assumes the management-client handles future connections to the server, e.g. via a cron job or a separate systemd service. This example could be modified to create a persistent systemd service if that is required. The Containerfile is not optimized in order to more clarly explain each step, e.g. it's generally better to invoke RUN a single time to avoid creating multiple layers in the image.
5+
The following example shows how to install the client into a bootc image and run it at first boot to register the system. This example assumes the management-client handles future connections to its management server, e.g. via a cron job or a separate systemd service. This example could be modified to create a persistent systemd service if that is required. The Containerfile is not optimized in order to more clearly explain each step, e.g. it's generally better to invoke RUN a single time to avoid creating multiple layers in the image.
66

77
```Dockerfile
88
FROM <bootc base image>
99

10+
# Bake the credentials for the management service into the image.
11+
ARG activation_key=
12+
1013
# Typically when using a management service, it will determine when to upgrade the system.
1114
# So, disable bootc-fetch-apply-updates.timer if it is included in the base image.
1215
RUN systemctl disable bootc-fetch-apply-updates.timer
1316

14-
# Install the client from dnf, or some other method that applies for your client
17+
# Install the client from dnf, or some other method that applies for your client.
1518
RUN dnf install management-client -y && dnf clean all
1619

17-
# Bake the credentials for the management service into the image
18-
ARG activation_key=
19-
20-
# The existence of .run_next_boot acts as a flag to determine if the
21-
# registration is required to run when booting
22-
RUN touch /etc/management-client/.run_next_boot
23-
2420
COPY <<"EOT" /usr/lib/systemd/system/management-client.service
2521
[Unit]
26-
Description=Run management client at boot
22+
Description=Register with management client on first boot
2723
After=network-online.target
28-
ConditionPathExists=/etc/management-client/.run_client_next_boot
24+
ConditionPathExists=/etc/management-client/.register-on-first-boot
2925

3026
[Service]
3127
Type=oneshot
3228
EnvironmentFile=/etc/management-client/.credentials
29+
ExecStartPre=/bin/rm -f /etc/management-client/.register-on-first-boot
3330
ExecStart=/usr/bin/management-client register --activation-key ${CLIENT_ACTIVATION_KEY}
34-
ExecStartPre=/bin/rm -f /etc/management-client/.run_next_boot
3531
ExecStop=/bin/rm -f /etc/management-client/.credentials
3632

3733
[Install]
3834
WantedBy=multi-user.target
3935
EOT
4036

41-
# Link the service to run at startup
37+
# Link the service to run at startup.
4238
RUN ln -s /usr/lib/systemd/system/management-client.service /usr/lib/systemd/system/multi-user.target.wants/management-client.service
4339

44-
# Store the credentials in a file to be used by the systemd service
40+
# Store the credentials in a file, so it can used by the systemd service.
4541
RUN echo -e "CLIENT_ACTIVATION_KEY=${activation_key}" > /etc/management-client/.credentials
4642

47-
# Set the flag to enable the service to run one time
48-
# The systemd service will remove this file after the registration completes the first time
49-
RUN touch /etc/management-client/.run_next_boot
43+
# This file exists as a condition flag for the management-client.service.
44+
# It will be removed once the registration finishes.
45+
RUN touch /etc/management-client/.register-on-first-boot
5046
```
51-

0 commit comments

Comments
 (0)