SHA256
Main turn point, no pacman wrapping, no update functionality, making things simplier
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
type = process
|
type = process
|
||||||
command = /usr/bin/hive-up daemon
|
command = /usr/bin/hive-up daemon
|
||||||
stop-command = /usr/bin/hive-up cli --upgrade
|
|
||||||
depends-on = network.target
|
depends-on = network.target
|
||||||
logfile = /var/log/dinit/hive-up.log
|
logfile = /var/log/dinit/hive-up.log
|
||||||
log-type = file
|
log-type = file
|
||||||
|
|||||||
@@ -4,8 +4,6 @@
|
|||||||
check_interval = 58
|
check_interval = 58
|
||||||
# Tells hive-up to automatically download updates when awailable.
|
# Tells hive-up to automatically download updates when awailable.
|
||||||
download_updates = true
|
download_updates = true
|
||||||
# Tells hive-up to automatically perform updates during system reboot
|
|
||||||
auto_update = false
|
|
||||||
|
|
||||||
# In [kernel] section user may specify kernel cmd
|
# In [kernel] section user may specify kernel cmd
|
||||||
# [kernel]
|
# [kernel]
|
||||||
|
|||||||
@@ -106,24 +106,6 @@ fn process_remoute(
|
|||||||
println!("Error while ansvering cli request: {}", ex);
|
println!("Error while ansvering cli request: {}", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// we should apply updates if any on reboot
|
|
||||||
BzzReq::ScheduleUpdate => {
|
|
||||||
// but only if we have actually any updates
|
|
||||||
if bzz_db.updates_available > 0 {
|
|
||||||
bzz_db.update_on_reboot = true;
|
|
||||||
// keep it simple Kira
|
|
||||||
// lets just return err from the loop if something wrong with db
|
|
||||||
hive_db::write_db(&bzz_db)?;
|
|
||||||
// signal remoute that evertyhing go OK
|
|
||||||
if let Err(ex) = hive_intercom::socket_send(
|
|
||||||
&listening_socket,
|
|
||||||
&client_addr,
|
|
||||||
BzzResp::Finish,
|
|
||||||
) {
|
|
||||||
println!("Error while ansvering cli request: {}", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BzzReq::CheckForUpdates => {
|
BzzReq::CheckForUpdates => {
|
||||||
let resp = BzzResp::Working(1);
|
let resp = BzzResp::Working(1);
|
||||||
if let Err(ex) =
|
if let Err(ex) =
|
||||||
|
|||||||
@@ -62,22 +62,12 @@ pub struct HiveDb {
|
|||||||
pub update_check_timestamp: u64,
|
pub update_check_timestamp: u64,
|
||||||
/// non zero if there is updates that can bee applied, showing numbers of packages that can be updated
|
/// non zero if there is updates that can bee applied, showing numbers of packages that can be updated
|
||||||
pub updates_available: u32,
|
pub updates_available: u32,
|
||||||
/// true if last update was successful
|
|
||||||
/// if it is false - nyanit need to roll back snapshots
|
|
||||||
pub update_status: bool,
|
|
||||||
/// datetime of last snapshot in format "%Y-%m-%dT%H:%M:%S"
|
|
||||||
pub last_snapshot_time: String,
|
|
||||||
/// set to true if we want to apply available updates on reboot
|
|
||||||
pub update_on_reboot: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_db() -> Result<HiveDb, DBError> {
|
fn init_db() -> Result<HiveDb, DBError> {
|
||||||
let bzz_db = HiveDb{
|
let bzz_db = HiveDb{
|
||||||
update_check_timestamp: 0,
|
update_check_timestamp: 0,
|
||||||
updates_available: 0,
|
updates_available: 0,
|
||||||
update_status: false,
|
|
||||||
last_snapshot_time: "".into(),
|
|
||||||
update_on_reboot: false,
|
|
||||||
};
|
};
|
||||||
write_db(&bzz_db)?;
|
write_db(&bzz_db)?;
|
||||||
Ok(bzz_db)
|
Ok(bzz_db)
|
||||||
|
|||||||
@@ -96,7 +96,6 @@ pub enum BzzResp {
|
|||||||
pub enum BzzReq {
|
pub enum BzzReq {
|
||||||
UpdatesAvailable,
|
UpdatesAvailable,
|
||||||
CheckForUpdates,
|
CheckForUpdates,
|
||||||
ScheduleUpdate,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn socket_bind(read_timeout_sec: u64) -> Result<UnixDatagram, std::io::Error> {
|
pub fn socket_bind(read_timeout_sec: u64) -> Result<UnixDatagram, std::io::Error> {
|
||||||
@@ -194,12 +193,3 @@ pub fn client_check_for_updates() -> Result<u32, IntercomError> {
|
|||||||
_ => Err(IntercomError::UnexpectedResponse),
|
_ => Err(IntercomError::UnexpectedResponse),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn client_schedule_update() -> Result<(), IntercomError> {
|
|
||||||
let resp = send_and_recv(BzzReq::ScheduleUpdate)?;
|
|
||||||
match resp {
|
|
||||||
BzzResp::Finish => Ok(()),
|
|
||||||
BzzResp::Error(ex) => Err(IntercomError::ServerError(ex)),
|
|
||||||
_ => Err(IntercomError::UnexpectedResponse),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+1
-44
@@ -24,9 +24,6 @@ mod hive_system;
|
|||||||
|
|
||||||
mod hive_config;
|
mod hive_config;
|
||||||
|
|
||||||
use crate::hive_config::HiveConfig;
|
|
||||||
use crate::hive_system::SysUpgradeError;
|
|
||||||
|
|
||||||
mod daemon;
|
mod daemon;
|
||||||
mod hive_db;
|
mod hive_db;
|
||||||
mod hive_intercom;
|
mod hive_intercom;
|
||||||
@@ -118,18 +115,11 @@ struct RemoteArgs {
|
|||||||
/// Ask daemon if there is any updates available
|
/// Ask daemon if there is any updates available
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
updates_avail: bool,
|
updates_avail: bool,
|
||||||
|
|
||||||
/// Ask daemon to perform system update on next reboot
|
|
||||||
#[arg(long)]
|
|
||||||
schedule_update: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Args, Debug)]
|
#[derive(Args, Debug)]
|
||||||
#[group(required = true, multiple = false)]
|
#[group(required = true, multiple = false)]
|
||||||
struct CliArgs {
|
struct CliArgs {
|
||||||
/// Perform system upgrade
|
|
||||||
#[arg(long)]
|
|
||||||
upgrade: bool,
|
|
||||||
/// Install new kernel into boot partition
|
/// Install new kernel into boot partition
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
update_boot: bool,
|
update_boot: bool,
|
||||||
@@ -161,33 +151,6 @@ struct Cli {
|
|||||||
mode: HiveUpMode,
|
mode: HiveUpMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cli_upgrade(bzz_config: HiveConfig) -> Result<(), HiveUpError> {
|
|
||||||
let mut bzz_db = hive_db::read_db()?;
|
|
||||||
|
|
||||||
if (bzz_db.updates_available !=0) && (bzz_db.update_on_reboot || bzz_config.update.auto_update) {
|
|
||||||
println!("Starting full system upgrade");
|
|
||||||
bzz_db.update_status = false;
|
|
||||||
hive_db::write_db(&bzz_db)?;
|
|
||||||
match hive_system::sys_upgrade() {
|
|
||||||
Ok(snap_time) => {
|
|
||||||
bzz_db.update_status = true;
|
|
||||||
bzz_db.update_on_reboot = false;
|
|
||||||
bzz_db.last_snapshot_time = snap_time;
|
|
||||||
hive_db::write_db(&bzz_db)?;
|
|
||||||
}
|
|
||||||
Err(SysUpgradeError::PkgUpgradeErr((snap_time, ex))) => {
|
|
||||||
bzz_db.update_status = false;
|
|
||||||
bzz_db.update_on_reboot = false;
|
|
||||||
bzz_db.last_snapshot_time = snap_time;
|
|
||||||
hive_db::write_db(&bzz_db)?;
|
|
||||||
return Err(ex.into());
|
|
||||||
}
|
|
||||||
Err(ex) => return Err(ex.to_string().into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> Result<(), HiveUpError> {
|
fn main() -> Result<(), HiveUpError> {
|
||||||
// registering signals handling
|
// registering signals handling
|
||||||
let term_flag: Arc<AtomicBool> = Arc::new(AtomicBool::new(false));
|
let term_flag: Arc<AtomicBool> = Arc::new(AtomicBool::new(false));
|
||||||
@@ -208,9 +171,7 @@ fn main() -> Result<(), HiveUpError> {
|
|||||||
match args.mode {
|
match args.mode {
|
||||||
HiveUpMode::Daemon => daemon::run(bzz_config, term_flag.clone(), reload_flag.clone())?,
|
HiveUpMode::Daemon => daemon::run(bzz_config, term_flag.clone(), reload_flag.clone())?,
|
||||||
HiveUpMode::Cli(cli_args) => {
|
HiveUpMode::Cli(cli_args) => {
|
||||||
if cli_args.upgrade {
|
if cli_args.update_boot {
|
||||||
cli_upgrade(bzz_config)?;
|
|
||||||
} else if cli_args.update_boot {
|
|
||||||
println!("Updating boot...");
|
println!("Updating boot...");
|
||||||
hive_system::boot_update()?;
|
hive_system::boot_update()?;
|
||||||
} else if cli_args.init_boot_menu {
|
} else if cli_args.init_boot_menu {
|
||||||
@@ -233,10 +194,6 @@ fn main() -> Result<(), HiveUpError> {
|
|||||||
} else if remote_args.updates_avail {
|
} else if remote_args.updates_avail {
|
||||||
let up_num = hive_intercom::client_updates_available()?;
|
let up_num = hive_intercom::client_updates_available()?;
|
||||||
println!("Updates awailable: {}", up_num);
|
println!("Updates awailable: {}", up_num);
|
||||||
} else if remote_args.schedule_update {
|
|
||||||
println!("Scheduling system update...");
|
|
||||||
hive_intercom::client_schedule_update()?;
|
|
||||||
print!("Done!")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user