mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
stop using exit codes, track app state
This commit is contained in:
committed by
Keagan McClelland
parent
30f8b8e6cd
commit
5a121945d2
@@ -1,18 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
for CONTAINER in $(docker ps -aq); do
|
exec appmgr repair-app-status
|
||||||
EXIT=`docker inspect -f "{{ .State.ExitCode }}" $CONTAINER`
|
|
||||||
if [ $EXIT -eq 0 ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if [ $EXIT -eq 143 ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if [ $EXIT -eq 137 ]; then
|
|
||||||
OOM=`docker inspect -f "{{ .State.OOMKilled }}" $CONTAINER`
|
|
||||||
if [ "$OOM" == "false" ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
docker start $CONTAINER
|
|
||||||
done
|
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use futures::future::{BoxFuture, FutureExt};
|
use futures::future::{BoxFuture, FutureExt};
|
||||||
use linear_map::LinearMap;
|
use linear_map::{set::LinearSet, LinearMap};
|
||||||
|
|
||||||
use crate::dependencies::{DependencyError, TaggedDependencyError};
|
use crate::dependencies::{DependencyError, TaggedDependencyError};
|
||||||
|
use crate::util::{from_yaml_async_reader, PersistencePath, YamlUpdateHandle};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
pub async fn start_app(name: &str, update_metadata: bool) -> Result<(), Error> {
|
pub async fn start_app(name: &str, update_metadata: bool) -> Result<(), Error> {
|
||||||
@@ -38,6 +39,12 @@ pub async fn start_app(name: &str, update_metadata: bool) -> Result<(), Error> {
|
|||||||
"Failed to Start Application: {}",
|
"Failed to Start Application: {}",
|
||||||
std::str::from_utf8(&output.stderr).unwrap_or("Unknown Error")
|
std::str::from_utf8(&output.stderr).unwrap_or("Unknown Error")
|
||||||
);
|
);
|
||||||
|
let mut running = YamlUpdateHandle::<LinearSet<String>>::new_or_default(
|
||||||
|
PersistencePath::from_ref("running.yaml"),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
running.insert(name.to_owned());
|
||||||
|
running.commit().await?;
|
||||||
} else if status == crate::apps::DockerStatus::Paused {
|
} else if status == crate::apps::DockerStatus::Paused {
|
||||||
resume_app(name).await?;
|
resume_app(name).await?;
|
||||||
}
|
}
|
||||||
@@ -79,6 +86,12 @@ pub async fn stop_app(
|
|||||||
"Failed to Stop Application: {}",
|
"Failed to Stop Application: {}",
|
||||||
std::str::from_utf8(&output.stderr).unwrap_or("Unknown Error")
|
std::str::from_utf8(&output.stderr).unwrap_or("Unknown Error")
|
||||||
);
|
);
|
||||||
|
let mut running = YamlUpdateHandle::<LinearSet<String>>::new_or_default(
|
||||||
|
PersistencePath::from_ref("running.yaml"),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
running.remove(name);
|
||||||
|
running.commit().await?;
|
||||||
crate::util::unlock(lock).await?;
|
crate::util::unlock(lock).await?;
|
||||||
}
|
}
|
||||||
Ok(res)
|
Ok(res)
|
||||||
@@ -192,3 +205,34 @@ pub async fn resume_app(name: &str) -> Result<(), Error> {
|
|||||||
crate::util::unlock(lock).await?;
|
crate::util::unlock(lock).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn repair_app_status() -> Result<(), Error> {
|
||||||
|
let running: Vec<String> = if let Some(mut f) = PersistencePath::from_ref("running.yaml")
|
||||||
|
.maybe_read(false)
|
||||||
|
.await
|
||||||
|
.transpose()?
|
||||||
|
{
|
||||||
|
from_yaml_async_reader(&mut *f).await?
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
};
|
||||||
|
for name in running {
|
||||||
|
let lock = crate::util::lock_file(
|
||||||
|
format!(
|
||||||
|
"{}",
|
||||||
|
Path::new(crate::PERSISTENCE_DIR)
|
||||||
|
.join("apps")
|
||||||
|
.join(&name)
|
||||||
|
.join("control.lock")
|
||||||
|
.display()
|
||||||
|
),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
if crate::apps::status(&name).await?.status == crate::apps::DockerStatus::Stopped {
|
||||||
|
start_app(&name, true).await?;
|
||||||
|
}
|
||||||
|
crate::util::unlock(lock).await?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
@@ -816,6 +816,9 @@ async fn inner_main() -> Result<(), Error> {
|
|||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.help("Password to use for encryption of backup file"),
|
.help("Password to use for encryption of backup file"),
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("repair-app-status").about("Restarts crashed apps"), // TODO: remove
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1540,6 +1543,10 @@ async fn inner_main() -> Result<(), Error> {
|
|||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
#[cfg(not(feature = "portable"))]
|
||||||
|
("repair-app-status", _) => {
|
||||||
|
control::repair_app_status().await?;
|
||||||
|
}
|
||||||
("pack", Some(sub_m)) => {
|
("pack", Some(sub_m)) => {
|
||||||
pack(
|
pack(
|
||||||
sub_m.value_of("PATH").unwrap(),
|
sub_m.value_of("PATH").unwrap(),
|
||||||
|
|||||||
Reference in New Issue
Block a user