ksud: use bind mount to serve module webui
This commit is contained in:
@@ -192,6 +192,15 @@ enum Module {
|
|||||||
#[arg(default_value = "8080")]
|
#[arg(default_value = "8080")]
|
||||||
port: u16,
|
port: u16,
|
||||||
},
|
},
|
||||||
|
/// Link modules for manager
|
||||||
|
LinkManager {
|
||||||
|
/// module id
|
||||||
|
mid: String,
|
||||||
|
/// Manager's pid
|
||||||
|
pid: i32,
|
||||||
|
/// Manager's package name
|
||||||
|
pkg: String,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(clap::Subcommand, Debug)]
|
#[derive(clap::Subcommand, Debug)]
|
||||||
@@ -273,6 +282,9 @@ pub fn run() -> Result<()> {
|
|||||||
Module::List => module::list_modules(),
|
Module::List => module::list_modules(),
|
||||||
Module::Shrink => module::shrink_ksu_images(),
|
Module::Shrink => module::shrink_ksu_images(),
|
||||||
Module::Serve { id, port } => server::serve_module(&id, port),
|
Module::Serve { id, port } => server::serve_module(&id, port),
|
||||||
|
Module::LinkManager { mid, pid, pkg } => {
|
||||||
|
module::link_module_for_manager(pid, &pkg, &mid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Commands::Install => event::install(),
|
Commands::Install => event::install(),
|
||||||
|
|||||||
@@ -703,3 +703,24 @@ pub fn shrink_ksu_images() -> Result<()> {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
|
pub fn link_module_for_manager(pid: i32, pkg: &str, mid: &str) -> Result<()> {
|
||||||
|
// switch to manager's mnt ns
|
||||||
|
utils::switch_mnt_ns(pid)?;
|
||||||
|
let target = PathBuf::from("/data/data").join(pkg).join("webroot");
|
||||||
|
|
||||||
|
// umount previous mount
|
||||||
|
let _ = mount::umount_dir(&target);
|
||||||
|
|
||||||
|
let src = PathBuf::from(defs::MODULE_DIR)
|
||||||
|
.join(mid)
|
||||||
|
.join(defs::MODULE_WEB_DIR);
|
||||||
|
mount::bind_mount(src, &target)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
||||||
|
pub fn link_module_for_manager(_pid: i32, _pkg: &str, _mid: &str) -> Result<()> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ pub fn mount_tmpfs(dest: impl AsRef<Path>) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
fn bind_mount(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
|
pub fn bind_mount(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()> {
|
||||||
info!(
|
info!(
|
||||||
"bind mount {} -> {}",
|
"bind mount {} -> {}",
|
||||||
from.as_ref().display(),
|
from.as_ref().display(),
|
||||||
|
|||||||
Reference in New Issue
Block a user