fix: service mode error and fallback to sidecar

This commit is contained in:
GyDi 2022-11-22 20:46:46 +08:00
parent a355a9c85e
commit 5098f14aab
No known key found for this signature in database
GPG Key ID: B28E790B95193457

View File

@ -107,16 +107,18 @@ impl CoreManager {
if enable {
// 服务模式启动失败就直接运行sidecar
match {
log::debug!(target: "app", "try to run core in service mode");
log::debug!(target: "app", "try to run core in service mode");
match (|| async {
win_service::check_service().await?;
win_service::run_core_by_service(&config_path).await
} {
})()
.await
{
Ok(_) => return Ok(()),
Err(err) => {
// 修改这个值免得stop出错
*self.use_service_mode.lock() = false;
log::error!(target: "app", "{err}");
}
}
@ -141,7 +143,7 @@ impl CoreManager {
let (mut rx, cmd_child) = cmd.args(args).spawn()?;
// 将pid写入文件中
crate::log_err!({
crate::log_err!((|| {
let pid = cmd_child.pid();
let path = dirs::clash_pid_path()?;
fs::File::create(path)
@ -149,7 +151,7 @@ impl CoreManager {
.write(format!("{pid}").as_bytes())
.context("failed to write pid to the file")?;
<Result<()>>::Ok(())
});
})());
let mut sidecar = self.sidecar.lock();
*sidecar = Some(cmd_child);