Misc 4 #66
@ -88,6 +88,7 @@ fn bootstrap_server_connection(
|
||||
}
|
||||
|
||||
if fs::metadata(DEFAULT_SOCKET_PATH).is_ok() {
|
||||
log::debug!("Connecting to default socket at {:?}", DEFAULT_SOCKET_PATH);
|
||||
return match StdUnixStream::connect(DEFAULT_SOCKET_PATH) {
|
||||
Ok(socket) => Ok(socket),
|
||||
Err(e) => match e.kind() {
|
||||
@ -100,6 +101,7 @@ fn bootstrap_server_connection(
|
||||
|
||||
let config_path = PathBuf::from(DEFAULT_CONFIG_PATH);
|
||||
if fs::metadata(&config_path).is_ok() {
|
||||
log::debug!("Starting server with default config at {:?}", config_path);
|
||||
return invoke_server_with_config(config_path);
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,9 @@ async fn socket_activate(config: ServerConfig) -> anyhow::Result<()> {
|
||||
let conn = get_socket_from_systemd().await?;
|
||||
let uid = conn.peer_cred()?.uid();
|
||||
let unix_user = UnixUser::from_uid(uid.into())?;
|
||||
|
||||
log::info!("Accepted connection from {}", unix_user.username);
|
||||
|
||||
handle_requests_for_single_session(conn, &unix_user, &config).await?;
|
||||
|
||||
Ok(())
|
||||
|
@ -83,6 +83,8 @@ pub fn read_config_from_path_with_arg_overrides(
|
||||
pub fn read_config_form_path(config_path: Option<PathBuf>) -> anyhow::Result<ServerConfig> {
|
||||
let config_path = config_path.unwrap_or_else(|| PathBuf::from(DEFAULT_CONFIG_PATH));
|
||||
|
||||
log::debug!("Reading config from {:?}", &config_path);
|
||||
|
||||
fs::read_to_string(&config_path)
|
||||
.context(format!(
|
||||
"Failed to read config file from {:?}",
|
||||
@ -99,6 +101,10 @@ pub fn read_config_form_path(config_path: Option<PathBuf>) -> anyhow::Result<Ser
|
||||
pub async fn create_mysql_connection_from_config(
|
||||
config: &MysqlConfig,
|
||||
) -> anyhow::Result<MySqlConnection> {
|
||||
let mut display_config = config.clone();
|
||||
display_config.password = "<REDACTED>".to_owned();
|
||||
log::debug!("Connecting to MySQL server with parameters: {:#?}", display_config);
|
||||
|
||||
match tokio::time::timeout(
|
||||
Duration::from_secs(config.timeout.unwrap_or(DEFAULT_TIMEOUT)),
|
||||
MySqlConnectOptions::new()
|
||||
|
@ -43,11 +43,12 @@ pub async fn listen_for_incoming_connections(
|
||||
|
||||
let parent_directory = socket_path.parent().unwrap();
|
||||
if !parent_directory.exists() {
|
||||
println!("Creating directory {:?}", parent_directory);
|
||||
log::debug!("Creating directory {:?}", parent_directory);
|
||||
fs::create_dir_all(parent_directory)?;
|
||||
}
|
||||
|
||||
println!("Listening on {:?}", socket_path);
|
||||
log::info!("Listening on socket {:?}", socket_path);
|
||||
|
||||
match fs::remove_file(socket_path.as_path()) {
|
||||
Ok(_) => {}
|
||||
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
|
||||
@ -68,6 +69,9 @@ pub async fn listen_for_incoming_connections(
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
log::info!("Accepted connection from {}", unix_user.username);
|
||||
|
||||
match handle_requests_for_single_session(conn, &unix_user, &config).await {
|
||||
Ok(_) => {}
|
||||
Err(e) => {
|
||||
@ -86,6 +90,7 @@ pub async fn handle_requests_for_single_session(
|
||||
) -> anyhow::Result<()> {
|
||||
let message_stream = create_server_to_client_message_stream(socket);
|
||||
let mut db_connection = create_mysql_connection_from_config(&config.mysql).await?;
|
||||
log::debug!("Successfully connected to database");
|
||||
|
||||
let result = handle_requests_for_single_session_with_db_connection(
|
||||
message_stream,
|
||||
@ -122,6 +127,8 @@ pub async fn handle_requests_for_single_session_with_db_connection(
|
||||
}
|
||||
};
|
||||
|
||||
log::trace!("Received request: {:?}", request);
|
||||
|
||||
match request {
|
||||
Request::CreateDatabases(databases_names) => {
|
||||
let result = create_databases(databases_names, unix_user, db_connection).await;
|
||||
|
Loading…
Reference in New Issue
Block a user