mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
fixes an issue where if a package had multiple port mappings, only the last one would get an nginx config
include the nginx paths when *removing* a package
This commit is contained in:
committed by
Aiden McClelland
parent
cc0535ad5b
commit
adeaabfa5f
@@ -9,7 +9,7 @@ use std::time::Duration;
|
||||
use bollard::Docker;
|
||||
use color_eyre::eyre::eyre;
|
||||
use patch_db::json_ptr::JsonPointer;
|
||||
use patch_db::{DbHandle, PatchDb, Revision};
|
||||
use patch_db::{DbHandle, LockType, PatchDb, Revision};
|
||||
use reqwest::Url;
|
||||
use rpc_toolkit::url::Host;
|
||||
use rpc_toolkit::Context;
|
||||
@@ -301,6 +301,10 @@ impl RpcContext {
|
||||
#[instrument(skip(self))]
|
||||
pub async fn cleanup(&self) -> Result<(), Error> {
|
||||
let mut db = self.db.handle();
|
||||
crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.lock(&mut db, LockType::Write)
|
||||
.await?;
|
||||
for package_id in crate::db::DatabaseModel::new()
|
||||
.package_data()
|
||||
.keys(&mut db, true)
|
||||
|
||||
@@ -126,7 +126,7 @@ pub async fn install(
|
||||
match pde.take() {
|
||||
Some(PackageDataEntry::Installed {
|
||||
installed,
|
||||
manifest,
|
||||
manifest: _manifest,
|
||||
static_files,
|
||||
}) => {
|
||||
*pde = Some(PackageDataEntry::Updating {
|
||||
@@ -1020,13 +1020,19 @@ pub async fn install_s9pk<R: AsyncRead + AsyncSeek + Unpin>(
|
||||
add_dependent_to_current_dependents_lists(&mut tx, pkg_id, ¤t_dependencies).await?;
|
||||
update_dependency_errors_of_dependents(ctx, &mut tx, pkg_id, current_dependents.keys())
|
||||
.await?;
|
||||
} else if let Some(recovered) = crate::db::DatabaseModel::new()
|
||||
.recovered_packages()
|
||||
.idx_model(pkg_id)
|
||||
.get(&mut tx, true)
|
||||
.await?
|
||||
.into_owned()
|
||||
{
|
||||
} else if let Some(recovered) = {
|
||||
// solve taxonomy escalation
|
||||
crate::db::DatabaseModel::new()
|
||||
.recovered_packages()
|
||||
.lock(&mut tx, LockType::Write)
|
||||
.await?;
|
||||
crate::db::DatabaseModel::new()
|
||||
.recovered_packages()
|
||||
.idx_model(pkg_id)
|
||||
.get(&mut tx, true)
|
||||
.await?
|
||||
.into_owned()
|
||||
} {
|
||||
handle_recovered_package(recovered, manifest, ctx, pkg_id, version, &mut tx).await?;
|
||||
add_dependent_to_current_dependents_lists(&mut tx, pkg_id, ¤t_dependencies).await?;
|
||||
update_dependency_errors_of_dependents(ctx, &mut tx, pkg_id, current_dependents.keys())
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use patch_db::DbHandle;
|
||||
use patch_db::{DbHandle, LockType};
|
||||
use reqwest::Url;
|
||||
use rpc_toolkit::command;
|
||||
|
||||
@@ -10,6 +10,10 @@ use crate::Error;
|
||||
pub async fn set_eos_url(#[context] ctx: RpcContext, #[arg] url: Url) -> Result<(), Error> {
|
||||
let mut db = ctx.db.handle();
|
||||
let mut tx = db.begin().await?;
|
||||
crate::db::DatabaseModel::new()
|
||||
.server_info()
|
||||
.lock(&mut tx, LockType::Write)
|
||||
.await?;
|
||||
crate::db::DatabaseModel::new()
|
||||
.server_info()
|
||||
.eos_marketplace()
|
||||
@@ -24,12 +28,16 @@ pub async fn set_eos_url(#[context] ctx: RpcContext, #[arg] url: Url) -> Result<
|
||||
pub async fn set_package_url(#[context] ctx: RpcContext, #[arg] url: Url) -> Result<(), Error> {
|
||||
let mut db = ctx.db.handle();
|
||||
let mut tx = db.begin().await?;
|
||||
ctx.set_nginx_conf(&mut tx).await?;
|
||||
crate::db::DatabaseModel::new()
|
||||
.server_info()
|
||||
.lock(&mut tx, LockType::Write)
|
||||
.await?;
|
||||
crate::db::DatabaseModel::new()
|
||||
.server_info()
|
||||
.package_marketplace()
|
||||
.put(&mut tx, &Some(url))
|
||||
.await?;
|
||||
ctx.set_nginx_conf(&mut tx).await?;
|
||||
tx.commit(None).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -120,8 +120,10 @@ impl NginxControllerInner {
|
||||
)
|
||||
};
|
||||
// write nginx configs
|
||||
let nginx_conf_path =
|
||||
nginx_root.join(format!("sites-available/{}_{}.conf", package, id));
|
||||
let nginx_conf_path = nginx_root.join(format!(
|
||||
"sites-available/{}_{}_{}.conf",
|
||||
package, id, port.0
|
||||
));
|
||||
tokio::fs::write(
|
||||
&nginx_conf_path,
|
||||
format!(
|
||||
@@ -138,7 +140,7 @@ impl NginxControllerInner {
|
||||
.await
|
||||
.with_ctx(|_| (ErrorKind::Filesystem, nginx_conf_path.display().to_string()))?;
|
||||
let sites_enabled_link_path =
|
||||
nginx_root.join(format!("sites-enabled/{}_{}.conf", package, id));
|
||||
nginx_root.join(format!("sites-enabled/{}_{}_{}.conf", package, id, port.0));
|
||||
if tokio::fs::metadata(&sites_enabled_link_path).await.is_ok() {
|
||||
tokio::fs::remove_file(&sites_enabled_link_path).await?;
|
||||
}
|
||||
@@ -150,7 +152,7 @@ impl NginxControllerInner {
|
||||
match self.interfaces.get_mut(&package) {
|
||||
None => {
|
||||
let info = PackageNetInfo {
|
||||
ip: ipv4,
|
||||
_ip: ipv4,
|
||||
interfaces: interface_map,
|
||||
};
|
||||
self.interfaces.insert(package, info);
|
||||
@@ -168,35 +170,44 @@ impl NginxControllerInner {
|
||||
async fn remove(&mut self, nginx_root: &Path, package: &PackageId) -> Result<(), Error> {
|
||||
let removed = self.interfaces.remove(package);
|
||||
if let Some(net_info) = removed {
|
||||
for (id, _meta) in net_info.interfaces {
|
||||
// remove ssl certificates and nginx configs
|
||||
let package_path = nginx_root.join(format!("ssl/{}", package));
|
||||
let enabled_path =
|
||||
nginx_root.join(format!("sites-enabled/{}_{}.conf", package, id));
|
||||
let available_path =
|
||||
nginx_root.join(format!("sites-available/{}_{}.conf", package, id));
|
||||
let _ = tokio::try_join!(
|
||||
async {
|
||||
if tokio::fs::metadata(&package_path).await.is_ok() {
|
||||
tokio::fs::remove_dir_all(&package_path)
|
||||
.map(|res| {
|
||||
res.with_ctx(|_| {
|
||||
(ErrorKind::Filesystem, package_path.display().to_string())
|
||||
for (id, meta) in net_info.interfaces {
|
||||
for (port, _lan_port_config) in meta.lan_config.iter() {
|
||||
// remove ssl certificates and nginx configs
|
||||
let package_path = nginx_root.join(format!("ssl/{}", package));
|
||||
let enabled_path = nginx_root
|
||||
.join(format!("sites-enabled/{}_{}_{}.conf", package, id, port.0));
|
||||
let available_path = nginx_root.join(format!(
|
||||
"sites-available/{}_{}_{}.conf",
|
||||
package, id, port.0
|
||||
));
|
||||
let _ = tokio::try_join!(
|
||||
async {
|
||||
if tokio::fs::metadata(&package_path).await.is_ok() {
|
||||
tokio::fs::remove_dir_all(&package_path)
|
||||
.map(|res| {
|
||||
res.with_ctx(|_| {
|
||||
(
|
||||
ErrorKind::Filesystem,
|
||||
package_path.display().to_string(),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
.await?;
|
||||
Ok(())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
tokio::fs::remove_file(&enabled_path).map(|res| res
|
||||
.with_ctx(|_| (ErrorKind::Filesystem, enabled_path.display().to_string()))),
|
||||
tokio::fs::remove_file(&available_path).map(|res| res.with_ctx(|_| (
|
||||
ErrorKind::Filesystem,
|
||||
available_path.display().to_string()
|
||||
))),
|
||||
)?;
|
||||
.await?;
|
||||
Ok(())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
tokio::fs::remove_file(&enabled_path).map(|res| res.with_ctx(|_| (
|
||||
ErrorKind::Filesystem,
|
||||
enabled_path.display().to_string()
|
||||
))),
|
||||
tokio::fs::remove_file(&available_path).map(|res| res.with_ctx(|_| (
|
||||
ErrorKind::Filesystem,
|
||||
available_path.display().to_string()
|
||||
))),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
self.hup().await?;
|
||||
@@ -214,7 +225,7 @@ impl NginxControllerInner {
|
||||
}
|
||||
}
|
||||
struct PackageNetInfo {
|
||||
ip: Ipv4Addr,
|
||||
_ip: Ipv4Addr,
|
||||
interfaces: BTreeMap<InterfaceId, InterfaceMetadata>,
|
||||
}
|
||||
pub struct InterfaceMetadata {
|
||||
|
||||
Reference in New Issue
Block a user