feat: add env vars for flags
ci/woodpecker/push/lint Pipeline was successful Details
ci/woodpecker/push/clippy Pipeline was successful Details
ci/woodpecker/push/build Pipeline was successful Details

signal-handling
Jef Roosens 2023-06-05 10:06:50 +02:00
parent f083d7e701
commit bef9698fc1
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 18 additions and 11 deletions

View File

@ -14,7 +14,7 @@ tar = "0.4.38"
flate2 = "1.0.26"
# Used for backup filenames
chrono = "0.4.26"
clap = { version = "4.3.1", features = ["derive"] }
clap = { version = "4.3.1", features = ["derive", "env"] }
[profile.release]
lto = "fat"

View File

@ -17,30 +17,30 @@ struct Cli {
jar: PathBuf,
/// Directory where configs are stored, and where the server will run [default: .]
#[arg(long, value_name = "CONFIG_DIR")]
#[arg(long, value_name = "CONFIG_DIR", env = "ALEX_CONFIG_DIR")]
config: Option<PathBuf>,
/// Directory where world files will be saved [default: ../worlds]
#[arg(long, value_name = "WORLD_DIR")]
#[arg(long, value_name = "WORLD_DIR", env = "ALEX_WORLD_DIR")]
world: Option<PathBuf>,
/// Directory where backups will be stored [default: ../backups]
#[arg(long, value_name = "BACKUP_DIR")]
#[arg(long, value_name = "BACKUP_DIR", env = "ALEX_WORLD_DIR")]
backup: Option<PathBuf>,
/// Java command to run the server jar with
#[arg(long, value_name = "JAVA_CMD", default_value_t = String::from("java"))]
#[arg(long, value_name = "JAVA_CMD", default_value_t = String::from("java"), env = "ALEX_JAVA")]
java: String,
/// XMS value in megabytes for the server instance
#[arg(long, default_value_t = 1024)]
#[arg(long, default_value_t = 1024, env = "ALEX_XMS")]
xms: u64,
/// XMX value in megabytes for the server instance
#[arg(long, default_value_t = 2048)]
#[arg(long, default_value_t = 2048, env = "ALEX_XMX")]
xmx: u64,
/// How many backups to keep
#[arg(short = 'n', long, default_value_t = 7)]
#[arg(short = 'n', long, default_value_t = 7, env = "ALEX_MAX_BACKUPS")]
max_backups: u64,
/// How frequently to perform a backup, in minutes; 0 to disable.
#[arg(short = 't', long, default_value_t = 0)]
#[arg(short = 't', long, default_value_t = 0, env = "ALEX_FREQUENCY")]
frequency: u64,
}
@ -50,7 +50,9 @@ fn backups_thread(counter: Arc<Mutex<server::ServerProcess>>, frequency: u64) {
{
let mut server = counter.lock().unwrap();
server.backup();
// We explicitely ignore the error here, as we don't want the thread to fail
let _ = server.backup();
}
}
}
@ -79,9 +81,14 @@ fn main() {
loop {
input.clear();
stdin.read_line(input);
if stdin.read_line(input).is_err() {
continue;
};
{
let mut server = counter.lock().unwrap();
if let Err(e) = server.send_command(input) {
println!("{}", e);
};