Add an action to update jails automatically.
I probably will only use this for end-user systems like a laptop but not for servers so I can pick when I need to reboot my servers.
parent
66823059b4
commit
c4cb3f5694
@ -0,0 +1,40 @@
|
||||
use std::process::Command;
|
||||
use std::time::Duration;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::action::ACTION_BUILD;
|
||||
use crate::db::DbHandle;
|
||||
use crate::db::DbJailAction;
|
||||
|
||||
pub(crate) const ACTION_UPDATE_JAIL: &str = "update_jail";
|
||||
const ACTION_UPDATE_JAIL_INTERVAL: u64 = 604800;
|
||||
|
||||
pub(crate) fn update_jail(
|
||||
db_conn: &mut DbHandle,
|
||||
action: &DbJailAction,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Updating jail {}.", action.jail_name.as_str());
|
||||
Command::new("poudriere")
|
||||
.arg("jail")
|
||||
.arg("-j")
|
||||
.arg(action.jail_name.as_str())
|
||||
.arg("-u")
|
||||
.status()?
|
||||
.exit_ok()?;
|
||||
let next_run = (SystemTime::now() + Duration::from_secs(ACTION_UPDATE_JAIL_INTERVAL))
|
||||
.duration_since(SystemTime::UNIX_EPOCH)?
|
||||
.as_secs();
|
||||
|
||||
let tx = db_conn.conn.transaction()?;
|
||||
tx.execute(
|
||||
"UPDATE jail_action SET next_run=$1 WHERE name=$2 AND jail_name=$3",
|
||||
(next_run, ACTION_UPDATE_JAIL, action.jail_name.as_str()),
|
||||
)?;
|
||||
// Since we just updated the jail, force a build ASAP since it may need to rebuild everything.
|
||||
tx.execute(
|
||||
"UPDATE local_action SET next_run=0 WHERE name=$1 AND jail_name=$2",
|
||||
(ACTION_BUILD, action.jail_name.as_str()),
|
||||
)?;
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
}
|
@ -1,10 +1,13 @@
|
||||
mod build;
|
||||
mod cleanup;
|
||||
mod jail;
|
||||
mod ports_tree;
|
||||
|
||||
pub(crate) use build::build;
|
||||
pub(crate) use build::ACTION_BUILD;
|
||||
pub(crate) use cleanup::cleanup;
|
||||
pub(crate) use cleanup::ACTION_CLEANUP;
|
||||
pub(crate) use jail::update_jail;
|
||||
pub(crate) use jail::ACTION_UPDATE_JAIL;
|
||||
pub(crate) use ports_tree::update_ports_tree;
|
||||
pub(crate) use ports_tree::ACTION_UPDATE_PORTS_TREE;
|
||||
|
Loading…
Reference in New Issue