Compare commits
12
Commits
v0.1.1
...
ci-log-steps
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8230de065f | ||
|
|
d0833ad563 | ||
|
|
8eebf73258 | ||
|
|
16637c3b38 | ||
|
|
4f83d134c1 | ||
|
|
29849c6254 | ||
|
|
4e5e6d96b7 | ||
|
|
e764c9c277 | ||
|
|
ebed809e43 | ||
|
|
c1449439e8 | ||
|
|
795819d5c8 | ||
|
|
7bcc384cfe |
No files matched your search
@@ -36,10 +36,10 @@ steps:
|
||||
commands:
|
||||
- git remote set-url origin "https://wvhulle:$${CODEBERG_TOKEN}@codeberg.org/$${CI_REPO}.git"
|
||||
- git checkout -B main "$${CI_COMMIT_SHA}"
|
||||
- nix run .#release-plz-release
|
||||
- nix run --quiet .#release-plz-release
|
||||
|
||||
- name: update-release-pr
|
||||
image: nixos/nix:latest
|
||||
environment: *release_env
|
||||
commands:
|
||||
- nix run .#release-plz-release-pr
|
||||
- nix run --quiet .#release-plz-release-pr
|
||||
@@ -8,74 +8,69 @@ variables:
|
||||
experimental-features = nix-command flakes
|
||||
build-users-group =
|
||||
accept-flake-config = true
|
||||
- &cache_writing_env
|
||||
<<: *nix_config
|
||||
CACHIX_AUTH_TOKEN:
|
||||
from_secret: cachix_auth_token
|
||||
- &on_main_branch
|
||||
- event: [push, manual]
|
||||
branch: main
|
||||
- &off_main_branch
|
||||
- event: pull_request
|
||||
- event: [push, manual]
|
||||
branch:
|
||||
exclude: main
|
||||
- &on_pull_requests
|
||||
- event: pull_request
|
||||
|
||||
steps:
|
||||
- name: build-test-and-cache-bootvine
|
||||
- name: build-workspace-dependencies
|
||||
image: nixos/nix:latest
|
||||
depends_on: []
|
||||
when: *on_main_branch
|
||||
environment: *cache_writing_env
|
||||
environment: *nix_config
|
||||
commands:
|
||||
- nix run .#build-and-push-to-cachix -- .#checks.x86_64-linux.bootvine-build
|
||||
- nix run --quiet .#build-unless-cached -- .#packages.x86_64-linux.workspace-dependencies
|
||||
|
||||
- name: build-and-test-bootvine
|
||||
image: nixos/nix:latest
|
||||
depends_on: []
|
||||
when: *off_main_branch
|
||||
depends_on: [build-workspace-dependencies]
|
||||
environment: *nix_config
|
||||
commands:
|
||||
- nix build --print-build-logs .#checks.x86_64-linux.bootvine-build
|
||||
|
||||
- name: build-and-cache-repo-tasks
|
||||
image: nixos/nix:latest
|
||||
depends_on: []
|
||||
when: *on_main_branch
|
||||
environment: *cache_writing_env
|
||||
commands:
|
||||
- nix run .#build-and-push-to-cachix -- .#checks.x86_64-linux.repo-tasks-build
|
||||
- nix run --quiet .#import-exported-paths
|
||||
- nix run --quiet .#build-and-export-paths -- .#checks.x86_64-linux.bootvine-build
|
||||
|
||||
- name: build-repo-tasks
|
||||
image: nixos/nix:latest
|
||||
depends_on: []
|
||||
when: *off_main_branch
|
||||
depends_on: [build-workspace-dependencies]
|
||||
environment: *nix_config
|
||||
commands:
|
||||
- nix build --print-build-logs .#checks.x86_64-linux.repo-tasks-build
|
||||
- nix run --quiet .#import-exported-paths
|
||||
- nix run --quiet .#build-and-export-paths -- .#checks.x86_64-linux.repo-tasks-build
|
||||
|
||||
- name: upload-build-cache
|
||||
image: nixos/nix:latest
|
||||
depends_on: [build-and-test-bootvine, build-repo-tasks]
|
||||
when:
|
||||
- event: [push, manual]
|
||||
branch: main
|
||||
status: [success, failure]
|
||||
environment:
|
||||
<<: *nix_config
|
||||
CACHIX_AUTH_TOKEN:
|
||||
from_secret: cachix_auth_token
|
||||
commands:
|
||||
- nix run --quiet .#upload-exported-paths
|
||||
|
||||
- name: lint-rust-with-clippy
|
||||
image: nixos/nix:latest
|
||||
depends_on: []
|
||||
depends_on: [build-workspace-dependencies]
|
||||
environment: *nix_config
|
||||
commands:
|
||||
- nix build --print-build-logs .#checks.x86_64-linux.clippy-lints
|
||||
- nix run --quiet .#import-exported-paths
|
||||
- nix build --quiet --print-build-logs .#checks.x86_64-linux.clippy-lints
|
||||
|
||||
- name: check-rust-formatting
|
||||
image: nixos/nix:latest
|
||||
depends_on: []
|
||||
depends_on: [build-workspace-dependencies]
|
||||
environment: *nix_config
|
||||
commands:
|
||||
- nix build --print-build-logs .#checks.x86_64-linux.rustfmt-formatting
|
||||
- nix run --quiet .#import-exported-paths
|
||||
- nix build --quiet --print-build-logs .#checks.x86_64-linux.rustfmt-formatting
|
||||
|
||||
- name: evaluate-flake-outputs
|
||||
image: nixos/nix:latest
|
||||
depends_on: []
|
||||
environment: *nix_config
|
||||
commands:
|
||||
- nix flake check --no-build
|
||||
- nix flake check --quiet --no-build
|
||||
|
||||
- name: check-conventional-commit-messages
|
||||
image: nixos/nix:latest
|
||||
@@ -84,4 +79,4 @@ steps:
|
||||
environment: *nix_config
|
||||
commands:
|
||||
- git fetch --quiet origin "$${CI_COMMIT_TARGET_BRANCH}"
|
||||
- nix run .#check-conventional-commits -- FETCH_HEAD..HEAD
|
||||
- nix run --quiet .#check-conventional-commits -- FETCH_HEAD..HEAD
|
||||
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.1.2](https://codeberg.org/wvhulle/bootvine/compare/v0.1.1...v0.1.2) - 2026-11-02
|
||||
|
||||
### Added
|
||||
|
||||
- show the kernel's image loading progress while resuming from hibernation
|
||||
- say when the screen is waiting for the system manager
|
||||
|
||||
### Changed
|
||||
|
||||
- reduce screen spacing to a small named set and declarative layouts
|
||||
|
||||
### Fixed
|
||||
|
||||
- repaint the whole screen while the root switches
|
||||
- finish console setup before resuming from hibernation
|
||||
|
||||
## [0.1.1](https://codeberg.org/wvhulle/bootvine/compare/v0.1.0...v0.1.1) - 2026-10-30
|
||||
|
||||
### Changed
|
||||
|
||||
Generated
+1
-1
@@ -144,7 +144,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bootvine"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"crossterm 0.29.0",
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ name = "bootvine"
|
||||
readme = "../README.md"
|
||||
repository = "https://codeberg.org/wvhulle/bootvine"
|
||||
rust-version = "1.91"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
@@ -94,6 +94,11 @@ impl BootState {
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn awaits_manager(&self) -> bool {
|
||||
self.root == Root::Unresolved
|
||||
}
|
||||
|
||||
pub fn set_root(&mut self, root: String) {
|
||||
if self.phase == Phase::User && !self.milestone_targets.contains(&root) {
|
||||
self.milestone_targets.push(root.clone());
|
||||
@@ -189,7 +194,7 @@ impl BootState {
|
||||
};
|
||||
let outcome = match result {
|
||||
JobResult::Done => Outcome::Succeeded { at },
|
||||
JobResult::Skipped | JobResult::Canceled => Outcome::Abandoned,
|
||||
JobResult::Skipped | JobResult::Canceled | JobResult::Collected => Outcome::Abandoned,
|
||||
JobResult::Failed => Outcome::Failed(FailureKind::Broke),
|
||||
JobResult::Timeout => Outcome::Failed(FailureKind::TimedOut),
|
||||
JobResult::Dependency => Outcome::Failed(FailureKind::DependencyFailed),
|
||||
@@ -332,6 +337,20 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_collected_job_on_a_multi_device_mount_source_is_not_a_failure() {
|
||||
let mut state = BootState::new(Phase::Initrd);
|
||||
queue_unit(
|
||||
&mut state,
|
||||
1,
|
||||
waiting("dev-nvme0n1p1:-dev-nvme1n1p3.device", &[]),
|
||||
500 * MS,
|
||||
);
|
||||
state.finish_job(1, JobResult::Collected, 2000 * MS);
|
||||
assert!(state.failed.is_empty());
|
||||
assert_eq!(state.tally().failed, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_unit_entering_the_failed_state_counts_without_a_failed_job() {
|
||||
let mut state = sample();
|
||||
|
||||
@@ -20,6 +20,7 @@ pub enum JobResult {
|
||||
Done,
|
||||
Skipped,
|
||||
Canceled,
|
||||
Collected,
|
||||
Timeout,
|
||||
Dependency,
|
||||
#[serde(other)]
|
||||
@@ -162,6 +163,7 @@ mod tests {
|
||||
);
|
||||
assert_eq!(from_str("maintenance").ok(), Some(ActiveState::Inactive));
|
||||
assert_eq!(from_str("dependency").ok(), Some(JobResult::Dependency));
|
||||
assert_eq!(from_str("collected").ok(), Some(JobResult::Collected));
|
||||
assert_eq!(from_str("frozen").ok(), Some(JobResult::Failed));
|
||||
assert_eq!(from_str("stop").ok(), Some(JobKind::TakesDown));
|
||||
assert_eq!(from_str("restart").ok(), Some(JobKind::BringsUp));
|
||||
|
||||
+31
-40
@@ -7,6 +7,7 @@ mod run_timeline;
|
||||
mod screen_chrome;
|
||||
#[cfg(test)]
|
||||
mod screen_render_fixtures;
|
||||
mod screen_spacing;
|
||||
mod stage_summary;
|
||||
mod tree_height_fitting;
|
||||
#[cfg(test)]
|
||||
@@ -18,7 +19,10 @@ use std::time::Duration;
|
||||
use jiff::fmt::friendly::{Designator, FractionalUnit, Spacing, SpanPrinter};
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Constraint, Layout, Rect},
|
||||
layout::{
|
||||
Constraint::{Fill, Length},
|
||||
Layout, Rect,
|
||||
},
|
||||
style::Color,
|
||||
text::Line,
|
||||
widgets::{Block, Borders, Widget},
|
||||
@@ -29,8 +33,9 @@ use unicode_width::UnicodeWidthStr;
|
||||
pub use self::screen_chrome::PasswordPrompt;
|
||||
use self::{
|
||||
failure_panel::FailurePanel,
|
||||
run_timeline::{RunningRun, Timeline},
|
||||
screen_chrome::{FOOTER_HEIGHT, Footer, Header, PasswordPopup},
|
||||
run_timeline::{RunningRun, Timeline, timeline_fits},
|
||||
screen_chrome::{Footer, Header, PasswordPopup},
|
||||
screen_spacing::{PANEL_MINIMUM_HEIGHT, RULED_ROW_HEIGHT, TEXT_ROW_HEIGHT},
|
||||
stage_summary::Stages,
|
||||
tree_height_fitting::rows_within_height,
|
||||
unit_tree::UnitTree,
|
||||
@@ -43,14 +48,7 @@ use crate::{
|
||||
screen_settings::{color_scheme::Colors, config_file::Timing, font_glyphs::Glyphs},
|
||||
};
|
||||
|
||||
const DURATION_WIDTH: u16 = 9;
|
||||
const MIN_BAR_WIDTH: u16 = 12;
|
||||
const MIN_HEIGHT_FOR_TIMELINE: u16 = 12;
|
||||
const MIN_TIMELINE_HEIGHT: u16 = run_timeline::CHROME_HEIGHT + 4;
|
||||
const HEADER_HEIGHT: u16 = 1;
|
||||
const MIN_FAILURE_PANEL_HEIGHT: u16 = failure_panel::RULE_HEIGHT + 1;
|
||||
const RESERVED_FAILURE_PANEL_HEIGHT: u16 = failure_panel::RULE_HEIGHT + 3;
|
||||
const MIN_TREE_HEIGHT_BESIDE_FAILURES: u16 = 4;
|
||||
const MIN_TIMELINE_HEIGHT: u16 = RULED_ROW_HEIGHT + PANEL_MINIMUM_HEIGHT;
|
||||
const BRANCH: &str = "├─ ";
|
||||
const LAST_BRANCH: &str = "└─ ";
|
||||
const PASSING_TRUNK: &str = "│ ";
|
||||
@@ -160,18 +158,23 @@ impl Widget for BootView<'_> {
|
||||
colors: &self.colors.footer,
|
||||
glyphs: self.glyphs,
|
||||
};
|
||||
let fits_timeline = area.width >= run_timeline::LABEL_WIDTH + 1 + MIN_BAR_WIDTH
|
||||
&& area.height >= MIN_HEIGHT_FOR_TIMELINE;
|
||||
let free = area
|
||||
.height
|
||||
.saturating_sub(HEADER_HEIGHT + stages.height() + FOOTER_HEIGHT);
|
||||
let [header_area, stage_area, body_area, footer_area] = area.layout(&Layout::vertical([
|
||||
Length(TEXT_ROW_HEIGHT),
|
||||
Length(stages.height()),
|
||||
Fill(1),
|
||||
Length(RULED_ROW_HEIGHT),
|
||||
]));
|
||||
let heights = Heights::share(
|
||||
free,
|
||||
body_area.height,
|
||||
UnitTree::height_of(pending_count, 0),
|
||||
failure_panel.height(),
|
||||
if fits_timeline { timeline.height() } else { 0 },
|
||||
if timeline_fits(body_area) {
|
||||
timeline.height()
|
||||
} else {
|
||||
0
|
||||
},
|
||||
);
|
||||
let budget = usize::from(heights.tree.saturating_sub(1));
|
||||
let budget = usize::from(heights.tree.saturating_sub(TEXT_ROW_HEIGHT));
|
||||
let rows = rows_within_height(forest, budget);
|
||||
let tree = UnitTree {
|
||||
phase: stages.current_phase(),
|
||||
@@ -184,24 +187,12 @@ impl Widget for BootView<'_> {
|
||||
};
|
||||
let tree_height = tree.height().min(heights.tree);
|
||||
|
||||
let [
|
||||
header_area,
|
||||
stage_area,
|
||||
tree_area,
|
||||
_,
|
||||
failure_area,
|
||||
timeline_area,
|
||||
footer_area,
|
||||
] = Layout::vertical([
|
||||
Constraint::Length(HEADER_HEIGHT),
|
||||
Constraint::Length(stages.height()),
|
||||
Constraint::Length(tree_height),
|
||||
Constraint::Fill(1),
|
||||
Constraint::Length(heights.failures),
|
||||
Constraint::Length(heights.timeline),
|
||||
Constraint::Length(FOOTER_HEIGHT),
|
||||
])
|
||||
.areas(area);
|
||||
let [tree_area, _, failure_area, timeline_area] = body_area.layout(&Layout::vertical([
|
||||
Length(tree_height),
|
||||
Fill(1),
|
||||
Length(heights.failures),
|
||||
Length(heights.timeline),
|
||||
]));
|
||||
|
||||
header.render(header_area, buf);
|
||||
stages.render(stage_area, buf);
|
||||
@@ -232,13 +223,13 @@ struct Heights {
|
||||
|
||||
impl Heights {
|
||||
fn share(free: u16, tree_need: u16, failures_need: u16, timeline_need: u16) -> Self {
|
||||
let reserved = RESERVED_FAILURE_PANEL_HEIGHT
|
||||
let reserved = PANEL_MINIMUM_HEIGHT
|
||||
.min(failures_need)
|
||||
.min(free.saturating_sub(MIN_TREE_HEIGHT_BESIDE_FAILURES));
|
||||
.min(free.saturating_sub(PANEL_MINIMUM_HEIGHT));
|
||||
let failures = failures_need
|
||||
.min(free.saturating_sub(tree_need))
|
||||
.max(reserved);
|
||||
let failures = if failures >= MIN_FAILURE_PANEL_HEIGHT {
|
||||
let failures = if failures >= RULED_ROW_HEIGHT {
|
||||
failures
|
||||
} else {
|
||||
0
|
||||
|
||||
@@ -9,16 +9,15 @@ use ratatui::{
|
||||
};
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use super::{fit_width, rule};
|
||||
use super::{
|
||||
fit_width, rule,
|
||||
screen_spacing::{TEXT_GAP, TEXT_INDENT, TEXT_ROW_HEIGHT},
|
||||
};
|
||||
use crate::{
|
||||
boot_model::{FailedUnit, FailureExplanation},
|
||||
screen_settings::{color_scheme::FailureColors, font_glyphs::Glyphs},
|
||||
};
|
||||
|
||||
pub const RULE_HEIGHT: u16 = 1;
|
||||
const LOG_INDENT: &str = " ";
|
||||
const REASON_GAP: &str = " ";
|
||||
|
||||
pub struct FailurePanel<'a> {
|
||||
pub newest_first: Vec<&'a FailedUnit>,
|
||||
pub colors: &'a FailureColors,
|
||||
@@ -42,14 +41,14 @@ impl FailurePanel<'_> {
|
||||
.iter()
|
||||
.map(|failed| 1 + log_lines(failed).len())
|
||||
.sum();
|
||||
RULE_HEIGHT.saturating_add(u16::try_from(rows).unwrap_or(u16::MAX))
|
||||
TEXT_ROW_HEIGHT.saturating_add(u16::try_from(rows).unwrap_or(u16::MAX))
|
||||
}
|
||||
|
||||
fn headline(&self, failed: &FailedUnit, width: usize) -> Line<'static> {
|
||||
let marker = format!("{} ", self.glyphs.failed);
|
||||
let label_room = width.saturating_sub(marker.width());
|
||||
let label = fit_width(&failed.label, label_room, self.glyphs.ellipsis);
|
||||
let reason_room = label_room.saturating_sub(label.width() + REASON_GAP.width());
|
||||
let reason_room = label_room.saturating_sub(label.width() + TEXT_GAP.width());
|
||||
let reason = match &failed.explanation {
|
||||
FailureExplanation::Explained(cause) if reason_room > 0 => {
|
||||
fit_width(&cause.reason, reason_room, self.glyphs.ellipsis)
|
||||
@@ -57,7 +56,7 @@ impl FailurePanel<'_> {
|
||||
_ => String::new(),
|
||||
};
|
||||
let reason_span =
|
||||
(!reason.is_empty()).then(|| format!("{REASON_GAP}{reason}").fg(self.colors.reason));
|
||||
(!reason.is_empty()).then(|| format!("{TEXT_GAP}{reason}").fg(self.colors.reason));
|
||||
Line::from(
|
||||
[
|
||||
marker.fg(self.colors.unit),
|
||||
@@ -70,11 +69,11 @@ impl FailurePanel<'_> {
|
||||
}
|
||||
|
||||
fn block(&self, failed: &FailedUnit, width: usize) -> Vec<Line<'static>> {
|
||||
let log_room = width.saturating_sub(LOG_INDENT.width());
|
||||
let log_room = width.saturating_sub(TEXT_INDENT.width());
|
||||
once(self.headline(failed, width))
|
||||
.chain(log_lines(failed).iter().map(|line| {
|
||||
format!(
|
||||
"{LOG_INDENT}{}",
|
||||
"{TEXT_INDENT}{}",
|
||||
fit_width(line, log_room, self.glyphs.ellipsis)
|
||||
)
|
||||
.fg(self.colors.log)
|
||||
@@ -170,8 +169,8 @@ mod tests {
|
||||
panel_text(&failures, 5),
|
||||
[
|
||||
"× web exited with status 1",
|
||||
" bind: address in use",
|
||||
" giving up",
|
||||
" bind: address in use",
|
||||
" giving up",
|
||||
"× db exited with status 1",
|
||||
"× cache exited with status 1",
|
||||
]
|
||||
@@ -189,10 +188,10 @@ mod tests {
|
||||
panel_text(&failures, 6),
|
||||
[
|
||||
"× web exited with status 1",
|
||||
" giving up",
|
||||
" giving up",
|
||||
"× db exited with status 1",
|
||||
" disk full",
|
||||
" read-only file system",
|
||||
" disk full",
|
||||
" read-only file system",
|
||||
"× cache exited with status 1",
|
||||
]
|
||||
);
|
||||
|
||||
@@ -13,6 +13,24 @@ use crate::{
|
||||
const CRYPTSETUP_MESSAGE: &str =
|
||||
"Please enter passphrase for disk Samsung SSD 980 PRO 1TB (cryptroot):";
|
||||
|
||||
#[test]
|
||||
fn the_stage_says_when_the_manager_has_not_answered_yet() {
|
||||
let mut state = BootState::new(Phase::Host);
|
||||
let lines = render(&state, 500 * MS, 110, 24);
|
||||
assert!(
|
||||
lines[1].contains("Stage 2") && lines[1].contains("waiting for the system manager"),
|
||||
"{}",
|
||||
lines.join("\n")
|
||||
);
|
||||
state.set_root("graphical.target".to_owned());
|
||||
let lines = render(&state, 500 * MS, 110, 24);
|
||||
assert!(
|
||||
lines.iter().all(|line| !line.contains("system manager")),
|
||||
"{}",
|
||||
lines.join("\n")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tree_on_top_timeline_below() {
|
||||
let lines = render(&boot_in_progress(), 12_400 * MS, 110, 24);
|
||||
@@ -65,7 +83,7 @@ fn tree_on_top_timeline_below() {
|
||||
);
|
||||
assert!(!screen.contains("root switch"), "{screen}");
|
||||
assert!(
|
||||
lines[23].starts_with("√ 2 done 2 running 3 waiting × 1 failed"),
|
||||
lines[23].starts_with("√ 2 done 2 running 3 waiting × 1 failed"),
|
||||
"{screen}"
|
||||
);
|
||||
}
|
||||
@@ -99,7 +117,7 @@ fn password_prompt_floats_over_a_dimmed_view() {
|
||||
assert!(lines[title_row + 3].contains("│ > ***_"), "{screen}");
|
||||
assert!(lines[title_row + 4].contains("Enter unlock"), "{screen}");
|
||||
assert!(
|
||||
lines[23].starts_with("√ 2 done 2 running 3 waiting × 1 failed"),
|
||||
lines[23].starts_with("√ 2 done 2 running 3 waiting × 1 failed"),
|
||||
"{screen}"
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -239,7 +257,7 @@ fn long_timeline_labels_end_in_an_ellipsis() {
|
||||
|
||||
#[test]
|
||||
fn narrow_screens_drop_the_timeline() {
|
||||
let lines = render(&boot_in_progress(), 12_400 * MS, 40, 24);
|
||||
let lines = render(&boot_in_progress(), 12_400 * MS, 37, 24);
|
||||
assert!(
|
||||
lines.iter().all(|line| !line.contains('■')),
|
||||
"{}",
|
||||
@@ -427,10 +445,10 @@ fn failures_show_their_reason_and_journal_lines_above_the_timeline() {
|
||||
);
|
||||
assert_eq!(
|
||||
lines[failures + 2],
|
||||
" ERROR! Failed to get system power limits",
|
||||
" ERROR! Failed to get system power limits",
|
||||
"{screen}"
|
||||
);
|
||||
assert_eq!(lines[failures + 3], " giving up", "{screen}");
|
||||
assert_eq!(lines[failures + 3], " giving up", "{screen}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -448,7 +466,7 @@ fn failure_lines_are_cut_to_a_narrow_screen() {
|
||||
);
|
||||
assert_eq!(
|
||||
lines[failures + 2],
|
||||
" ERROR! Failed to get syst…",
|
||||
" ERROR! Failed to get syste…",
|
||||
"{screen}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@ use std::{cmp::Reverse, iter::once, time::Duration};
|
||||
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Constraint, Layout, Rect},
|
||||
layout::{
|
||||
Constraint::{Fill, Length},
|
||||
Layout, Rect,
|
||||
},
|
||||
style::{Color, Stylize},
|
||||
symbols::Marker,
|
||||
text::{Line, Span},
|
||||
@@ -12,18 +15,22 @@ use ratatui::{
|
||||
},
|
||||
};
|
||||
|
||||
use super::{WHOLE_UNITS, fit_width, rule, unit_count};
|
||||
use super::{
|
||||
WHOLE_UNITS, fit_width, rule,
|
||||
screen_spacing::{
|
||||
ANNOTATION_COLUMN_WIDTH, COLUMN_GAP_WIDTH, RULED_ROW_HEIGHT, TEXT_ROW_HEIGHT,
|
||||
TIMELINE_LABEL_WIDTH,
|
||||
},
|
||||
unit_count,
|
||||
};
|
||||
use crate::{
|
||||
boot_model::{FinishedRun, MilestoneRow},
|
||||
screen_settings::{color_scheme::TimelineColors, font_glyphs::Glyphs},
|
||||
};
|
||||
|
||||
pub const LABEL_WIDTH: u16 = 28;
|
||||
pub const CHROME_HEIGHT: u16 = 2;
|
||||
const MARK_WIDTH: u16 = 2;
|
||||
const SLOWEST_RUNS_SHOWN: usize = 5;
|
||||
const KERNEL_ORIGIN_LABEL: &str = "Kernel";
|
||||
const AXIS_LABEL_SPACING: u16 = 8;
|
||||
const AXIS_STEPS: [Duration; 12] = [
|
||||
Duration::from_secs(1),
|
||||
Duration::from_secs(2),
|
||||
@@ -56,6 +63,17 @@ pub struct RunningRun<'a> {
|
||||
pub since: Duration,
|
||||
}
|
||||
|
||||
fn label_and_bar_areas(area: Rect) -> [Rect; 2] {
|
||||
area.layout(
|
||||
&Layout::horizontal([Length(TIMELINE_LABEL_WIDTH), Fill(1)]).spacing(COLUMN_GAP_WIDTH),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn timeline_fits(area: Rect) -> bool {
|
||||
let [_, bar_area] = label_and_bar_areas(area);
|
||||
bar_area.width >= ANNOTATION_COLUMN_WIDTH
|
||||
}
|
||||
|
||||
impl Timeline<'_> {
|
||||
pub fn height(&self) -> u16 {
|
||||
let entries = self.milestones.len()
|
||||
@@ -64,11 +82,11 @@ impl Timeline<'_> {
|
||||
if entries == 0 {
|
||||
return 0;
|
||||
}
|
||||
CHROME_HEIGHT.saturating_add(u16::try_from(entries).unwrap_or(u16::MAX))
|
||||
RULED_ROW_HEIGHT.saturating_add(u16::try_from(entries).unwrap_or(u16::MAX))
|
||||
}
|
||||
|
||||
fn finished_that_fit(&self, height: u16) -> Vec<&FinishedRun> {
|
||||
let bar_rows = usize::from(height.saturating_sub(CHROME_HEIGHT));
|
||||
let bar_rows = usize::from(height.saturating_sub(RULED_ROW_HEIGHT));
|
||||
let room = bar_rows.saturating_sub(self.milestones.len() + self.running.len());
|
||||
let mut longest_first = self.finished.clone();
|
||||
longest_first
|
||||
@@ -128,7 +146,7 @@ impl Timeline<'_> {
|
||||
fn fitted(&self, label: &str) -> String {
|
||||
fit_width(
|
||||
label,
|
||||
usize::from(LABEL_WIDTH - MARK_WIDTH),
|
||||
usize::from(TIMELINE_LABEL_WIDTH - MARK_WIDTH),
|
||||
self.glyphs.ellipsis,
|
||||
)
|
||||
}
|
||||
@@ -169,10 +187,7 @@ impl Widget for Timeline<'_> {
|
||||
);
|
||||
let inner = block.inner(area);
|
||||
block.render(area, buf);
|
||||
let [label_area, bar_area] =
|
||||
Layout::horizontal([Constraint::Length(LABEL_WIDTH), Constraint::Fill(1)])
|
||||
.spacing(1)
|
||||
.areas(inner);
|
||||
let [label_area, bar_area] = label_and_bar_areas(inner);
|
||||
let entries: Vec<TimelineEntry> = self
|
||||
.milestones
|
||||
.iter()
|
||||
@@ -184,12 +199,15 @@ impl Widget for Timeline<'_> {
|
||||
)
|
||||
.chain(self.running.iter().map(|row| self.running_entry(row)))
|
||||
.collect();
|
||||
let [_, entry_labels_area] =
|
||||
label_area.layout(&Layout::vertical([Length(TEXT_ROW_HEIGHT), Fill(1)]));
|
||||
Paragraph::new(
|
||||
once(Line::default())
|
||||
.chain(entries.iter().map(|entry| entry.label.clone()))
|
||||
entries
|
||||
.iter()
|
||||
.map(|entry| entry.label.clone())
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.render(label_area, buf);
|
||||
.render(entry_labels_area, buf);
|
||||
let axis = TimeAxis::new(self.origin, self.now, bar_area.width);
|
||||
let label_row = f64::from(bar_area.height.saturating_sub(1).max(1));
|
||||
let axis_color = self.colors.axis;
|
||||
@@ -265,7 +283,7 @@ struct TimeAxis {
|
||||
impl TimeAxis {
|
||||
fn new(origin: Duration, now: Duration, width: u16) -> Self {
|
||||
let elapsed = now.saturating_sub(origin).max(AXIS_STEPS[0]);
|
||||
let max_labels = u128::from((width / AXIS_LABEL_SPACING).max(1));
|
||||
let max_labels = u128::from((width / ANNOTATION_COLUMN_WIDTH).max(1));
|
||||
let step = AXIS_STEPS
|
||||
.into_iter()
|
||||
.find(|step| elapsed.as_nanos().div_ceil(step.as_nanos()) <= max_labels)
|
||||
|
||||
@@ -2,13 +2,19 @@ use std::{iter::once, time::Duration};
|
||||
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Constraint, Rect},
|
||||
layout::{
|
||||
Constraint::{self, Fill, Length},
|
||||
Layout, Rect,
|
||||
},
|
||||
style::{Style, Stylize},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Clear, Padding, Paragraph, Widget, Wrap},
|
||||
widgets::{Block, Clear, Padding, Paragraph, Widget, Wrap},
|
||||
};
|
||||
|
||||
use super::{DURATION_WIDTH, ELAPSED};
|
||||
use super::{
|
||||
ELAPSED, rule,
|
||||
screen_spacing::{ANNOTATION_COLUMN_WIDTH, TEXT_GAP},
|
||||
};
|
||||
use crate::{
|
||||
boot_model::{Tally, boot_origin::BootOrigin},
|
||||
screen_settings::{
|
||||
@@ -17,7 +23,6 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
pub const FOOTER_HEIGHT: u16 = 2;
|
||||
const SEPARATOR: &str = " · ";
|
||||
const REJECTED_PASSPHRASE: &str = "Wrong passphrase, try again";
|
||||
|
||||
@@ -47,19 +52,17 @@ impl Header<'_> {
|
||||
|
||||
impl Widget for Header<'_> {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
self.origin().render(
|
||||
Rect {
|
||||
width: area.width.saturating_sub(DURATION_WIDTH),
|
||||
..area
|
||||
},
|
||||
buf,
|
||||
);
|
||||
let [origin_area, total_area] = area.layout(&Layout::horizontal([
|
||||
Fill(1),
|
||||
Length(ANNOTATION_COLUMN_WIDTH),
|
||||
]));
|
||||
self.origin().render(origin_area, buf);
|
||||
if let Some(total) = self.total {
|
||||
Line::from(ELAPSED.unsigned_duration_to_string(&total))
|
||||
.fg(self.colors.total_time)
|
||||
.bold()
|
||||
.right_aligned()
|
||||
.render(area, buf);
|
||||
.render(total_area, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,24 +75,23 @@ pub struct Footer<'a> {
|
||||
|
||||
impl Widget for Footer<'_> {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let failed = format!(" {} {} failed", self.glyphs.failed, self.tally.failed);
|
||||
let failed = format!(
|
||||
"{TEXT_GAP}{} {} failed",
|
||||
self.glyphs.failed, self.tally.failed
|
||||
);
|
||||
let failed = if self.tally.failed > 0 {
|
||||
failed.fg(self.colors.failed).bold()
|
||||
} else {
|
||||
failed.fg(self.colors.no_failures)
|
||||
};
|
||||
let block = Block::new()
|
||||
.borders(Borders::TOP)
|
||||
.border_style(self.colors.rule);
|
||||
let inner = block.inner(area);
|
||||
block.render(area, buf);
|
||||
Line::from(vec![
|
||||
Paragraph::new(Line::from(vec![
|
||||
format!("{} {} done", self.glyphs.done, self.tally.done).fg(self.colors.done),
|
||||
format!(" {} running", self.tally.running).fg(self.colors.running),
|
||||
format!(" {} waiting", self.tally.waiting).fg(self.colors.waiting),
|
||||
format!("{TEXT_GAP}{} running", self.tally.running).fg(self.colors.running),
|
||||
format!("{TEXT_GAP}{} waiting", self.tally.waiting).fg(self.colors.waiting),
|
||||
failed,
|
||||
])
|
||||
.render(inner, buf);
|
||||
]))
|
||||
.block(rule(self.colors.rule, Line::default()))
|
||||
.render(area, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
pub const TEXT_ROW_HEIGHT: u16 = 1;
|
||||
pub const RULED_ROW_HEIGHT: u16 = 2;
|
||||
pub const PANEL_MINIMUM_HEIGHT: u16 = 4;
|
||||
pub const COLUMN_GAP_WIDTH: u16 = 1;
|
||||
pub const ANNOTATION_COLUMN_WIDTH: u16 = 9;
|
||||
pub const TIMELINE_LABEL_WIDTH: u16 = 28;
|
||||
pub const TEXT_GAP: &str = " ";
|
||||
pub const TEXT_INDENT: &str = " ";
|
||||
@@ -8,14 +8,21 @@ use ratatui::{
|
||||
widgets::{Paragraph, Widget},
|
||||
};
|
||||
|
||||
use super::{BRANCH, ELAPSED, LAST_BRANCH, unit_count};
|
||||
use super::{BRANCH, ELAPSED, LAST_BRANCH, screen_spacing::ANNOTATION_COLUMN_WIDTH, unit_count};
|
||||
use crate::{
|
||||
boot_model::BootState,
|
||||
screen_settings::{color_scheme::StageColors, font_glyphs::Glyphs},
|
||||
};
|
||||
|
||||
const SHUTDOWN_SUCCESSOR: &str = "systemd-shutdown";
|
||||
const PHASE_WIDTH: usize = 9;
|
||||
const AWAITING_MANAGER: &str = " · waiting for the system manager";
|
||||
|
||||
fn padded_phase_label(label: &str) -> String {
|
||||
format!(
|
||||
"{label:phase_width$}",
|
||||
phase_width = usize::from(ANNOTATION_COLUMN_WIDTH)
|
||||
)
|
||||
}
|
||||
|
||||
pub struct Stages<'a> {
|
||||
pub state: &'a BootState,
|
||||
@@ -57,7 +64,7 @@ impl Stages<'_> {
|
||||
self.state.finished_stages.iter().map(|stage| {
|
||||
Line::from(vec![
|
||||
BRANCH.fg(self.colors.branches),
|
||||
format!("{:PHASE_WIDTH$}", stage.label).fg(self.colors.finished_label),
|
||||
padded_phase_label(stage.label).fg(self.colors.finished_label),
|
||||
format!(
|
||||
"{} done in {}",
|
||||
self.glyphs.bead,
|
||||
@@ -105,10 +112,15 @@ impl Stages<'_> {
|
||||
let elapsed = ELAPSED.unsigned_duration_to_string(&self.now.saturating_sub(started_at));
|
||||
Line::from(vec![
|
||||
LAST_BRANCH.fg(self.colors.branches),
|
||||
format!("{:PHASE_WIDTH$}", self.state.phase.label())
|
||||
padded_phase_label(self.state.phase.label())
|
||||
.fg(self.colors.current)
|
||||
.bold(),
|
||||
elapsed.fg(self.colors.current),
|
||||
if self.state.awaits_manager() {
|
||||
AWAITING_MANAGER.fg(self.colors.current)
|
||||
} else {
|
||||
Span::default()
|
||||
},
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ fn slow_runs_show_their_timeout_in_a_column() {
|
||||
"{screen}"
|
||||
);
|
||||
assert!(
|
||||
line_with(&lines, "slow").ends_with("6.40s 1m30s"),
|
||||
line_with(&lines, "slow").ends_with("6.40s 1m30s"),
|
||||
"{screen}"
|
||||
);
|
||||
assert!(line_with(&lines, "quick").ends_with("2.40s"), "{screen}");
|
||||
|
||||
@@ -2,7 +2,10 @@ use std::{iter::once, time::Duration};
|
||||
|
||||
use ratatui::{
|
||||
buffer::Buffer,
|
||||
layout::{Constraint, Rect},
|
||||
layout::{
|
||||
Constraint::{self, Fill, Length},
|
||||
Layout, Rect,
|
||||
},
|
||||
style::{Style, Stylize},
|
||||
text::{Line, Span},
|
||||
widgets::{Row, Table, Widget},
|
||||
@@ -10,8 +13,8 @@ use ratatui::{
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use super::{
|
||||
BRANCH, DURATION_WIDTH, ENDED_TRUNK, LAST_BRANCH, PASSING_TRUNK, RUNNING_ELAPSED, WHOLE_UNITS,
|
||||
fit_width,
|
||||
BRANCH, ENDED_TRUNK, LAST_BRANCH, PASSING_TRUNK, RUNNING_ELAPSED, WHOLE_UNITS, fit_width,
|
||||
screen_spacing::{ANNOTATION_COLUMN_WIDTH, COLUMN_GAP_WIDTH, TEXT_ROW_HEIGHT},
|
||||
};
|
||||
use crate::{
|
||||
boot_model::{RowStatus, TreeRow, UnitKind},
|
||||
@@ -20,10 +23,8 @@ use crate::{
|
||||
|
||||
const SPINNER: [char; 4] = ['|', '/', '-', '\\'];
|
||||
const SPINNER_STEP: Duration = Duration::from_millis(100);
|
||||
const MIN_DESCRIPTION_WIDTH: u16 = 12;
|
||||
const MIN_TAG_WIDTH: u16 = 6;
|
||||
const MIN_LABEL_WIDTH: u16 = 24;
|
||||
const HEADER_ROWS: u16 = 1;
|
||||
const LABEL_SHARE: u16 = 3;
|
||||
const DESCRIPTION_SHARE: u16 = 2;
|
||||
const SHOW_TIMEOUT_AFTER: Duration = Duration::from_secs(5);
|
||||
const TIMEOUT_HEADER: &str = "Timeout";
|
||||
|
||||
@@ -43,10 +44,11 @@ pub struct UnitTree<'a> {
|
||||
}
|
||||
|
||||
struct Columns {
|
||||
constraints: Vec<Constraint>,
|
||||
label: u16,
|
||||
tag: u16,
|
||||
description: u16,
|
||||
timeout: u16,
|
||||
shows_annotations: bool,
|
||||
shows_timeout: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
@@ -66,15 +68,42 @@ fn spinner_at(now: Duration) -> char {
|
||||
SPINNER[usize::try_from(steps % 4).unwrap_or_default()]
|
||||
}
|
||||
|
||||
fn width_of(text: &str) -> u16 {
|
||||
u16::try_from(text.width()).unwrap_or(u16::MAX)
|
||||
fn solved_columns(width: u16, shows_annotations: bool, shows_timeout: bool) -> Columns {
|
||||
let leading = if shows_annotations {
|
||||
vec![
|
||||
Fill(LABEL_SHARE),
|
||||
Length(ANNOTATION_COLUMN_WIDTH),
|
||||
Fill(DESCRIPTION_SHARE),
|
||||
]
|
||||
} else {
|
||||
vec![Fill(1)]
|
||||
};
|
||||
let constraints: Vec<Constraint> = leading
|
||||
.into_iter()
|
||||
.chain(once(Length(ANNOTATION_COLUMN_WIDTH)))
|
||||
.chain(shows_timeout.then_some(Length(ANNOTATION_COLUMN_WIDTH)))
|
||||
.collect();
|
||||
let solved = Layout::horizontal(constraints.clone())
|
||||
.spacing(COLUMN_GAP_WIDTH)
|
||||
.split(Rect::new(0, 0, width, TEXT_ROW_HEIGHT));
|
||||
Columns {
|
||||
label: solved[0].width,
|
||||
description: if shows_annotations {
|
||||
solved[2].width
|
||||
} else {
|
||||
0
|
||||
},
|
||||
constraints,
|
||||
shows_annotations,
|
||||
shows_timeout,
|
||||
}
|
||||
}
|
||||
|
||||
impl UnitTree<'_> {
|
||||
pub fn height_of(rows: usize, hidden: usize) -> u16 {
|
||||
u16::try_from(rows + usize::from(hidden > 0))
|
||||
.unwrap_or(u16::MAX)
|
||||
.saturating_add(HEADER_ROWS)
|
||||
.saturating_add(TEXT_ROW_HEIGHT)
|
||||
}
|
||||
|
||||
pub fn height(&self) -> u16 {
|
||||
@@ -87,7 +116,7 @@ impl UnitTree<'_> {
|
||||
|
||||
fn header(&self, columns: &Columns) -> Row<'static> {
|
||||
if !self.phase_fits_its_column(columns) {
|
||||
return Row::default().height(HEADER_ROWS);
|
||||
return Row::default().height(TEXT_ROW_HEIGHT);
|
||||
}
|
||||
let name = |text: &'static str| Line::from(text).fg(self.colors.columns);
|
||||
Row::new(columns.shown([
|
||||
@@ -116,15 +145,6 @@ impl UnitTree<'_> {
|
||||
})
|
||||
}
|
||||
|
||||
fn timeout_width(&self) -> u16 {
|
||||
self.rows
|
||||
.iter()
|
||||
.filter_map(|row| self.run_timeout(row))
|
||||
.map(|timeout| width_of(&WHOLE_UNITS.unsigned_duration_to_string(&timeout.limit)))
|
||||
.max()
|
||||
.map_or(0, |widest| widest.max(width_of(TIMEOUT_HEADER)))
|
||||
}
|
||||
|
||||
fn timeout_cell(&self, row: &TreeRow) -> Line<'static> {
|
||||
self.run_timeout(row)
|
||||
.map_or_else(Line::default, |timeout| {
|
||||
@@ -218,39 +238,16 @@ impl UnitTree<'_> {
|
||||
}
|
||||
|
||||
fn columns(&self, width: u16) -> Columns {
|
||||
let timeout = self.timeout_width();
|
||||
let timeout_room = if timeout > 0 { timeout + 1 } else { 0 };
|
||||
let unannotated = width.saturating_sub(DURATION_WIDTH + 1 + timeout_room);
|
||||
let annotated: Vec<(&TreeRow, Stage)> = self
|
||||
.rows
|
||||
.iter()
|
||||
.zip(self.stages())
|
||||
.filter(|(row, _)| {
|
||||
row.chain.is_empty() && !(row.description.is_none() && row.kind.tag().is_none())
|
||||
})
|
||||
.collect();
|
||||
let tag = annotated
|
||||
.iter()
|
||||
.map(|(row, _)| width_of(row.kind.tag().unwrap_or_default()))
|
||||
.fold(MIN_TAG_WIDTH, u16::max);
|
||||
let content = unannotated.saturating_sub(2);
|
||||
let label = (content * 3 / 5).max(MIN_LABEL_WIDTH);
|
||||
let fits_annotations =
|
||||
!annotated.is_empty() && label + tag + MIN_DESCRIPTION_WIDTH <= content;
|
||||
fits_annotations.then_some(label).map_or(
|
||||
Columns {
|
||||
label: unannotated,
|
||||
tag: 0,
|
||||
description: 0,
|
||||
timeout,
|
||||
},
|
||||
|label| Columns {
|
||||
label,
|
||||
tag,
|
||||
description: content - label - tag,
|
||||
timeout,
|
||||
},
|
||||
)
|
||||
let shows_timeout = self.rows.iter().any(|row| self.run_timeout(row).is_some());
|
||||
let has_annotated_rows = self.rows.iter().any(|row| {
|
||||
row.chain.is_empty() && !(row.description.is_none() && row.kind.tag().is_none())
|
||||
});
|
||||
let annotated = solved_columns(width, true, shows_timeout);
|
||||
if has_annotated_rows && annotated.description >= ANNOTATION_COLUMN_WIDTH {
|
||||
annotated
|
||||
} else {
|
||||
solved_columns(width, false, shows_timeout)
|
||||
}
|
||||
}
|
||||
|
||||
fn row(&self, row: &TreeRow, stage: Stage, prefix: String, columns: &Columns) -> Row<'static> {
|
||||
@@ -279,8 +276,11 @@ impl UnitTree<'_> {
|
||||
marker,
|
||||
Span::styled(self.chained_label(row, room), style),
|
||||
]),
|
||||
Line::from(annotation(row.kind.tag().unwrap_or_default(), columns.tag))
|
||||
.fg(self.colors.columns),
|
||||
Line::from(annotation(
|
||||
row.kind.tag().unwrap_or_default(),
|
||||
ANNOTATION_COLUMN_WIDTH,
|
||||
))
|
||||
.fg(self.colors.columns),
|
||||
Line::from(annotation(
|
||||
row.description.as_deref().unwrap_or_default(),
|
||||
columns.description,
|
||||
@@ -297,33 +297,22 @@ impl Columns {
|
||||
fn shown<T>(&self, cells: [T; 5]) -> impl Iterator<Item = T> {
|
||||
let present = [
|
||||
true,
|
||||
self.tag > 0,
|
||||
self.description > 0,
|
||||
self.shows_annotations,
|
||||
self.shows_annotations,
|
||||
true,
|
||||
self.timeout > 0,
|
||||
self.shows_timeout,
|
||||
];
|
||||
cells
|
||||
.into_iter()
|
||||
.zip(present)
|
||||
.filter_map(|(cell, present)| present.then_some(cell))
|
||||
}
|
||||
|
||||
fn widths(&self) -> impl Iterator<Item = Constraint> {
|
||||
self.shown([
|
||||
self.label,
|
||||
self.tag,
|
||||
self.description,
|
||||
DURATION_WIDTH,
|
||||
self.timeout,
|
||||
])
|
||||
.map(Constraint::Length)
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for UnitTree<'_> {
|
||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||
let capacity = usize::from(area.height.saturating_sub(HEADER_ROWS));
|
||||
let shown = if usize::from(self.height() - HEADER_ROWS) > capacity {
|
||||
let capacity = usize::from(area.height.saturating_sub(TEXT_ROW_HEIGHT));
|
||||
let shown = if usize::from(self.height() - TEXT_ROW_HEIGHT) > capacity {
|
||||
capacity.saturating_sub(1).min(self.rows.len())
|
||||
} else {
|
||||
self.rows.len()
|
||||
@@ -336,20 +325,25 @@ impl Widget for UnitTree<'_> {
|
||||
])
|
||||
});
|
||||
let columns = self.columns(area.width);
|
||||
Table::new(
|
||||
let table = Table::new(
|
||||
self.rows
|
||||
.iter()
|
||||
.zip(self.stages())
|
||||
.zip(tree_prefixes(self.rows))
|
||||
.take(shown)
|
||||
.map(|((row, stage), prefix)| self.row(row, stage, prefix, &columns))
|
||||
.chain(overflow),
|
||||
columns.widths(),
|
||||
.map(|((row, stage), prefix)| self.row(row, stage, prefix, &columns)),
|
||||
columns.constraints.clone(),
|
||||
)
|
||||
.header(self.header(&columns))
|
||||
.column_spacing(COLUMN_GAP_WIDTH)
|
||||
.header(self.header(&columns));
|
||||
match overflow {
|
||||
Some(overflow_row) => table.footer(overflow_row),
|
||||
None => table,
|
||||
}
|
||||
.render(area, buf);
|
||||
if !self.phase_fits_its_column(&columns) {
|
||||
self.phase.render(Rect { height: 1, ..area }, buf);
|
||||
let [phase_row, _] = area.layout(&Layout::vertical([Length(TEXT_ROW_HEIGHT), Fill(1)]));
|
||||
self.phase.render(phase_row, buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ pub mod console_palette;
|
||||
pub mod console_takeover;
|
||||
pub mod live_desk;
|
||||
pub mod passphrase_input;
|
||||
pub mod resume_console;
|
||||
pub mod stream_sources;
|
||||
pub mod watch_loop;
|
||||
pub mod watch_screen;
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{future::ready, io, ops::ControlFlow, time::Duration};
|
||||
use std::{future::ready, io, mem, ops::ControlFlow, path::PathBuf, time::Duration};
|
||||
|
||||
use crossterm::event::Event;
|
||||
use futures::{Stream, StreamExt};
|
||||
@@ -11,6 +11,7 @@ use crate::{
|
||||
console_palette::ConsoleLook,
|
||||
console_takeover::{ForegroundVt, QuietKernelConsole, console_look, vt_of_stdin},
|
||||
passphrase_input::asks_to_quit,
|
||||
resume_console::{RESUME_CONSOLE_MARKER, resume_console_is_open},
|
||||
stream_sources::items_when_readable,
|
||||
watch_screen::{ConsoleDesk, Refresh, ScreenInput, WatchEnding},
|
||||
},
|
||||
@@ -24,6 +25,8 @@ pub struct LiveDesk {
|
||||
look: ConsoleLook,
|
||||
entry: Option<PasswordEntry>,
|
||||
handover_deadline: Option<Duration>,
|
||||
resume_marker: PathBuf,
|
||||
console_was_lent: bool,
|
||||
}
|
||||
|
||||
impl LiveDesk {
|
||||
@@ -44,6 +47,8 @@ impl LiveDesk {
|
||||
look: console_look(own_vt),
|
||||
entry: None,
|
||||
handover_deadline: None,
|
||||
resume_marker: PathBuf::from(RESUME_CONSOLE_MARKER),
|
||||
console_was_lent: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +139,17 @@ impl ConsoleDesk for LiveDesk {
|
||||
self.follow_requests(false);
|
||||
}
|
||||
|
||||
fn lends_console(&mut self) -> bool {
|
||||
let lent = resume_console_is_open(&self.resume_marker);
|
||||
self.console_was_lent |= lent;
|
||||
lent
|
||||
}
|
||||
|
||||
fn keep_console_up(&mut self) -> Refresh {
|
||||
if self.lends_console() {
|
||||
return Refresh::Steady;
|
||||
}
|
||||
let console_returned = mem::take(&mut self.console_was_lent);
|
||||
let kernel_got_loud = self
|
||||
.quiet_kernel
|
||||
.as_mut()
|
||||
@@ -144,7 +159,7 @@ impl ConsoleDesk for LiveDesk {
|
||||
let look = console_look(self.own_vt);
|
||||
let restyled = look != self.look;
|
||||
self.look = look;
|
||||
if kernel_got_loud || terminal_was_taken || restyled {
|
||||
if console_returned || kernel_got_loud || terminal_was_taken || restyled {
|
||||
Refresh::Repaint
|
||||
} else {
|
||||
Refresh::Steady
|
||||
@@ -157,3 +172,40 @@ pub fn password_request_inputs(watch: RequestWatch) -> io::Result<impl Stream<It
|
||||
.filter(|changed| ready(*changed))
|
||||
.map(|_| ScreenInput::PasswordRequests))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{env, fs, process};
|
||||
|
||||
use super::*;
|
||||
|
||||
fn desk_watching(resume_marker: PathBuf) -> LiveDesk {
|
||||
LiveDesk {
|
||||
quiet_kernel: None,
|
||||
foreground: None,
|
||||
for_system: true,
|
||||
own_vt: None,
|
||||
look: console_look(None),
|
||||
entry: None,
|
||||
handover_deadline: None,
|
||||
resume_marker,
|
||||
console_was_lent: false,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_console_is_repainted_only_after_it_was_lent_for_resume() {
|
||||
let marker = env::temp_dir().join(format!("bootvine-resume-marker-{}", process::id()));
|
||||
let mut desk = desk_watching(marker.clone());
|
||||
assert!(!desk.lends_console());
|
||||
|
||||
fs::write(&marker, "1").expect("create the marker");
|
||||
assert!(desk.lends_console());
|
||||
assert_eq!(desk.keep_console_up(), Refresh::Steady);
|
||||
|
||||
fs::remove_file(&marker).expect("remove the marker");
|
||||
assert!(!desk.lends_console());
|
||||
assert_eq!(desk.keep_console_up(), Refresh::Repaint);
|
||||
assert_eq!(desk.keep_console_up(), Refresh::Steady);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
use std::{
|
||||
fmt,
|
||||
fs::{self, File, OpenOptions},
|
||||
io::{self, Write},
|
||||
path::Path,
|
||||
thread,
|
||||
};
|
||||
|
||||
use crossterm::{
|
||||
Command,
|
||||
cursor::MoveTo,
|
||||
queue,
|
||||
style::{Attribute, Color as ConsoleColor, SetAttribute, SetForegroundColor},
|
||||
};
|
||||
use ratatui::{
|
||||
backend::CrosstermBackend,
|
||||
buffer::Buffer,
|
||||
layout::{Constraint, Rect},
|
||||
style::{Color, Style},
|
||||
widgets::{Block, Borders, Widget},
|
||||
};
|
||||
use rustix::termios::tcgetwinsize;
|
||||
|
||||
use crate::console_session::{stream_sources::FRAME_INTERVAL, watch_screen::overwrite_every_cell};
|
||||
|
||||
pub const RESUME_CONSOLE_MARKER: &str = "/run/bootvine/resume-console-open";
|
||||
const BOOTVINE_TERMINAL: &str = "/dev/tty12";
|
||||
const KERNEL_PRINTK: &str = "/proc/sys/kernel/printk";
|
||||
const KERNEL_TIMESTAMPS: &str = "/sys/module/printk/parameters/time";
|
||||
const KERNEL_INFO_VISIBLE: &str = "7";
|
||||
const TIMESTAMPS_HIDDEN: &str = "N";
|
||||
const FRAMES_TO_SETTLE: u32 = 2;
|
||||
const BAND_HEIGHT: u16 = 4;
|
||||
const BAND_TITLE: &str = " Looking for a hibernated session ";
|
||||
|
||||
struct ConfineScrolling(Rect);
|
||||
|
||||
impl Command for ConfineScrolling {
|
||||
fn write_ansi(&self, sequence: &mut impl fmt::Write) -> fmt::Result {
|
||||
write!(sequence, "\x1b[{};{}r", self.0.top() + 1, self.0.bottom())
|
||||
}
|
||||
}
|
||||
|
||||
struct ReleaseScrolling;
|
||||
|
||||
impl Command for ReleaseScrolling {
|
||||
fn write_ansi(&self, sequence: &mut impl fmt::Write) -> fmt::Result {
|
||||
sequence.write_str("\x1b[r")
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn resume_console_is_open(marker: &Path) -> bool {
|
||||
marker.exists()
|
||||
}
|
||||
|
||||
fn band_area(screen: Rect) -> Rect {
|
||||
screen.centered_vertically(Constraint::Length(BAND_HEIGHT))
|
||||
}
|
||||
|
||||
fn band_frame() -> Block<'static> {
|
||||
Block::new()
|
||||
.borders(Borders::TOP | Borders::BOTTOM)
|
||||
.border_style(Style::new().fg(Color::Yellow))
|
||||
.title(BAND_TITLE)
|
||||
}
|
||||
|
||||
fn open_bootvine_terminal() -> io::Result<File> {
|
||||
OpenOptions::new().write(true).open(BOOTVINE_TERMINAL)
|
||||
}
|
||||
|
||||
fn draw_progress_band() -> io::Result<()> {
|
||||
let terminal = open_bootvine_terminal()?;
|
||||
let window = tcgetwinsize(&terminal)?;
|
||||
let band = band_area(Rect::new(0, 0, window.ws_col, window.ws_row));
|
||||
let progress_rows = band_frame().inner(band);
|
||||
if progress_rows.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let mut painted = Buffer::empty(band);
|
||||
band_frame().render(band, &mut painted);
|
||||
let mut backend = CrosstermBackend::new(terminal);
|
||||
overwrite_every_cell(&mut backend, &painted)?;
|
||||
queue!(
|
||||
backend,
|
||||
SetAttribute(Attribute::Bold),
|
||||
SetForegroundColor(ConsoleColor::DarkYellow),
|
||||
ConfineScrolling(progress_rows),
|
||||
MoveTo(progress_rows.x, progress_rows.y),
|
||||
)?;
|
||||
Write::flush(&mut backend)
|
||||
}
|
||||
|
||||
fn restore_bootvine_terminal() -> io::Result<()> {
|
||||
let mut terminal = open_bootvine_terminal()?;
|
||||
queue!(terminal, SetAttribute(Attribute::Reset), ReleaseScrolling)?;
|
||||
terminal.flush()
|
||||
}
|
||||
|
||||
pub fn open_resume_console() -> io::Result<()> {
|
||||
let printk_levels = fs::read_to_string(KERNEL_PRINTK)?;
|
||||
let previous_level = printk_levels.split_whitespace().next().unwrap_or_default();
|
||||
let previous_timestamps = fs::read_to_string(KERNEL_TIMESTAMPS).unwrap_or_default();
|
||||
let marker = Path::new(RESUME_CONSOLE_MARKER);
|
||||
if let Some(directory) = marker.parent() {
|
||||
fs::create_dir_all(directory)?;
|
||||
}
|
||||
fs::write(
|
||||
marker,
|
||||
format!("{previous_level}\n{}\n", previous_timestamps.trim()),
|
||||
)?;
|
||||
thread::sleep(FRAME_INTERVAL * FRAMES_TO_SETTLE);
|
||||
let _ = fs::write(KERNEL_TIMESTAMPS, TIMESTAMPS_HIDDEN);
|
||||
fs::write(KERNEL_PRINTK, KERNEL_INFO_VISIBLE)?;
|
||||
draw_progress_band()
|
||||
}
|
||||
|
||||
pub fn close_resume_console() -> io::Result<()> {
|
||||
let marker = Path::new(RESUME_CONSOLE_MARKER);
|
||||
let recorded = fs::read_to_string(marker)?;
|
||||
let mut recorded_lines = recorded.lines();
|
||||
let previous_level = recorded_lines.next().unwrap_or_default();
|
||||
let previous_timestamps = recorded_lines.next().unwrap_or_default();
|
||||
let terminal_restored = restore_bootvine_terminal();
|
||||
if !previous_timestamps.is_empty() {
|
||||
let _ = fs::write(KERNEL_TIMESTAMPS, previous_timestamps);
|
||||
}
|
||||
let level_restored = fs::write(KERNEL_PRINTK, previous_level);
|
||||
fs::remove_file(marker)?;
|
||||
terminal_restored.and(level_restored)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn screen_with_rows(rows: u16) -> Rect {
|
||||
Rect::new(0, 0, 80, rows)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_band_sits_in_the_middle_with_two_rows_for_the_kernel() {
|
||||
let band = band_area(screen_with_rows(50));
|
||||
assert_eq!(band, Rect::new(0, 23, 80, BAND_HEIGHT));
|
||||
assert_eq!(band_frame().inner(band), Rect::new(0, 24, 80, 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_scroll_region_counts_rows_from_one() {
|
||||
let mut sequence = String::new();
|
||||
ConfineScrolling(Rect::new(0, 24, 80, 2))
|
||||
.write_ansi(&mut sequence)
|
||||
.expect("writing to a string");
|
||||
assert_eq!(sequence, "\x1b[25;26r");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_screen_without_room_for_the_band_leaves_the_kernel_no_rows() {
|
||||
let band = band_area(screen_with_rows(2));
|
||||
assert!(band_frame().inner(band).is_empty());
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,10 @@ pub trait ConsoleDesk {
|
||||
}
|
||||
|
||||
fn begin_handover(&mut self, _reached: &str, _deadline: Duration) {}
|
||||
|
||||
fn lends_console(&mut self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
struct CachedProjection {
|
||||
@@ -183,6 +187,9 @@ impl<Desk: ConsoleDesk> WatchScreen<Desk> {
|
||||
Error: From<B::Error>,
|
||||
{
|
||||
batch.into_iter().try_for_each(|input| self.absorb(input))?;
|
||||
if self.desk.lends_console() {
|
||||
return ControlFlow::Continue(());
|
||||
}
|
||||
match self.draw(terminal) {
|
||||
Ok(()) => ControlFlow::Continue(()),
|
||||
Err(error) => ControlFlow::Break(WatchEnding::Failed(error)),
|
||||
@@ -253,7 +260,10 @@ where
|
||||
.await
|
||||
}
|
||||
|
||||
fn overwrite_every_cell<B: Backend>(backend: &mut B, frame: &Buffer) -> Result<(), B::Error> {
|
||||
pub(super) fn overwrite_every_cell<B: Backend>(
|
||||
backend: &mut B,
|
||||
frame: &Buffer,
|
||||
) -> Result<(), B::Error> {
|
||||
backend.draw(
|
||||
frame
|
||||
.content
|
||||
|
||||
+13
-1
@@ -3,7 +3,10 @@ use std::{
|
||||
};
|
||||
|
||||
use bootvine::{
|
||||
console_session::watch_loop::{Settings, run},
|
||||
console_session::{
|
||||
resume_console::{close_resume_console, open_resume_console},
|
||||
watch_loop::{Settings, run},
|
||||
},
|
||||
screen_settings::config_file::{
|
||||
Config, ConfigError, Timing, default_config_table, read_config_file,
|
||||
},
|
||||
@@ -69,6 +72,13 @@ enum Command {
|
||||
Install(InstallOptions),
|
||||
#[command(about = "Disable and remove what install put in place")]
|
||||
Uninstall(UninstallOptions),
|
||||
#[command(
|
||||
about = "Let the kernel's image loading progress reach the console; started before \
|
||||
systemd-hibernate-resume.service"
|
||||
)]
|
||||
OpenResumeConsole,
|
||||
#[command(about = "Undo open-resume-console when no hibernated image was restored")]
|
||||
CloseResumeConsole,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
@@ -102,6 +112,8 @@ fn main() -> ExitCode {
|
||||
),
|
||||
Some(Command::Install(options)) => report_outcome(install_files(&options)),
|
||||
Some(Command::Uninstall(options)) => report_outcome(uninstall_files(&options)),
|
||||
Some(Command::OpenResumeConsole) => report_outcome(open_resume_console()),
|
||||
Some(Command::CloseResumeConsole) => report_outcome(close_resume_console()),
|
||||
None => watch_boot(cli.watch),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,13 @@ const PACKAGED_UNITS: [PackagedUnit; 2] = [
|
||||
contents: include_str!("../../system-files/systemd/bootvine-shutdown.service"),
|
||||
},
|
||||
];
|
||||
const RESUME_DROP_IN_DIR: &str = "systemd-hibernate-resume.service.d";
|
||||
const RESUME_DROP_IN: PackagedUnit = PackagedUnit {
|
||||
name: "systemd-hibernate-resume.service.d/bootvine.conf",
|
||||
contents: include_str!(
|
||||
"../../system-files/systemd/systemd-hibernate-resume.service.d/bootvine.conf"
|
||||
),
|
||||
};
|
||||
const DRACUT_MODULE_SETUP: &str =
|
||||
include_str!("../../system-files/dracut/90bootvine/module-setup.sh");
|
||||
const MKINITCPIO_INSTALL_HOOK: &str =
|
||||
@@ -177,14 +184,17 @@ fn binary_file(target: &InstallTarget) -> Result<Option<InstalledFile>, InstallE
|
||||
|
||||
fn unit_files(target: &InstallTarget) -> impl Iterator<Item = InstalledFile> {
|
||||
let binary_path = target.binary_path();
|
||||
PACKAGED_UNITS.iter().map(move |unit| InstalledFile {
|
||||
destination: target.unit_path(unit.name),
|
||||
contents: unit
|
||||
.contents
|
||||
.replace(PACKAGED_BINARY_PATH, &binary_path.to_string_lossy())
|
||||
.into_bytes(),
|
||||
mode: 0o644,
|
||||
})
|
||||
PACKAGED_UNITS
|
||||
.iter()
|
||||
.chain(once(&RESUME_DROP_IN))
|
||||
.map(move |unit| InstalledFile {
|
||||
destination: target.unit_path(unit.name),
|
||||
contents: unit
|
||||
.contents
|
||||
.replace(PACKAGED_BINARY_PATH, &binary_path.to_string_lossy())
|
||||
.into_bytes(),
|
||||
mode: 0o644,
|
||||
})
|
||||
}
|
||||
|
||||
fn initrd_hook_files(initrd: InitrdGenerator) -> Vec<InstalledFile> {
|
||||
@@ -318,6 +328,7 @@ pub fn uninstall_files(options: &UninstallOptions) -> Result<(), InstallError> {
|
||||
.every_installed_path()
|
||||
.into_iter()
|
||||
.try_for_each(|path| remove_if_present(target.staged(&path)))?;
|
||||
let _ = fs::remove_dir(target.staged(&target.unit_path(RESUME_DROP_IN_DIR)));
|
||||
let dracut_module_dir = target.staged(Path::new(DRACUT_MODULE_DIR));
|
||||
match fs::remove_dir(&dracut_module_dir) {
|
||||
Err(error) if error.kind() == ErrorKind::DirectoryNotEmpty => {
|
||||
|
||||
@@ -113,6 +113,14 @@ fn queued_units(signals: &[Signal]) -> impl Iterator<Item = &str> {
|
||||
})
|
||||
}
|
||||
|
||||
fn connected_inputs(changes: Vec<BootChange>, switching_root: bool) -> Vec<ScreenInput> {
|
||||
(!changes.is_empty())
|
||||
.then_some(ScreenInput::Boot(changes))
|
||||
.into_iter()
|
||||
.chain(switching_root.then_some(ScreenInput::FullRepaint))
|
||||
.collect()
|
||||
}
|
||||
|
||||
struct BootTracker {
|
||||
scope: Scope,
|
||||
target: RootRequest,
|
||||
@@ -160,9 +168,9 @@ impl BusFeed {
|
||||
}
|
||||
Link::Connected(connection) => {
|
||||
let received = self.tracker.receive(connection).await;
|
||||
let switching_root = matches!(self.tracker.root_switch, RootSwitch::Queued(_));
|
||||
Some(match received {
|
||||
Ok(changes) if changes.is_empty() => Vec::new(),
|
||||
Ok(changes) => vec![ScreenInput::Boot(changes)],
|
||||
Ok(changes) => connected_inputs(changes, switching_root),
|
||||
Err(_) => self.lose_connection(),
|
||||
})
|
||||
}
|
||||
@@ -184,7 +192,7 @@ impl BusFeed {
|
||||
Ok(changes) => vec![ScreenInput::Boot(changes), ScreenInput::FullRepaint],
|
||||
Err(_) if Instant::now() < deadline => {
|
||||
sleep(BACKGROUND_CHECK_INTERVAL).await;
|
||||
Vec::new()
|
||||
vec![ScreenInput::FullRepaint]
|
||||
}
|
||||
Err(_) => {
|
||||
self.link = Link::Finished;
|
||||
@@ -546,6 +554,23 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_screen_is_repainted_only_while_the_root_switches() {
|
||||
assert!(connected_inputs(Vec::new(), false).is_empty());
|
||||
assert!(matches!(
|
||||
connected_inputs(Vec::new(), true).as_slice(),
|
||||
[ScreenInput::FullRepaint]
|
||||
));
|
||||
assert!(matches!(
|
||||
connected_inputs(vec![BootChange::ForgetJobs], true).as_slice(),
|
||||
[ScreenInput::Boot(_), ScreenInput::FullRepaint]
|
||||
));
|
||||
assert!(matches!(
|
||||
connected_inputs(vec![BootChange::ForgetJobs], false).as_slice(),
|
||||
[ScreenInput::Boot(_)]
|
||||
));
|
||||
}
|
||||
|
||||
fn in_state(state: ActiveState) -> Activity {
|
||||
Activity {
|
||||
state: Some(state),
|
||||
|
||||
@@ -12,6 +12,7 @@ depends() {
|
||||
install() {
|
||||
inst_binary bootvine
|
||||
inst_simple "$systemdsystemunitdir/bootvine.service"
|
||||
inst_simple "$systemdsystemunitdir/systemd-hibernate-resume.service.d/bootvine.conf"
|
||||
if [[ -f /etc/bootvine.toml ]]; then
|
||||
inst_simple /etc/bootvine.toml
|
||||
fi
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
build() {
|
||||
add_binary bootvine
|
||||
add_systemd_unit bootvine.service
|
||||
add_file /usr/lib/systemd/system/systemd-hibernate-resume.service.d/bootvine.conf
|
||||
if [[ -f /etc/bootvine.toml ]]; then
|
||||
add_file /etc/bootvine.toml
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
After=systemd-vconsole-setup.service
|
||||
|
||||
[Service]
|
||||
ExecStartPre=-/usr/bin/bootvine open-resume-console
|
||||
ExecStopPost=-/usr/bin/bootvine close-resume-console
|
||||
+25
-1
@@ -270,12 +270,36 @@ While it runs, bootvine:
|
||||
`/proc/sys/kernel/printk` to 1, so only emergency messages reach the
|
||||
screen, and sets it again if something raises it;
|
||||
- **silences systemd's status output** with the manager's `SetShowStatus`
|
||||
call.
|
||||
call;
|
||||
- **repaints every cell every 100 ms during a root switch**, because PID 1
|
||||
writes to the console and resets it while it re-executes, and drawing only
|
||||
the cells that changed would leave that on screen.
|
||||
|
||||
It restores the log level and the status output when it hands the console
|
||||
back. Kernel messages from before it starts are already on screen; see
|
||||
[early kernel messages](configuration.md#early-kernel-messages).
|
||||
|
||||
### Resuming from hibernation
|
||||
|
||||
The kernel freezes all processes before it loads a hibernated image, so
|
||||
bootvine cannot draw during the load. A drop-in on
|
||||
`systemd-hibernate-resume.service` runs `bootvine open-resume-console` first,
|
||||
which:
|
||||
|
||||
- creates `/run/bootvine/resume-console-open`, so the running bootvine stops
|
||||
drawing, stops resetting the log level and stops taking `tty12` back;
|
||||
- raises the console log level to 7, so the kernel's `pr_info` progress lines
|
||||
reach the screen, and hides their timestamps;
|
||||
- draws a band across the middle of `tty12`, limits scrolling to the two rows
|
||||
inside it, and sets the colour and cursor there. The kernel console writes at
|
||||
the cursor in the terminal's current colour, always from column 0, so it
|
||||
stays inside the band without knowing about it.
|
||||
|
||||
If an image is restored, none of this needs undoing: the boot kernel's memory
|
||||
is replaced, and the restored system keeps its own log level and terminals. If
|
||||
not, `bootvine close-resume-console` runs as `ExecStopPost`, restoring what
|
||||
the marker recorded, the colour and the scrolling, and bootvine repaints.
|
||||
|
||||
### Passphrase prompts
|
||||
|
||||
bootvine acts as a systemd
|
||||
|
||||
+34
-1
@@ -58,7 +58,8 @@ the kernel:
|
||||
under `initrd.target`.
|
||||
- **The switch to the real root**: the initrd moves into the stages at the
|
||||
top, with its time and unit count, and the tree starts again under the
|
||||
default target. The timeline keeps the initrd's runs, left of the `│`.
|
||||
default target. Until the new manager answers, the stage line says it is
|
||||
waiting for it. The timeline keeps the initrd's runs, left of the `│`.
|
||||
- **Stage 2** up to `graphical.target`.
|
||||
- **The handover**: bootvine hands the console back once the default target is
|
||||
reached, or earlier, once the display manager has switched to its own
|
||||
@@ -83,6 +84,37 @@ The `scripted-initrd` machine uses NixOS's older scripted initrd, which has no
|
||||
systemd. The initrd's lines scroll past as usual, and bootvine starts in
|
||||
stage 2, from `sysinit.target` on.
|
||||
|
||||
## Resuming from hibernation
|
||||
|
||||
<img src="https://codeberg.org/wvhulle/bootvine/raw/branch/recordings/hibernate-resume.webp" width="640" alt="The tree held still during a resume, with the kernel's image loading progress in a band across the middle of the screen">
|
||||
|
||||
Resuming from hibernation looks different from a boot, because the kernel
|
||||
freezes every process before it loads the image, bootvine included. The tree
|
||||
stops moving, and a band across the middle of the screen shows the kernel's own
|
||||
progress:
|
||||
|
||||
```
|
||||
─── Looking for a hibernated session ─────────────────────────────
|
||||
PM: Image loading progress: 60%
|
||||
|
||||
──────────────────────────────────────────────────────────────────
|
||||
```
|
||||
|
||||
The text comes straight from the kernel, which is why it is a line of text and
|
||||
not a bar. The screen stays like this until the restored system takes over.
|
||||
Bootvine does not draw again, because the restore replaces it along with the
|
||||
rest of the boot kernel's memory.
|
||||
|
||||
The last lines show how the time was spent. `Read ... in N seconds` is the
|
||||
image load. `Suspending console(s)` means the load has finished and the kernel
|
||||
is about to jump into the restored system. If the screen stays on that line for
|
||||
a long time, the wait is the restored kernel bringing devices back up, not the
|
||||
disk.
|
||||
|
||||
With no image to restore, `systemd-hibernate-resume` finishes at once and the
|
||||
band disappears. Some kernel console setups
|
||||
switch to a blank terminal for the load; the same lines then appear there.
|
||||
|
||||
## Shutdown
|
||||
|
||||
<img src="https://codeberg.org/wvhulle/bootvine/raw/branch/recordings/shutdown.gif" width="691" alt="A poweroff: units stopping under the targets waiting on them">
|
||||
@@ -174,6 +206,7 @@ shows the shutdown.
|
||||
| `nix run .#sample-vm-text-console` | the same units without a display manager, handing over at the default target | [without a display manager](#without-a-display-manager) |
|
||||
| `nix run .#sample-vm-scripted-initrd` | the same units with NixOS's scripted initrd, so bootvine starts in stage 2 only | [without a systemd initrd](#without-a-systemd-initrd) |
|
||||
| `nix run .#sample-vm-encrypted-volume` | a LUKS volume unlocked in the initrd; the passphrase is `sample passphrase` | [passphrase prompts](#passphrase-prompts) |
|
||||
| `nix run .#sample-vm-hibernate-resume` | a swap disk to hibernate to; run `systemctl hibernate`, then start the machine again | [resuming from hibernation](#resuming-from-hibernation) |
|
||||
| `nix run .#sample-vm-failures` | a firmware failure in the initrd, then units that exit with an error, crash, time out, cannot be run, restart too often, report a status, die after starting, and one that fails only through its dependency | [failures](#failures) |
|
||||
|
||||
Each machine keeps its disk in `~/.cache/bootvine-<machine>.qcow2`; delete it
|
||||
|
||||
@@ -60,7 +60,12 @@
|
||||
{ pkgs, builds, ... }:
|
||||
{
|
||||
default = builds.bootvine;
|
||||
inherit (builds) bootvine scripted-demos repo-tasks;
|
||||
inherit (builds)
|
||||
bootvine
|
||||
scripted-demos
|
||||
repo-tasks
|
||||
workspace-dependencies
|
||||
;
|
||||
sample-unit-files = pkgs.callPackage ./vm-tests/slow-services/sample-unit-files.nix {
|
||||
inherit (vmTests) sampleUnits;
|
||||
};
|
||||
@@ -101,6 +106,39 @@
|
||||
}
|
||||
) vmTests.machineDescriptions;
|
||||
|
||||
exportBuiltPathsHook = pkgs.writeShellApplication {
|
||||
name = "export-built-paths-hook";
|
||||
text = ''
|
||||
exported_paths_dir="$CI_WORKSPACE/.nix-built-paths"
|
||||
mkdir -p "$exported_paths_dir"
|
||||
read -ra built_paths <<< "$OUT_PATHS"
|
||||
nix copy --quiet --to "file://$exported_paths_dir?compression=zstd" "''${built_paths[@]}"
|
||||
printf '%s\n' "''${built_paths[@]}" >> "$exported_paths_dir/paths.txt"
|
||||
'';
|
||||
};
|
||||
|
||||
buildAndExportPaths = pkgs.writeShellApplication {
|
||||
name = "build-and-export-paths";
|
||||
text = ''
|
||||
export NIX_CONFIG="''${NIX_CONFIG:-}
|
||||
post-build-hook = ${lib.getExe exportBuiltPathsHook}"
|
||||
nix build --quiet --print-build-logs "$@"
|
||||
'';
|
||||
};
|
||||
|
||||
importExportedPaths = pkgs.writeShellApplication {
|
||||
name = "import-exported-paths";
|
||||
text = ''
|
||||
exported_paths_dir="$CI_WORKSPACE/.nix-built-paths"
|
||||
if [[ ! -s "$exported_paths_dir/paths.txt" ]]; then
|
||||
echo "No exported paths to import"
|
||||
exit 0
|
||||
fi
|
||||
mapfile -t built_paths < "$exported_paths_dir/paths.txt"
|
||||
nix copy --quiet --no-check-sigs --from "file://$exported_paths_dir" "''${built_paths[@]}"
|
||||
'';
|
||||
};
|
||||
|
||||
releasePlzOnCodeberg =
|
||||
subcommand: description:
|
||||
shellScriptApp "release-plz-${subcommand}" description {
|
||||
@@ -150,12 +188,47 @@
|
||||
text = "exec xtask publish-recordings";
|
||||
};
|
||||
|
||||
build-and-push-to-cachix =
|
||||
shellScriptApp "build-and-push-to-cachix"
|
||||
"Build flake outputs and push everything built to the wvhulle Cachix cache"
|
||||
build-and-export-paths = {
|
||||
type = "app";
|
||||
meta.description = "Build flake outputs and export newly built paths to the CI workspace";
|
||||
program = lib.getExe buildAndExportPaths;
|
||||
};
|
||||
|
||||
build-unless-cached =
|
||||
shellScriptApp "build-unless-cached"
|
||||
"Build a flake output and export it to the CI workspace unless it is already in Cachix"
|
||||
{
|
||||
text = ''
|
||||
built_output=$(nix eval --quiet --raw "$1.outPath")
|
||||
if nix path-info --quiet --store https://wvhulle.cachix.org "$built_output" > /dev/null 2>&1; then
|
||||
echo "$built_output is already in Cachix"
|
||||
exit 0
|
||||
fi
|
||||
${lib.getExe buildAndExportPaths} "$1"
|
||||
'';
|
||||
};
|
||||
|
||||
import-exported-paths = {
|
||||
type = "app";
|
||||
meta.description = "Import paths exported to the CI workspace by an earlier step";
|
||||
program = lib.getExe importExportedPaths;
|
||||
};
|
||||
|
||||
upload-exported-paths =
|
||||
shellScriptApp "upload-exported-paths"
|
||||
"Push paths exported to the CI workspace to the wvhulle Cachix cache"
|
||||
{
|
||||
runtimeInputs = [ pkgs.cachix ];
|
||||
text = ''exec cachix watch-exec wvhulle -- nix build --print-build-logs "$@"'';
|
||||
text = ''
|
||||
exported_paths_dir="$CI_WORKSPACE/.nix-built-paths"
|
||||
if [[ ! -s "$exported_paths_dir/paths.txt" ]]; then
|
||||
echo "No newly built paths to upload"
|
||||
exit 0
|
||||
fi
|
||||
${lib.getExe importExportedPaths}
|
||||
mapfile -t built_paths < "$exported_paths_dir/paths.txt"
|
||||
cachix push wvhulle "''${built_paths[@]}"
|
||||
'';
|
||||
};
|
||||
|
||||
check-conventional-commits =
|
||||
|
||||
@@ -30,6 +30,8 @@ let
|
||||
args: craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; } // args);
|
||||
in
|
||||
{
|
||||
workspace-dependencies = cargoArtifacts;
|
||||
|
||||
rustfmt-formatting = craneLib.cargoFmt {
|
||||
inherit (commonArgs) src pname version;
|
||||
cargoExtraArgs = "--all";
|
||||
@@ -51,6 +53,10 @@ in
|
||||
substituteInPlace $out/lib/systemd/system/$unit \
|
||||
--replace-fail /usr/bin/bootvine $out/bin/bootvine
|
||||
done
|
||||
resume_drop_in=systemd-hibernate-resume.service.d/bootvine.conf
|
||||
install -Dm644 bootvine/system-files/systemd/$resume_drop_in $out/lib/systemd/system/$resume_drop_in
|
||||
substituteInPlace $out/lib/systemd/system/$resume_drop_in \
|
||||
--replace-fail /usr/bin/bootvine $out/bin/bootvine
|
||||
install -Dm755 bootvine/system-files/dracut/90bootvine/module-setup.sh \
|
||||
$out/lib/dracut/modules.d/90bootvine/module-setup.sh
|
||||
install -Dm644 bootvine/system-files/mkinitcpio/install/sd-bootvine \
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
release_always = true
|
||||
semver_check = false
|
||||
git_release_type = "prod"
|
||||
release_commits = "^(feat|fix|perf)[(:!]"
|
||||
pr_labels = ["release"]
|
||||
pr_body = """
|
||||
{% for release in releases %}
|
||||
|
||||
@@ -15,6 +15,7 @@ let
|
||||
scripted-initrd = "the slow units with the scripted initrd, so bootvine starts in stage 2";
|
||||
encrypted-volume = "a LUKS volume unlocked in the initrd with the passphrase 'sample passphrase'";
|
||||
failures = "units that fail in every way systemd reports, each with journal messages";
|
||||
hibernate-resume = "a swap disk to hibernate to, showing the kernel's image loading progress on resume";
|
||||
};
|
||||
|
||||
machines = lib.mapAttrs (machineName: _: machineModule machineName) machineDescriptions;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
{ machine, pkgs, ... }:
|
||||
{
|
||||
name = "bootvine-hibernate-resume";
|
||||
|
||||
nodes.machine =
|
||||
{ lib, ... }:
|
||||
{
|
||||
imports = [
|
||||
machine
|
||||
(pkgs.path + "/nixos/tests/common/auto-format-root-device.nix")
|
||||
];
|
||||
|
||||
boot.resumeDevice = "/dev/vdc";
|
||||
swapDevices = lib.mkOverride 0 [
|
||||
{
|
||||
device = "/dev/vdc";
|
||||
options = [ "x-systemd.makefs" ];
|
||||
}
|
||||
];
|
||||
|
||||
powerManagement = {
|
||||
powerDownCommands = "systemctl --no-block stop backdoor.service";
|
||||
resumeCommands = "systemctl --no-block restart backdoor.service";
|
||||
};
|
||||
|
||||
virtualisation = {
|
||||
memorySize = 2048;
|
||||
qemu.options = [
|
||||
"-vga none"
|
||||
"-device VGA,xres=1280,yres=800"
|
||||
"-chardev socket,id=recording-monitor,path=recording-monitor,server=on,wait=off"
|
||||
"-mon chardev=recording-monitor,mode=readline"
|
||||
];
|
||||
emptyDiskImages = [ 4096 ];
|
||||
useNixStoreImage = true;
|
||||
useEFIBoot = true;
|
||||
};
|
||||
};
|
||||
|
||||
testScript =
|
||||
builtins.readFile ../shared/console.py
|
||||
+ builtins.readFile ../shared/screen_recording.py
|
||||
+ builtins.readFile ./check.py;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
RESUME_MARKER = "/run/bootvine/resume-console-open"
|
||||
BOOT_CONSOLE_LEVEL = "3"
|
||||
SENTINEL_TEXT = "held only in memory"
|
||||
|
||||
|
||||
def console_level():
|
||||
return machine.succeed("cut -f1 /proc/sys/kernel/printk").strip()
|
||||
|
||||
|
||||
def assert_console_returned():
|
||||
machine.wait_until_fails("systemctl is-active bootvine")
|
||||
machine.fail(f"test -e {RESUME_MARKER}")
|
||||
assert console_level() == BOOT_CONSOLE_LEVEL, f"kernel console level was not restored: {console_level()}"
|
||||
|
||||
|
||||
machine.start()
|
||||
|
||||
machine.wait_for_unit("default.target")
|
||||
assert_console_returned()
|
||||
machine.succeed("swapon --show=NAME --noheadings | grep -q .")
|
||||
machine.succeed(
|
||||
"mkdir /run/test",
|
||||
"mount -t ramfs ramfs /run/test",
|
||||
f"echo '{SENTINEL_TEXT}' > /run/test/sentinel",
|
||||
"dd if=/dev/urandom of=/run/test/ballast bs=1M count=500",
|
||||
)
|
||||
|
||||
machine.execute("systemctl hibernate >&2 &", check_return=False)
|
||||
machine.wait_for_shutdown()
|
||||
|
||||
resume_recording = ScreenRecording(machine)
|
||||
resume_recording.frame_seconds = 0.1
|
||||
machine.start()
|
||||
resume_recording.start()
|
||||
machine.wait_for_console_text("Image loading progress")
|
||||
machine.wait_for_console_text("Image loading done")
|
||||
machine.succeed(f"grep '{SENTINEL_TEXT}' /run/test/sentinel")
|
||||
assert console_level() == BOOT_CONSOLE_LEVEL, f"the restored system kept the opened level: {console_level()}"
|
||||
assert foreground_terminal() != f"tty{BOOTVINE_TERMINAL}", "the restored system came back on bootvine's terminal"
|
||||
machine.fail("systemctl is-active bootvine")
|
||||
machine.sleep(1)
|
||||
resume_recording.stop()
|
||||
|
||||
machine.crash()
|
||||
machine.start()
|
||||
machine.wait_for_unit("default.target")
|
||||
machine.fail("test -e /run/test/sentinel")
|
||||
assert_console_returned()
|
||||
journal = bootvine_journal()
|
||||
print(journal)
|
||||
assert " in Initrd " in journal, "bootvine did not run in the initrd of the boot without an image"
|
||||
machine.succeed('test "$(systemctl show -p Result --value bootvine)" = success')
|
||||
@@ -0,0 +1,21 @@
|
||||
{ lib, ... }:
|
||||
{
|
||||
boot.initrd.availableKernelModules = [ "bochs" ];
|
||||
|
||||
virtualisation.vmVariant = {
|
||||
boot.resumeDevice = "/dev/vdb";
|
||||
swapDevices = lib.mkOverride 0 [
|
||||
{
|
||||
device = "/dev/vdb";
|
||||
options = [ "x-systemd.makefs" ];
|
||||
}
|
||||
];
|
||||
virtualisation = {
|
||||
emptyDiskImages = [ 4096 ];
|
||||
qemu.options = lib.mkForce [
|
||||
"-vga none"
|
||||
"-device VGA,xres=1920,yres=1080"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -14,6 +14,7 @@ class ScreenRecording:
|
||||
self.recorded_machine = recorded_machine
|
||||
self.frames_directory = os.path.join(recorded_machine.out_dir, "recording")
|
||||
self.raw_frame = os.path.join(recorded_machine.state_dir, "recording-frame.ppm")
|
||||
self.frame_seconds = RECORDING_FRAME_SECONDS
|
||||
self.stopping = threading.Event()
|
||||
self.thread = threading.Thread(target=self.record_frames, daemon=True)
|
||||
|
||||
@@ -64,7 +65,7 @@ class ScreenRecording:
|
||||
while not self.stopping.is_set():
|
||||
self.save_frame(monitor, frame_number)
|
||||
frame_number += 1
|
||||
self.stopping.wait(RECORDING_FRAME_SECONDS)
|
||||
self.stopping.wait(self.frame_seconds)
|
||||
except (OSError, ConnectionError, subprocess.CalledProcessError):
|
||||
pass
|
||||
finally:
|
||||
|
||||
Reference in new issue
Block a user