forked from coreos/fedora-coreos-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
15fcos: remember when Ignition ran and print on console
Some users sometimes may not realize that they're using a pre-booted version of a CoreOS image. This makes things confusing because they then don't understand why the Ignition config wasn't applied. There's no way to consistently detect this, but at least we can print an informational message about (1) when Ignition ran, and (2) how many boots ago that was. This enhances the Ignition issue we already write for whether a user config was provided rather than creating a separate one. Related: bugzilla.redhat.com/show_bug.cgi?id=1977949 Related: coreos/ignition#1214
- Loading branch information
Showing
3 changed files
with
78 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 40 additions & 22 deletions
62
overlay.d/15fcos/usr/libexec/coreos-check-ignition-config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,44 @@ | ||
#!/usr/bin/bash | ||
# The logic for the message_id is handled in | ||
# https://github.com/coreos/ignition/pull/958 | ||
# In this script, we need to capture the journald | ||
# log with the particular message_id and query using | ||
#`jq` utility to check if a user config is provided. | ||
|
||
# Change the output color to yellow | ||
warn='\033[0;33m' | ||
# No color | ||
nc='\033[0m' | ||
|
||
# See https://github.com/coreos/ignition/pull/958 for the MESSAGE_ID source. | ||
# It will track the journal messages related to an Ignition config provided | ||
# by the user. | ||
output=$(journalctl -o json-pretty MESSAGE_ID=57124006b5c94805b77ce473e92a8aeb | jq -s '.[] | select(.IGNITION_CONFIG_TYPE == "user")'| wc -l) | ||
|
||
if [[ $output -gt 0 ]];then | ||
echo "Ignition: user-provided config was applied" > /etc/issue.d/30_ignition_config_info.issue | ||
set -euo pipefail | ||
|
||
is_firstboot=0 | ||
|
||
IGNITION_INFO=/var/lib/coreos/ignition.info.json | ||
|
||
IGNITION_FIRSTBOOT_INFO=/run/ignition.info.json | ||
if [ -e "${IGNITION_FIRSTBOOT_INFO}" ]; then | ||
is_firstboot=1 | ||
mkdir -p "$(dirname "${IGNITION_INFO}")" | ||
mv "${IGNITION_FIRSTBOOT_INFO}" "${IGNITION_INFO}" | ||
fi | ||
|
||
WARN='\033[0;33m' # yellow | ||
RESET='\033[0m' # reset | ||
|
||
mkdir -p /run/issue.d | ||
touch /run/issue.d/coreos-ignition-provisioning.issue | ||
|
||
d=$(jq -r .date "${IGNITION_INFO}") | ||
if jq -e .usercfg "${IGNITION_INFO}" &>/dev/null; then | ||
usercfg="with Ignition config" | ||
prefix="" | ||
suffix="" | ||
else | ||
usercfg="without Ignition config" | ||
prefix="$WARN" | ||
suffix="$RESET" | ||
fi | ||
|
||
if [ "${is_firstboot}" == 1 ]; then | ||
echo -e "${prefix}Ignition: ran on ${d} (this boot) ${usercfg}${suffix}" \ | ||
> /run/issue.d/coreos-ignition-provisioning.issue | ||
else | ||
echo -e "${warn}Ignition: no config provided by user${nc}" > /etc/issue.d/30_ignition_config_info.issue | ||
nreboots=$(($(journalctl --list-boots | wc -l) - 1)) | ||
[ "${nreboots}" -eq 1 ] && boot=boot || boot=boots | ||
echo -e "${prefix}Ignition: ran on ${d} (at least $nreboots $boot ago) ${usercfg}${suffix}" \ | ||
> /run/issue.d/coreos-ignition-provisioning.issue | ||
fi | ||
|
||
# Ask all running agetty instances to reload and update their | ||
# displayed prompts in case this script was run before agetty. | ||
/usr/sbin/agetty --reload | ||
# Our makeshift way of getting /run/issue.d semantics. See: | ||
# https://github.com/coreos/console-login-helper-messages/blob/e06fc88ae8fbcc3a422bc8c686f70c15aebb9d9a/usr/lib/console-login-helper-messages/issue.defs#L8-L17 | ||
ln -sf /run/issue.d/coreos-ignition-provisioning.issue /etc/issue.d/ |