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