Commit 793e6c11 authored by Heinz N. Gies's avatar Heinz N. Gies

Fix autostart->autoboot and add autoboot feature

parent 90d13cec
......@@ -206,7 +206,7 @@ pub struct JailConfig {
/// weather to start this jail on --startup
#[serde(default = "dflt_false")]
pub autostart: bool,
pub autoboot: bool,
// Resources
/// max physical memory in MB (memoryuse)
......@@ -277,7 +277,7 @@ impl PartialEq for JailConfig {
self.image_uuid == other.image_uuid &&
self.alias == other.alias &&
self.hostname == other.hostname &&
self.autostart == other.autostart &&
self.autoboot == other.autoboot &&
self.max_physical_memory == other.max_physical_memory &&
self.cpu_cap == other.cpu_cap &&
self.quota == other.quota &&
......
......@@ -7,6 +7,7 @@ use std::path::PathBuf;
use std::str;
use std::cmp::PartialEq;
use std::collections::HashMap;
use std::slice::Iter;
use prettytable::Table;
use prettytable::format;
......@@ -233,7 +234,13 @@ impl<'a> JDB<'a> {
/// Finds an entry for a given uuid
fn find(self: &'a JDB<'a>, uuid: &Uuid) -> Option<usize> {
self.index.entries.iter().position(|x| x.uuid == *uuid)
}
/// Iterator over index entries
pub fn iter(self: &'a JDB<'a>) -> Iter<'a, IdxEntry> {
self.index.entries.iter()
}
/// Prints the jdb database
pub fn print(self: &'a JDB<'a>, headerless: bool, parsable: bool) -> Result<i32, Box<Error>> {
let mut table = Table::new();
......@@ -245,7 +252,7 @@ impl<'a> JDB<'a> {
table.add_row(row!["UUID", "TYPE", "RAM", "STATE", "ALIAS"]);
}
}
for e in &(self.index.entries) {
for e in self.iter() {
self.print_entry(e, &mut table, parsable)?;
}
if !parsable {
......
......@@ -209,7 +209,18 @@ fn run() -> i32 {
}
}
fn startup(_conf: &Config) -> Result<i32, Box<Error>> {
fn startup(conf: &Config) -> Result<i32, Box<Error>> {
let db = JDB::open(conf)?;
for e in db.iter() {
let jail = db.get(&e.uuid)?;
if jail.config.autoboot && jail.outer.is_none() {
println!("Starting jail {}", jail.idx.uuid);
jail.start(conf)?;
} else {
println!("Skipping startup for jail {}", jail.idx.uuid);
}
};
Ok(0)
}
......
......@@ -88,7 +88,7 @@ pub struct JailUpdate {
/// hostname of the jail
hostname: Option<String>,
/// weather to start this jail on --startup
autostart: Option<bool>,
autoboot: Option<bool>,
/// max physical memory in MB (memoryuse)
max_physical_memory: Option<u64>,
/// mac cpu usage 100 = 1 core (pcpu)
......@@ -137,7 +137,7 @@ impl JailUpdate {
JailUpdate {
alias: None,
hostname: None,
autostart: None,
autoboot: None,
max_physical_memory: None,
cpu_cap: None,
max_shm_memory: None,
......@@ -159,13 +159,13 @@ impl JailUpdate {
pub fn apply(&self, config: JailConfig) -> JailConfig {
let mut c = config.clone();
update!(self, c;
autostart,
alias,
hostname,
max_physical_memory,
cpu_cap,
max_lwps,
dns_domain
autoboot,
alias,
hostname,
max_physical_memory,
cpu_cap,
max_lwps,
dns_domain
);
update_option!(self, c;
max_shm_memory,
......@@ -275,7 +275,7 @@ mod tests {
image_uuid: Uuid::nil(),
alias: String::from("test-alias"),
hostname: String::from("test-hostname"),
autostart: true,
autoboot: true,
max_physical_memory: 1024,
cpu_cap: 100,
quota: 5,
......@@ -324,12 +324,12 @@ mod tests {
assert_eq!(hostname, update.apply(conf).hostname);
}
#[test]
fn autostart() {
fn autoboot() {
let conf = conf();
assert_eq!(true, conf.autostart);
assert_eq!(true, conf.autoboot);
let mut update = JailUpdate::empty();
update.autostart = Some(false);
assert_eq!(false, update.apply(conf).autostart);
update.autoboot = Some(false);
assert_eq!(false, update.apply(conf).autoboot);
}
#[test]
fn max_physical_memory() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment