mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
feat: Add the stop/start loop for the service
This commit is contained in:
@@ -7,7 +7,7 @@ use std::{ffi::OsString, time::Instant};
|
||||
use chrono::Utc;
|
||||
use clap::builder::{TypedValueParser, ValueParserFactory};
|
||||
use clap::Parser;
|
||||
use imbl_value::json;
|
||||
use imbl_value::{json, InternedString};
|
||||
use models::{ActionId, HealthCheckId, ImageId, PackageId};
|
||||
use patch_db::json_ptr::JsonPointer;
|
||||
use rpc_toolkit::{from_fn, from_fn_async, AnyContext, Context, Empty, HandlerExt, ParentHandler};
|
||||
@@ -111,11 +111,15 @@ pub fn service_effect_handler() -> ParentHandler {
|
||||
.subcommand(
|
||||
"createOverlayedImage",
|
||||
from_fn_async(create_overlayed_image)
|
||||
.with_custom_display_fn::<AnyContext, _>(|_, path| {
|
||||
.with_custom_display_fn::<AnyContext, _>(|_, (path, _)| {
|
||||
Ok(println!("{}", path.display()))
|
||||
})
|
||||
.with_remote_cli::<ContainerCliContext>(),
|
||||
)
|
||||
.subcommand(
|
||||
"destroyOverlayedImage",
|
||||
from_fn_async(destroy_overlayed_image).no_cli(),
|
||||
)
|
||||
.subcommand(
|
||||
"getSslCertificate",
|
||||
from_fn_async(get_ssl_certificate).no_cli(),
|
||||
@@ -668,7 +672,32 @@ async fn set_health(context: EffectContext, params: SetHealth) -> Result<Value,
|
||||
.await?;
|
||||
Ok(json!(()))
|
||||
}
|
||||
#[derive(serde::Deserialize, serde::Serialize, Parser)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[command(rename_all = "camelCase")]
|
||||
pub struct DestroyOverlayedImageParams {
|
||||
image_id: ImageId,
|
||||
guid: InternedString,
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
pub async fn destroy_overlayed_image(
|
||||
ctx: EffectContext,
|
||||
DestroyOverlayedImageParams { image_id, guid }: DestroyOverlayedImageParams,
|
||||
) -> Result<(), Error> {
|
||||
let ctx = ctx.deref()?;
|
||||
if ctx
|
||||
.persistent_container
|
||||
.overlays
|
||||
.lock()
|
||||
.await
|
||||
.remove(&guid)
|
||||
.is_none()
|
||||
{
|
||||
tracing::warn!("Could not find a guard to remove on the destroy overlayed image; assumming that it already is removed and will be skipping");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
#[derive(serde::Deserialize, serde::Serialize, Parser)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[command(rename_all = "camelCase")]
|
||||
@@ -680,10 +709,10 @@ pub struct CreateOverlayedImageParams {
|
||||
pub async fn create_overlayed_image(
|
||||
ctx: EffectContext,
|
||||
CreateOverlayedImageParams { image_id }: CreateOverlayedImageParams,
|
||||
) -> Result<PathBuf, Error> {
|
||||
) -> Result<(PathBuf, InternedString), Error> {
|
||||
let ctx = ctx.deref()?;
|
||||
let path = Path::new("images")
|
||||
.join(&*ARCH)
|
||||
.join(*ARCH)
|
||||
.join(&image_id)
|
||||
.with_extension("squashfs");
|
||||
if let Some(image) = ctx
|
||||
@@ -730,7 +759,7 @@ pub async fn create_overlayed_image(
|
||||
.lock()
|
||||
.await
|
||||
.insert(guid.clone(), guard);
|
||||
Ok(container_mountpoint)
|
||||
Ok((container_mountpoint, guid))
|
||||
} else {
|
||||
Err(Error::new(
|
||||
eyre!("image {image_id} not found in s9pk"),
|
||||
|
||||
Reference in New Issue
Block a user