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