This function initializes the HQ server. It takes a path to a directory and tries to find metadata of a running HQ server either directly inside the directory or in a path linked to by a symlink named [`SYMLINK_PATH`]. If no metadata is found or the metadata links to a server that seems to be offline, a new server will be started. If an already running server is found, an error will be returned
(
gsettings: &GlobalSettings,
server_cfg: ServerConfig,
)
| 60 | /// |
| 61 | /// If an already running server is found, an error will be returned. |
| 62 | pub async fn init_hq_server( |
| 63 | gsettings: &GlobalSettings, |
| 64 | server_cfg: ServerConfig, |
| 65 | ) -> anyhow::Result<()> { |
| 66 | match get_server_status(gsettings.server_directory()).await { |
| 67 | Err(_) | Ok(ServerStatus::Offline) => { |
| 68 | log::info!("No online server found, starting a new server"); |
| 69 | start_server(gsettings, server_cfg).await |
| 70 | } |
| 71 | Ok(ServerStatus::Online) => anyhow::bail!( |
| 72 | "Server at {0} is already online, please stop it first using \ |
| 73 | `hq server stop --server-dir {0}`", |
| 74 | gsettings.server_directory().display() |
| 75 | ), |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | pub async fn get_client_session(server_directory: &Path) -> anyhow::Result<ClientSession> { |
| 80 | let default_home = default_server_directory(); |
no test coverage detected