mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
@@ -264,7 +264,8 @@ async fn perform_backup<Db: DbHandle>(
|
|||||||
|
|
||||||
let mut tx = db.begin().await?; // for lock scope
|
let mut tx = db.begin().await?; // for lock scope
|
||||||
let (started, health) = match main_status_model.get(&mut tx, true).await?.into_owned() {
|
let (started, health) = match main_status_model.get(&mut tx, true).await?.into_owned() {
|
||||||
MainStatus::Running { started, health } => (Some(started.clone()), health.clone()),
|
MainStatus::Starting => (Some(Utc::now()), Default::default()),
|
||||||
|
MainStatus::Running { started, health } => (Some(started), health.clone()),
|
||||||
MainStatus::Stopped | MainStatus::Stopping => (None, Default::default()),
|
MainStatus::Stopped | MainStatus::Stopping => (None, Default::default()),
|
||||||
MainStatus::BackingUp { .. } => {
|
MainStatus::BackingUp { .. } => {
|
||||||
backup_report.insert(
|
backup_report.insert(
|
||||||
|
|||||||
@@ -46,10 +46,7 @@ pub async fn start(
|
|||||||
.to_owned();
|
.to_owned();
|
||||||
let mut status = installed.status().main().get_mut(&mut tx).await?;
|
let mut status = installed.status().main().get_mut(&mut tx).await?;
|
||||||
|
|
||||||
*status = MainStatus::Running {
|
*status = MainStatus::Starting;
|
||||||
started: Utc::now(),
|
|
||||||
health: BTreeMap::new(),
|
|
||||||
};
|
|
||||||
status.save(&mut tx).await?;
|
status.save(&mut tx).await?;
|
||||||
heal_all_dependents_transitive(&ctx, &mut tx, &id).await?;
|
heal_all_dependents_transitive(&ctx, &mut tx, &id).await?;
|
||||||
|
|
||||||
|
|||||||
@@ -143,9 +143,10 @@ pub struct Manager {
|
|||||||
#[derive(TryFromPrimitive)]
|
#[derive(TryFromPrimitive)]
|
||||||
#[repr(usize)]
|
#[repr(usize)]
|
||||||
pub enum Status {
|
pub enum Status {
|
||||||
Running = 0,
|
Starting = 0,
|
||||||
Stopped = 1,
|
Running = 1,
|
||||||
Paused = 2,
|
Stopped = 2,
|
||||||
|
Paused = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ManagerSharedState {
|
pub struct ManagerSharedState {
|
||||||
@@ -268,6 +269,15 @@ async fn run_main(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let _ = state
|
||||||
|
.status
|
||||||
|
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| {
|
||||||
|
if x == Status::Starting as usize {
|
||||||
|
Some(Status::Running as usize)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
let res = tokio::select! {
|
let res = tokio::select! {
|
||||||
a = runtime => a.map_err(|_| Error::new(eyre!("Manager runtime panicked!"), crate::ErrorKind::Docker)).and_then(|a| a),
|
a = runtime => a.map_err(|_| Error::new(eyre!("Manager runtime panicked!"), crate::ErrorKind::Docker)).and_then(|a| a),
|
||||||
_ = health => Err(Error::new(eyre!("Health check daemon exited!"), crate::ErrorKind::Unknown)),
|
_ = health => Err(Error::new(eyre!("Health check daemon exited!"), crate::ErrorKind::Unknown)),
|
||||||
@@ -464,10 +474,15 @@ async fn start(shared: &ManagerSharedState) -> Result<(), Error> {
|
|||||||
crate::ErrorKind::Docker,
|
crate::ErrorKind::Docker,
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
shared.status.store(
|
let _ = shared
|
||||||
Status::Running as usize,
|
.status
|
||||||
std::sync::atomic::Ordering::SeqCst,
|
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| {
|
||||||
);
|
if x != Status::Running as usize {
|
||||||
|
Some(Status::Starting as usize)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use std::collections::BTreeMap;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@@ -29,16 +30,34 @@ async fn synchronize_once(shared: &ManagerSharedState) -> Result<(), Error> {
|
|||||||
MainStatus::Stopping => {
|
MainStatus::Stopping => {
|
||||||
*status = MainStatus::Stopped;
|
*status = MainStatus::Stopped;
|
||||||
}
|
}
|
||||||
|
MainStatus::Starting => {
|
||||||
|
start(shared).await?;
|
||||||
|
}
|
||||||
MainStatus::Running { started, .. } => {
|
MainStatus::Running { started, .. } => {
|
||||||
*started = Utc::now();
|
*started = Utc::now();
|
||||||
start(shared).await?;
|
start(shared).await?;
|
||||||
}
|
}
|
||||||
MainStatus::BackingUp { .. } => (),
|
MainStatus::BackingUp { .. } => (),
|
||||||
},
|
},
|
||||||
|
Status::Starting => match *status {
|
||||||
|
MainStatus::Stopped | MainStatus::Stopping => {
|
||||||
|
stop(shared).await?;
|
||||||
|
}
|
||||||
|
MainStatus::Starting | MainStatus::Running { .. } => (),
|
||||||
|
MainStatus::BackingUp { .. } => {
|
||||||
|
pause(shared).await?;
|
||||||
|
}
|
||||||
|
},
|
||||||
Status::Running => match *status {
|
Status::Running => match *status {
|
||||||
MainStatus::Stopped | MainStatus::Stopping => {
|
MainStatus::Stopped | MainStatus::Stopping => {
|
||||||
stop(shared).await?;
|
stop(shared).await?;
|
||||||
}
|
}
|
||||||
|
MainStatus::Starting => {
|
||||||
|
*status = MainStatus::Running {
|
||||||
|
started: Utc::now(),
|
||||||
|
health: BTreeMap::new(),
|
||||||
|
};
|
||||||
|
}
|
||||||
MainStatus::Running { .. } => (),
|
MainStatus::Running { .. } => (),
|
||||||
MainStatus::BackingUp { .. } => {
|
MainStatus::BackingUp { .. } => {
|
||||||
pause(shared).await?;
|
pause(shared).await?;
|
||||||
@@ -48,7 +67,7 @@ async fn synchronize_once(shared: &ManagerSharedState) -> Result<(), Error> {
|
|||||||
MainStatus::Stopped | MainStatus::Stopping => {
|
MainStatus::Stopped | MainStatus::Stopping => {
|
||||||
stop(shared).await?;
|
stop(shared).await?;
|
||||||
}
|
}
|
||||||
MainStatus::Running { .. } => {
|
MainStatus::Starting | MainStatus::Running { .. } => {
|
||||||
resume(shared).await?;
|
resume(shared).await?;
|
||||||
}
|
}
|
||||||
MainStatus::BackingUp { .. } => (),
|
MainStatus::BackingUp { .. } => (),
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ pub struct Status {
|
|||||||
pub enum MainStatus {
|
pub enum MainStatus {
|
||||||
Stopped,
|
Stopped,
|
||||||
Stopping,
|
Stopping,
|
||||||
|
Starting,
|
||||||
Running {
|
Running {
|
||||||
started: DateTime<Utc>,
|
started: DateTime<Utc>,
|
||||||
health: BTreeMap<HealthCheckId, HealthCheckResult>,
|
health: BTreeMap<HealthCheckId, HealthCheckResult>,
|
||||||
@@ -94,22 +95,25 @@ impl MainStatus {
|
|||||||
}
|
}
|
||||||
pub fn running(&self) -> bool {
|
pub fn running(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
MainStatus::Running { .. }
|
MainStatus::Starting
|
||||||
|
| MainStatus::Running { .. }
|
||||||
| MainStatus::BackingUp {
|
| MainStatus::BackingUp {
|
||||||
started: Some(_), ..
|
started: Some(_), ..
|
||||||
} => true,
|
} => true,
|
||||||
_ => false,
|
MainStatus::Stopped
|
||||||
|
| MainStatus::Stopping
|
||||||
|
| MainStatus::BackingUp { started: None, .. } => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn stop(&mut self) {
|
pub fn stop(&mut self) {
|
||||||
match self {
|
match self {
|
||||||
MainStatus::Running { .. } => {
|
MainStatus::Starting | MainStatus::Running { .. } => {
|
||||||
*self = MainStatus::Stopping;
|
*self = MainStatus::Stopping;
|
||||||
}
|
}
|
||||||
MainStatus::BackingUp { started, .. } => {
|
MainStatus::BackingUp { started, .. } => {
|
||||||
*started = None;
|
*started = None;
|
||||||
}
|
}
|
||||||
_ => (),
|
MainStatus::Stopped | MainStatus::Stopping => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user