(
endpoint: &ServerEndpoint,
config_template: &str,
config_subdir: &str,
publish_dir: &str,
env: EnvConfig,
result_tx: mpsc::Sender<Message>,
)
| 160 | } |
| 161 | |
| 162 | pub async fn start_httpd( |
| 163 | endpoint: &ServerEndpoint, |
| 164 | config_template: &str, |
| 165 | config_subdir: &str, |
| 166 | publish_dir: &str, |
| 167 | env: EnvConfig, |
| 168 | result_tx: mpsc::Sender<Message>, |
| 169 | ) -> Result<SubProcess> { |
| 170 | let httpd_dir = get_cache_dir(&env.httpd_dir)?; |
| 171 | let configs_dir = get_cache_dir(config_subdir)?; |
| 172 | |
| 173 | let mut httpd_cfg = configs_dir.clone(); |
| 174 | httpd_cfg.push(format!("{}.conf", endpoint.guid)); |
| 175 | |
| 176 | let mut pid_file = configs_dir.clone(); |
| 177 | pid_file.push(format!("{}.pid", endpoint.guid)); |
| 178 | |
| 179 | let mut lock_file = configs_dir.clone(); |
| 180 | lock_file.push(format!("{}.lock", endpoint.guid)); |
| 181 | |
| 182 | // Kill any existing httpd process before starting a new one |
| 183 | #[cfg(unix)] |
| 184 | kill_by_pid_file(&pid_file); |
| 185 | |
| 186 | let port = find_free_tcp_port() |
| 187 | .await |
| 188 | .context(t!("error-finding-free-port"))?; |
| 189 | |
| 190 | let httpd_config = config_template.replace("[[PUBLISH_DIR]]", publish_dir); |
| 191 | let httpd_config = httpd_config.replace("[[SRVROOT]]", httpd_dir.to_str().unwrap()); |
| 192 | let httpd_config = httpd_config.replace("[[PORT]]", &port.to_string()); |
| 193 | let httpd_config = httpd_config.replace("[[PID_FILE]]", pid_file.to_str().unwrap()); |
| 194 | let httpd_config = httpd_config.replace("[[LOCK_FILE]]", lock_file.to_str().unwrap()); |
| 195 | |
| 196 | #[cfg(unix)] |
| 197 | let httpd_config = httpd_config.replace("[[IS_LINUX]]", ""); |
| 198 | |
| 199 | #[cfg(not(unix))] |
| 200 | let httpd_config = httpd_config.replace("[[IS_LINUX]]", "#"); |
| 201 | |
| 202 | std::fs::write(&httpd_cfg, httpd_config).context(crate::t!("error-writing-httpd-conf"))?; |
| 203 | |
| 204 | let httpd_cfg = httpd_cfg.to_str().unwrap().to_string(); |
| 205 | let httpd_exe = httpd_dir.join("bin").join(HTTPD_EXE); |
| 206 | |
| 207 | #[allow(unused_mut)] |
| 208 | let mut envs = HashMap::<String, String>::new(); |
| 209 | |
| 210 | #[cfg(target_os = "macos")] |
| 211 | envs.insert( |
| 212 | "DYLD_LIBRARY_PATH".to_string(), |
| 213 | httpd_dir.join("lib").to_str().unwrap().to_string(), |
| 214 | ); |
| 215 | |
| 216 | #[cfg(target_os = "linux")] |
| 217 | envs.insert( |
| 218 | "LD_LIBRARY_PATH".to_string(), |
| 219 | httpd_dir.join("lib").to_str().unwrap().to_string(), |
no test coverage detected