mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
fix: Stop service before (#2019)
This commit is contained in:
@@ -121,13 +121,14 @@ impl StopReceipts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(db))]
|
#[instrument(skip(db))]
|
||||||
async fn stop_common<Db: DbHandle>(
|
pub async fn stop_common<Db: DbHandle>(
|
||||||
db: &mut Db,
|
db: &mut Db,
|
||||||
id: &PackageId,
|
id: &PackageId,
|
||||||
breakages: &mut BTreeMap<PackageId, TaggedDependencyError>,
|
breakages: &mut BTreeMap<PackageId, TaggedDependencyError>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<MainStatus, Error> {
|
||||||
let mut tx = db.begin().await?;
|
let mut tx = db.begin().await?;
|
||||||
let receipts = StopReceipts::new(&mut tx, id).await?;
|
let receipts = StopReceipts::new(&mut tx, id).await?;
|
||||||
|
let last_status = receipts.status.get(&mut tx).await?;
|
||||||
receipts.status.set(&mut tx, MainStatus::Stopping).await?;
|
receipts.status.set(&mut tx, MainStatus::Stopping).await?;
|
||||||
|
|
||||||
tx.save().await?;
|
tx.save().await?;
|
||||||
@@ -140,7 +141,7 @@ async fn stop_common<Db: DbHandle>(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(last_status)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command(
|
#[command(
|
||||||
@@ -170,15 +171,15 @@ pub async fn stop_dry(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(ctx))]
|
#[instrument(skip(ctx))]
|
||||||
pub async fn stop_impl(ctx: RpcContext, id: PackageId) -> Result<(), Error> {
|
pub async fn stop_impl(ctx: RpcContext, id: PackageId) -> Result<MainStatus, Error> {
|
||||||
let mut db = ctx.db.handle();
|
let mut db = ctx.db.handle();
|
||||||
let mut tx = db.begin().await?;
|
let mut tx = db.begin().await?;
|
||||||
|
|
||||||
stop_common(&mut tx, &id, &mut BTreeMap::new()).await?;
|
let last_statuts = stop_common(&mut tx, &id, &mut BTreeMap::new()).await?;
|
||||||
|
|
||||||
tx.commit().await?;
|
tx.commit().await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(last_statuts)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command(display(display_none), metadata(sync_db = true))]
|
#[command(display(display_none), metadata(sync_db = true))]
|
||||||
|
|||||||
@@ -710,8 +710,10 @@ pub async fn download_install_s9pk(
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let pkg_id = &temp_manifest.id;
|
let pkg_id = &temp_manifest.id;
|
||||||
let version = &temp_manifest.version;
|
let version = &temp_manifest.version;
|
||||||
|
let mut previous_state: Option<MainStatus> = None;
|
||||||
|
|
||||||
if let Err(e) = async {
|
if let Err(e) = async {
|
||||||
|
previous_state = Some(crate::control::stop_impl(ctx.clone(), pkg_id.clone()).await?);
|
||||||
let mut db_handle = ctx.db.handle();
|
let mut db_handle = ctx.db.handle();
|
||||||
let mut tx = db_handle.begin().await?;
|
let mut tx = db_handle.begin().await?;
|
||||||
let receipts = DownloadInstallReceipts::new(&mut tx, &pkg_id).await?;
|
let receipts = DownloadInstallReceipts::new(&mut tx, &pkg_id).await?;
|
||||||
@@ -813,6 +815,10 @@ pub async fn download_install_s9pk(
|
|||||||
}
|
}
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
if previous_state.map(|x| x.running()).unwrap_or(false) {
|
||||||
|
crate::control::start(ctx.clone(), pkg_id.clone()).await?;
|
||||||
|
}
|
||||||
|
|
||||||
let mut handle = ctx.db.handle();
|
let mut handle = ctx.db.handle();
|
||||||
let mut tx = handle.begin().await?;
|
let mut tx = handle.begin().await?;
|
||||||
let receipts = cleanup::CleanupFailedReceipts::new(&mut tx).await?;
|
let receipts = cleanup::CleanupFailedReceipts::new(&mut tx).await?;
|
||||||
@@ -825,6 +831,9 @@ pub async fn download_install_s9pk(
|
|||||||
}
|
}
|
||||||
Err(e)
|
Err(e)
|
||||||
} else {
|
} else {
|
||||||
|
if previous_state.map(|x| x.running()).unwrap_or(false) {
|
||||||
|
crate::control::start(ctx.clone(), pkg_id.clone()).await?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user