Pre Post transaction hooks for snapshots and such.

This commit is contained in:
2026-09-14 22:48:05 +02:00
parent 4a4e6927bd
commit 2fedcd0805
8 changed files with 98 additions and 34 deletions
Generated
+1 -1
View File
@@ -146,7 +146,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]] [[package]]
name = "hive-up" name = "hive-up"
version = "0.2.0" version = "0.2.1"
dependencies = [ dependencies = [
"clap", "clap",
"nix", "nix",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "hive-up" name = "hive-up"
version = "0.2.0" version = "0.2.1"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
+27 -30
View File
@@ -4,57 +4,54 @@ Program to manage update process of Kira Linux. Creating snapshots. Dealing with
There should be some documantation here. There should be some documantation here.
hive-up uses `/var/lib/hive-up/hyve-db.json` file as database for stuff hive-up uses `/etc/hive-up.toml` as config file.
And `/etc/hive-up.toml` as config file.
As an daemon hive-up righ now doing only periodical checks for updates.
```text ```text
Update program fot Kira Linux :3
Usage: hive-up <COMMAND> Usage: hive-up <COMMAND>
Commands: Commands:
cli Perform local operations boot Manage system boot
remote Ask hive-up daemon something pac Intended to be used by pacman hooks
daemon Run hive-up in daemon mode help Print this message or the help of the given subcommand(s)
help Print this message or the help of the given subcommand(s)
Options: Options:
-h, --help Print help -h, --help Print help
-V, --version Print version -V, --version Print version
``` ```
For cli mode: Pac mode:
```text ```text
Usage: hive-up cli <--upgrade|--update-boot|--init-boot-menu|--init-boot> Usage: hive-up pac <COMMAND>
Commands:
snapshot-system Creates snapshoots of /usr and /var subvolumea
start This supposed to be called by pacman hook before transaction hive-up will check for /var/lib/hive-up/pac-lock and will not create snapshots in case it present Its safe lock mesure to prevent multiple snapshots on system fixing or some corner cases Lock file can be deleted by `pac finish` that should be called by pacman after transaction
finis This supposed to be called by pacman hook before transaction. Right now only thing it does is removes /var/lib/hive-up/pac-lock file
help Print this message or the help of the given subcommand(s)
Options: Options:
--upgrade Perform system upgrade -h, --help Print help
--update-boot Install new kernel into boot partition Print help
--init-boot-menu Cleans up and recreates UFI boot menu
--init-boot Cleans up and recreates UFI boot menu and /EFI dir content
-h, --help Print help
``` ```
For remote mode: Boot mode:
```text ```text
Usage: hive-up remote <--check-updates|--updates-avail|--schedule-update> Usage: hive-up boot <COMMAND>
Commands:
update Install new kernel into boot partition
efi-menu-init Cleans up and recreates UFI boot menu
init Cleans up and recreates UFI boot menu and /EFI dir content
help Print this message or the help of the given subcommand(s)
Options: Options:
--check-updates Ask daemon to check for updates -h, --help Print help
--updates-avail Ask daemon if there is any updates available
--schedule-update Ask daemon to perform system update on next reboot
-h, --help Print help
``` ```
`hive-up daemon` - do not have any flags for now.
`hive-up cli --upgrade` - generally not supposed to be called by user. It get called by system service manager (dinit) after hive-up service stop (on reboot or system shutdown)
When `hive-up cli --upgrade` is called, it checks if `update_on_reboot` flag is set in **DB** or `auto_update` flag checked in **config**, and if `updates_available` in **DB** is non zero. Update routine continue only if this conditios are met.
1. It creates snapshots of `/usr` and `/var` subvolumes 1. It creates snapshots of `/usr` and `/var` subvolumes
2. It sets `update_status` to **false** in **DB**
3. Performs update, and if everything was fine sets `update_status` to **true** in **DB**
After this, system reboots, and on system boot Nyanit figures up what to do with failed updates if any
+12
View File
@@ -0,0 +1,12 @@
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
Description = Release lock and do stuff
When = PostTransaction
Exec = /usr/bin/hive-up pac finish
+12
View File
@@ -0,0 +1,12 @@
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
Description = Snapshot system before any changes
When = PreTransaction
Exec = /usr/bin/hive-up pac start
+34
View File
@@ -34,6 +34,9 @@ const BOOT_MENU_LABEL_BACK: &str = "Kira OS Fallback";
const BOOT_UKI_IMAGE_NAME: &str = "\\EFI\\linux-kira-lts.efi"; const BOOT_UKI_IMAGE_NAME: &str = "\\EFI\\linux-kira-lts.efi";
const BOOT_UKI_IMAGE_NAME_BACK: &str = "\\EFI\\linux-kira-lts-back.efi"; const BOOT_UKI_IMAGE_NAME_BACK: &str = "\\EFI\\linux-kira-lts-back.efi";
const PAC_LOCK_FILE: &str = "/var/lib/hive-up/pac-lock";
#[derive(Debug)] #[derive(Debug)]
pub struct CommandFailed { pub struct CommandFailed {
pub stderr: Vec<u8>, pub stderr: Vec<u8>,
@@ -227,6 +230,37 @@ pub fn snapshot_system() -> Result<String, ExecCommandError> {
Ok(local_time) Ok(local_time)
} }
/// Function for pacman preTransaction hook
///
pub fn pac_start() -> Result<(), ExecCommandError> {
use std::path::Path;
// Check if lock file exist
let pack_lock_path = Path::new(PAC_LOCK_FILE);
if pack_lock_path.exists() {
println!("Warning! Pac Lock file exist, skipping system snapshot...");
return Ok(());
}
println!("Creating system snapshot...");
let snap_time = snapshot_system()?;
println!("Ok.");
fs::write(PAC_LOCK_FILE, snap_time)?;
Ok(())
}
pub fn pac_finish() -> Result<(), ExecCommandError> {
use std::path::Path;
// Check if lock file exist
let pack_lock_path = Path::new(PAC_LOCK_FILE);
if pack_lock_path.exists() {
println!("Remowing pac-lock...");
fs::remove_file(pack_lock_path)?;
}
else {
println!("Warning! Pac Lock file does not exist - something is wrong...");
}
Ok(())
}
//const TMP_ROOT: &str = "/mnt/bee-root"; //const TMP_ROOT: &str = "/mnt/bee-root";
// pub fn list_bzzpss_snaps() -> Result<Vec<String>, ExecCommandError> { // pub fn list_bzzpss_snaps() -> Result<Vec<String>, ExecCommandError> {
// use regex::Regex; // use regex::Regex;
+11 -2
View File
@@ -21,7 +21,6 @@ use std::sync::Arc;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
mod hive_system; mod hive_system;
mod hive_config; mod hive_config;
#[derive(Debug)] #[derive(Debug)]
@@ -92,6 +91,14 @@ enum BootCommand {
enum Pac { enum Pac {
/// Creates snapshoots of /usr and /var subvolumea /// Creates snapshoots of /usr and /var subvolumea
SnapshotSystem, SnapshotSystem,
/// This supposed to be called by pacman hook before transaction
/// hive-up will check for /var/lib/hive-up/pac-lock and will not create snapshots in case it present
/// Its safe lock mesure to prevent multiple snapshots on system fixing or some corner cases
/// Lock file can be deleted by `pac finish` that should be called by pacman after transaction
Start,
/// This supposed to be called by pacman hook before transaction.
/// Right now only thing it does is removes /var/lib/hive-up/pac-lock file
Finis,
} }
#[derive(Subcommand, Debug)] #[derive(Subcommand, Debug)]
@@ -158,7 +165,9 @@ fn main() -> Result<(), HiveUpError> {
println!("Creating system snapshot..."); println!("Creating system snapshot...");
let _ = hive_system::snapshot_system()?; let _ = hive_system::snapshot_system()?;
println!("Ok."); println!("Ok.");
} },
Pac::Start => hive_system::pac_start()?,
Pac::Finis => hive_system::pac_finish()?
} }
} }