The nydus-service
crate helps to reuse the core services of nydus, allowing you to integrate nydus services into your project elegantly and easily. It provides:
It also supplies the nydus daemon and the daemon controller to help manage these services.
You're supposed to know that nydusd
running as daemon to expose a FUSE mountpoint, a Virtio-FS mountpoint or an EROFS mountpoint inside guest for containers to access, and it provides key features include:
If you want to use these features as native in your project without preparing and invoking nydusd
deliberately, nydus-service
is just born for this.
For example, reuse the fuse service with nydus-service
in three steps.
prepare the config:
rust
{
"device": {
"backend": {
"type": "registry",
"config": {
"scheme": "",
"skip_verify": true,
"timeout": 5,
"connect_timeout": 5,
"retry_limit": 4,
"auth": "YOUR_LOGIN_AUTH="
}
},
"cache": {
"type": "blobcache",
"config": {
"work_dir": "cache"
}
}
},
"mode": "direct",
"digest_validate": false,
"iostats_files": false,
"enable_xattr": true,
"fs_prefetch": {
"enable": true,
"threads_count": 4
}
}
create a daemon:
```Rust static ref DAEMON_CONTROLLER: DaemonController = DaemonController::default()
let cmd = FsBackendMountCmd { fstype: FsBackendType::Rafs, // Bootstrap path source: bootstrap, // Backend config config, // Virutal mountpoint mountpoint: "/".tostring(), // Prefetch files prefetch_files: None, };
let daemon = {
createfusedaemon(
// Mountpoint for the FUSE filesystem, target for mount.fuse
mountpoint,
// Vfs associated with the filesystem service object
vfs,
// Supervisor
None,
// Service instance identifier
id,
// Number of working threads to serve fuse requests
fusethreads,
// daemon controller's waker
waker,
// Path to the Nydus daemon administration API socket
Some("apisock"),
// Start Nydus daemon in upgrade mode
upgrade,
// Mounts FUSE filesystem in rw mode
!writable,
// FUSE server failover policy
failvoer-policy,
// Request structure to mount a backend filesystem instance
Some(cmd),
BTI.toowned(),
)
.map(|d| {
info!("Fuse daemon started!");
d
})
.maperr(|e| {
error!("Failed in starting daemon: {}", e);
e
})?
};
DAEMONCONTROLLER.setdaemon(daemon); ```
start daemon controller:
```rust thread::spawn(move || { let daemon = DAEMONCONTROLLER.getdaemon(); if let Some(fs) = daemon.getdefaultfsservice() { DAEMONCONTROLLER.setfsservice(fs); }
// Run the main event loop
if DAEMON_CONTROLLER.is_active() {
DAEMON_CONTROLLER.run_loop();
}
// Gracefully shutdown system.
info!("nydusd quits");
DAEMON_CONTROLLER.shutdown();
}); ```
Then, you can make the most of nydus services in your project.
Platforms:
Operating Systems:
This code is licensed under Apache-2.0 or BSD-3-Clause.