Skip to content

Commit ccc0421

Browse files
committed
supervisor: Auto setulimit
1 parent 9cb4c6c commit ccc0421

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

supervisor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fs-err.workspace = true
1414
git-version.workspace = true
1515
libc.workspace = true
1616
load_config.workspace = true
17+
nix.workspace = true
1718
notify.workspace = true
1819
rocket = { workspace = true, features = ["json"] }
1920
serde = { workspace = true, features = ["derive"] }

supervisor/src/main.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,23 @@ struct Args {
5858
log_file: Option<String>,
5959
}
6060

61+
#[cfg(unix)]
62+
fn set_max_ulimit() -> Result<()> {
63+
use nix::sys::resource::{getrlimit, setrlimit, Resource};
64+
let (soft, hard) = getrlimit(Resource::RLIMIT_NOFILE)?;
65+
if soft < hard {
66+
setrlimit(Resource::RLIMIT_NOFILE, hard, hard)?;
67+
}
68+
Ok(())
69+
}
70+
6171
fn main() -> Result<()> {
72+
// Set max ulimit for file descriptors
73+
#[cfg(unix)]
74+
if let Err(err) = set_max_ulimit() {
75+
error!("Failed to set max ulimit: {err:?}");
76+
}
77+
6278
let args = Args::parse();
6379
if let Some(log_file) = &args.log_file {
6480
mk_parents(log_file)?;

0 commit comments

Comments
 (0)