Skip to content

Commit dcf93be

Browse files
Reference current exe before starting updater and improve logging
1 parent 25061e7 commit dcf93be

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

client/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ pub async fn main() -> Result<()> {
755755
// spawn a task to watch for ctrl-c signals from user to trigger the shutdown
756756
spawn_in_span(shutdown.on_user_signal("User signaled shutdown".to_string()));
757757

758+
let current_exe = std::env::current_exe()?;
758759
let restart = Arc::new(Mutex::new(false));
759760
if let Err(error) = run(
760761
cfg,
@@ -774,8 +775,8 @@ pub async fn main() -> Result<()> {
774775
let reason = shutdown.completed_shutdown().await;
775776

776777
if *restart.lock().await {
777-
info!("Restarting Light Client...");
778-
utils::restart();
778+
info!("Restarting light client at {}", current_exe.display());
779+
utils::restart(current_exe);
779780
}
780781

781782
// we are not logging error here since expectation is

core/src/updater/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub async fn run(
223223
continue;
224224
}
225225
if started_at.elapsed() >= delay {
226-
info!("Updating the Avail Light Client...");
226+
info!("Updating light client...");
227227

228228
let asset = release.target_asset()?;
229229

@@ -254,24 +254,24 @@ pub async fn run(
254254
})
255255
.await?;
256256

257-
info!("Downloaded new version of the Avail Light Client");
257+
info!("Downloaded new version from {}", asset.url);
258258

259259
let asset_name = asset.target.bin_name();
260260

261261
// extract to current directory
262262
extract_archive(&archive_path, asset_name)?;
263263

264-
debug!("Extracted new version of the Avail Light Client: {asset_name}");
264+
info!("Extracted new version of {asset_name}");
265265

266266
let bin = current_dir.as_path().join(PathBuf::from(asset_name));
267267
self_replace::self_replace(bin)?;
268268

269-
debug!("Replaced new version of the Avail Light Client");
269+
info!("Replaced new version of the light client");
270270

271271
let mut restart = restart.lock().await;
272272
*restart = true;
273273

274-
let message = "Avail Light Client update is available, stopping...".to_string();
274+
let message = "Light client updated, stopping...".to_string();
275275
if let Err(error) = shutdown.trigger_shutdown(message) {
276276
error!("{error:#}");
277277
}

core/src/utils.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use color_eyre::{
1818
Result,
1919
};
2020
use futures::Future;
21+
#[cfg(not(target_arch = "wasm32"))]
22+
use std::path::PathBuf;
2123
use tokio::task::JoinHandle;
2224
#[cfg(target_arch = "wasm32")]
2325
use tokio_with_wasm::alias as tokio;
@@ -204,15 +206,15 @@ pub fn rng() -> rand::rngs::StdRng {
204206
}
205207

206208
#[cfg(not(target_arch = "wasm32"))]
207-
pub fn restart() {
208-
let current_exe = std::env::current_exe().unwrap();
209-
209+
pub fn restart(current_exe: PathBuf) {
210210
#[cfg(unix)]
211211
{
212212
use std::os::unix::process::CommandExt;
213-
_ = std::process::Command::new(current_exe)
213+
let error = std::process::Command::new(current_exe)
214214
.args(std::env::args().skip(1))
215215
.exec();
216+
error!("Restarting light client failed: {error}");
217+
std::process::exit(1);
216218
}
217219

218220
#[cfg(windows)]

0 commit comments

Comments
 (0)