Crates.io | nydus-service |
lib.rs | nydus-service |
version | 0.3.0 |
source | src |
created_at | 2023-02-14 07:52:49.21568 |
updated_at | 2023-06-17 14:36:44.694666 |
description | Nydus Image Service Manager |
homepage | https://nydus.dev/ |
repository | https://github.com/dragonflyoss/image-service |
max_upload_size | |
id | 784690 |
size | 188,874 |
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:
{
"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:
static ref DAEMON_CONTROLLER: DaemonController = DaemonController::default()
let cmd = FsBackendMountCmd {
fs_type: FsBackendType::Rafs,
// Bootstrap path
source: bootstrap,
// Backend config
config,
// Virutal mountpoint
mountpoint: "/".to_string(),
// Prefetch files
prefetch_files: None,
};
let daemon = {
create_fuse_daemon(
// 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
fuse_threads,
// daemon controller's waker
waker,
// Path to the Nydus daemon administration API socket
Some("api_sock"),
// 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.to_owned(),
)
.map(|d| {
info!("Fuse daemon started!");
d
})
.map_err(|e| {
error!("Failed in starting daemon: {}", e);
e
})?
};
DAEMON_CONTROLLER.set_daemon(daemon);
start daemon controller:
thread::spawn(move || {
let daemon = DAEMON_CONTROLLER.get_daemon();
if let Some(fs) = daemon.get_default_fs_service() {
DAEMON_CONTROLLER.set_fs_service(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.