Skip to content

Commit 49223d4

Browse files
committed
Make CLI daemonize itself (by default)
1 parent bbfced4 commit 49223d4

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

Cargo.lock

+35-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ anyhow = "1.0.75"
88
argh = "0.1.12"
99
cookie-monster = { path = "../cookie-monster" }
1010
cookie_store = "^0.19"
11+
daemonize-me = "2.0.1"
1112
etcetera = "0.8.0"
1213
fs = { path = "../fs" }
1314
fuser = "0.13.0"

cli/src/main.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};
44

55
use argh::FromArgs;
66
use cookie_store::{Cookie, CookieStore};
7+
use daemonize_me::Daemon;
78
use etcetera::BaseStrategy;
89
use fuser::MountOption;
910
use url::Url;
@@ -14,13 +15,16 @@ use lib_bb::client::BBAPIClient;
1415
#[derive(FromArgs)]
1516
/// A CLI tool to authenticate to and mount BlackboardFS
1617
struct BbfsCli {
18+
#[argh(switch, short = 'm')]
19+
monitor: bool,
1720
/// the path to mount the Blackboard filesystem at
1821
#[argh(positional)]
1922
mount_point: PathBuf,
2023
}
2124

2225
fn main() -> anyhow::Result<()> {
2326
let args: BbfsCli = argh::from_env();
27+
let mount_point = args.mount_point.canonicalize().unwrap();
2428

2529
let strategy = etcetera::choose_base_strategy().unwrap();
2630
let data_dir = {
@@ -31,16 +35,24 @@ fn main() -> anyhow::Result<()> {
3135
};
3236

3337
let cookie_file = data_dir.join("cookie");
38+
let stdout =
39+
File::create(data_dir.join("stdout.log")).expect("failed to create stdout log file");
40+
let stderr =
41+
File::create(data_dir.join("stderr.log")).expect("failed to create stderr log file");
3442

3543
let bb_url = Url::parse("https://learn.uq.edu.au/").unwrap();
3644

3745
let cookies = find_cookies(&cookie_file, &bb_url).unwrap();
3846

47+
if !args.monitor {
48+
Daemon::new().stdout(stdout).stderr(stderr).start().unwrap();
49+
}
50+
3951
let client = BBAPIClient::new(cookies);
4052
fuser::mount2(
4153
BBFS::new(client),
42-
&args.mount_point,
43-
&[MountOption::AutoUnmount],
54+
mount_point,
55+
&[MountOption::AutoUnmount, MountOption::RO],
4456
)
4557
.unwrap();
4658
Ok(())

static/banner.png

189 KB
Loading

static/banner.png.kra

683 KB
Binary file not shown.

0 commit comments

Comments
 (0)