Skip to content

Commit

Permalink
Fix log filename and pid filename
Browse files Browse the repository at this point in the history
  • Loading branch information
diqiu50 committed Jan 20, 2025
1 parent 8a7c9da commit 0a7a3af
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 29 deletions.
1 change: 1 addition & 0 deletions clients/filesystem-fuse/conf/gvfs_fuse.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
file_mask = 0o600
dir_mask = 0o700
fs_type = "memory"
data_path = "target/gvfs-fuse"

[fuse.properties]

Expand Down
62 changes: 49 additions & 13 deletions clients/filesystem-fuse/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use serde::Deserialize;
use std::collections::HashMap;
use std::fs;

// FuseConfig
pub(crate) const CONF_FUSE_FILE_MASK: ConfigEntity<u32> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"file_mask",
Expand All @@ -45,20 +46,36 @@ pub(crate) const CONF_FUSE_FS_TYPE: ConfigEntity<&'static str> = ConfigEntity::n
"memory",
);

pub(crate) const CONF_FUSE_CONFIG_PATH: ConfigEntity<&'static str> = ConfigEntity::new(
pub(crate) const CONF_FUSE_CONFIG_FILE_PATH: ConfigEntity<&'static str> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"config_path",
"The path of the FUSE configuration file",
"/etc/gvfs/gvfs.toml",
"/etc/gvfs-fuse/config.toml",
);

pub(crate) const CONF_FUSE_DATA_DIR: ConfigEntity<&'static str> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"data_dir",
"The data path of GVFS FUSE",
"/var/data/gvfs-fuse",
);

pub(crate) const CONF_FUSE_LOG_DIR: ConfigEntity<&'static str> = ConfigEntity::new(
FuseConfig::MODULE_NAME,
"log_dir",
"The log path of GVFS FUSE",
"logs", //relative to the data path
);

// FilesystemConfig
pub(crate) const CONF_FILESYSTEM_BLOCK_SIZE: ConfigEntity<u32> = ConfigEntity::new(
FilesystemConfig::MODULE_NAME,
"block_size",
"The block size of the gvfs fuse filesystem",
4096,
);

// GravitinoConfig
pub(crate) const CONF_GRAVITINO_URI: ConfigEntity<&'static str> = ConfigEntity::new(
GravitinoConfig::MODULE_NAME,
"uri",
Expand Down Expand Up @@ -125,22 +142,32 @@ impl Default for DefaultConfig {
ConfigValue::String(CONF_FUSE_FS_TYPE),
);
configs.insert(
Self::compose_key(CONF_FUSE_CONFIG_PATH),
ConfigValue::String(CONF_FUSE_CONFIG_PATH),
Self::compose_key(CONF_FUSE_CONFIG_FILE_PATH),
ConfigValue::String(CONF_FUSE_CONFIG_FILE_PATH),
);
configs.insert(
Self::compose_key(CONF_GRAVITINO_URI),
ConfigValue::String(CONF_GRAVITINO_URI),
Self::compose_key(CONF_FUSE_DATA_DIR),
ConfigValue::String(CONF_FUSE_DATA_DIR),
);
configs.insert(
Self::compose_key(CONF_GRAVITINO_METALAKE),
ConfigValue::String(CONF_GRAVITINO_METALAKE),
Self::compose_key(CONF_FUSE_LOG_DIR),
ConfigValue::String(CONF_FUSE_LOG_DIR),
);

configs.insert(
Self::compose_key(CONF_FILESYSTEM_BLOCK_SIZE),
ConfigValue::U32(CONF_FILESYSTEM_BLOCK_SIZE),
);

configs.insert(
Self::compose_key(CONF_GRAVITINO_URI),
ConfigValue::String(CONF_GRAVITINO_URI),
);
configs.insert(
Self::compose_key(CONF_GRAVITINO_METALAKE),
ConfigValue::String(CONF_GRAVITINO_METALAKE),
);

DefaultConfig { configs }
}
}
Expand Down Expand Up @@ -220,19 +247,20 @@ impl AppConfig {
info!("Use configuration file: {}", &path);
path
} else {
//use default config
if fs::metadata(CONF_FUSE_CONFIG_PATH.default).is_err() {
if fs::metadata(CONF_FUSE_CONFIG_FILE_PATH.default).is_err() {
//use default config
warn!(
"The default configuration file is not found, using the default configuration"
);
return Ok(AppConfig::default());
} else {
//use the default configuration file
warn!(
"Using the default config file {}",
CONF_FUSE_CONFIG_PATH.default
CONF_FUSE_CONFIG_FILE_PATH.default
);
}
CONF_FUSE_CONFIG_PATH.default.to_string()
CONF_FUSE_CONFIG_FILE_PATH.default.to_string()
}
};
let config = builder
Expand Down Expand Up @@ -265,7 +293,11 @@ pub struct FuseConfig {
#[serde(default)]
pub fs_type: String,
#[serde(default)]
pub config_path: String,
pub config_file_path: String,
#[serde(default)]
pub data_dir: String,
#[serde(default)]
pub log_dir: String,
#[serde(default)]
pub properties: HashMap<String, String>,
}
Expand Down Expand Up @@ -305,6 +337,8 @@ mod test {
let config = AppConfig::from_file(Some("tests/conf/config_test.toml".to_string())).unwrap();
assert_eq!(config.fuse.file_mask, 0o644);
assert_eq!(config.fuse.dir_mask, 0o755);
assert_eq!(config.fuse.data_dir, "/target/gvfs-fuse");
assert_eq!(config.fuse.log_dir, "/target/gvfs-fuse/logs");
assert_eq!(config.filesystem.block_size, 8192);
assert_eq!(config.gravitino.uri, "http://localhost:8090");
assert_eq!(config.gravitino.metalake, "test");
Expand All @@ -323,6 +357,8 @@ mod test {
let config = AppConfig::default();
assert_eq!(config.fuse.file_mask, 0o600);
assert_eq!(config.fuse.dir_mask, 0o700);
assert_eq!(config.fuse.data_dir, "/var/data/gvfs-fuse");
assert_eq!(config.fuse.log_dir, "logs");
assert_eq!(config.filesystem.block_size, 4096);
assert_eq!(config.gravitino.uri, "http://localhost:8090");
assert_eq!(config.gravitino.metalake, "");
Expand Down
3 changes: 3 additions & 0 deletions clients/filesystem-fuse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ macro_rules! test_enable_with {
pub const RUN_TEST_WITH_S3: &str = "RUN_TEST_WITH_S3";
pub const RUN_TEST_WITH_FUSE: &str = "RUN_TEST_WITH_FUSE";

pub const LOG_FILE_NAME: &str = "gvfs-fuse.log";
pub const PID_FILE_NAME: &str = "gvfs-fuse.pid";

pub async fn gvfs_mount(mount_to: &str, mount_from: &str, config: &AppConfig) -> GvfsResult<()> {
gvfs_fuse::mount(mount_to, mount_from, config).await
}
Expand Down
45 changes: 29 additions & 16 deletions clients/filesystem-fuse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,43 @@ use crate::command_args::Commands;
use clap::Parser;
use daemonize::Daemonize;
use gvfs_fuse::config::AppConfig;
use gvfs_fuse::{gvfs_mount, gvfs_unmount};
use gvfs_fuse::{gvfs_mount, gvfs_unmount, LOG_FILE_NAME, PID_FILE_NAME};
use log::{error, info};
use std::fs::OpenOptions;
use std::fs::{create_dir_all, OpenOptions};
use std::io;
use std::path::Path;
use std::process::{exit, Command};
use std::{env, io};
use tokio::runtime::Runtime;
use tokio::signal;
use tokio::signal::unix::{signal, SignalKind};

fn make_daemon() {
let log_file_name = "/tmp/gvfs-fuse.log";
fn make_daemon(config: &AppConfig) -> io::Result<()> {
let data_dir_name = Path::new(&config.fuse.data_dir).to_path_buf();
if !data_dir_name.exists() {
Err(io::Error::new(
io::ErrorKind::NotFound,
format!("Data directory {} not found", &config.fuse.data_dir),
))?
};

let log_dir_name = data_dir_name.join(&config.fuse.log_dir);
if !log_dir_name.exists() {
create_dir_all(&log_dir_name)?
};
let log_file_name = Path::new(&config.fuse.log_dir).join(LOG_FILE_NAME);
let log_file = OpenOptions::new()
.create(true)
.append(true)
.open(log_file_name)
.open(&log_file_name)
.unwrap();
let log_err_file = OpenOptions::new().write(true).open(log_file_name).unwrap();
let log_err_file = OpenOptions::new().append(true).open(log_file_name).unwrap();

let cwd = env::current_dir();
if let Err(e) = cwd {
error!("Error getting current directory: {}", e);
return;
}
let cwd = cwd.unwrap();
let pid_file_name = data_dir_name.join(PID_FILE_NAME);

let daemonize = Daemonize::new()
.pid_file("/tmp/gvfs-fuse.pid")
.pid_file(pid_file_name)
.chown_pid_file(true)
.working_directory(&cwd)
.working_directory(&data_dir_name)
.stdout(log_file)
.stderr(log_err_file);

Expand All @@ -61,6 +69,7 @@ fn make_daemon() {
exit(-1)
}
}
Ok(())
}

fn mount_fuse(config: AppConfig, mount_point: String, target: String) -> io::Result<()> {
Expand Down Expand Up @@ -162,7 +171,11 @@ fn main() -> Result<(), i32> {
let result = if foreground {
mount_fuse(app_config, mount_point, location)
} else {
make_daemon();
let result = make_daemon(&app_config);
if let Err(e) = result {
error!("Failed to daemonize: {:?}", e);
return Err(-1);
};
mount_fuse(app_config, mount_point, location)
};

Expand Down
2 changes: 2 additions & 0 deletions clients/filesystem-fuse/tests/conf/config_test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
file_mask= 0o644
dir_mask= 0o755
fs_type = "memory"
data_dir = "/target/gvfs-fuse"
log_dir = "/target/gvfs-fuse/logs"

[fuse.properties]
key1 = "value1"
Expand Down
1 change: 1 addition & 0 deletions clients/filesystem-fuse/tests/conf/gvfs_fuse_s3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
file_mask= 0o600
dir_mask= 0o700
fs_type = "gvfs"
data_path = "target/debug/gvfs-fuse"

[fuse.properties]
key1 = "value1"
Expand Down

0 comments on commit 0a7a3af

Please sign in to comment.