Skip to content

Commit 5ed6576

Browse files
committed
feat: Daemon variable to differentiate cli and service
1 parent c269c9d commit 5ed6576

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

debian/firesquid.service

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ExecStart=/usr/bin/firesquid
77
Restart=always
88
PrivateTmp=true
99
NoNewPrivileges=true
10+
Environment="DAEMON=1"
1011

1112
[Install]
1213
Alias=firesquid

src/main.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,27 @@ use crate::cli::generate_cli;
1919
use crate::state::{State, StatePtr};
2020

2121
use std::fs;
22-
use std::path;
2322

2423
#[tokio::main]
2524
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
26-
if env::var("RUST_LOG").is_err() {
25+
if env::var_os("RUST_LOG").is_none() {
2726
env::set_var("RUST_LOG", "info");
2827
}
2928

3029
tracing_subscriber::fmt::init();
3130

32-
//TODO: better way of finding out if it's being run by system
33-
if !path::Path::new("/tmp/firesquid/lock.pid").exists() {
34-
start_daemon().await?;
31+
if env::var_os("DAEMON").is_none() {
32+
println!("cli goes here");
3533
return Ok(());
3634
}
3735

38-
println!("CLI GOES HERE");
36+
start_daemon().await?;
3937

4038
Ok(())
4139
}
4240

4341
async fn start_daemon() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
44-
info!("Creating lock file");
4542
fs::create_dir("/tmp/firesquid").ok();
46-
fs::File::create("/tmp/firesquid/lock.pid").ok();
4743

4844
let cli_options = match generate_cli() {
4945
Ok(options) => options,
@@ -94,9 +90,6 @@ async fn start_daemon() -> Result<(), Box<dyn std::error::Error + Send + Sync>>
9490

9591
terminate_all_vms(state_ptr).await;
9692

97-
info!("Removing lock file");
98-
fs::remove_file("/tmp/firesquid/lock.pid").ok();
99-
10093
Ok(())
10194
}
10295

0 commit comments

Comments
 (0)