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" flate2 = "1.0.26"
# Used for backup filenames # Used for backup filenames
chrono = "0.4.26" chrono = "0.4.26"
clap = { version = "4.3.1", features = ["derive"] } clap = { version = "4.3.1", features = ["derive", "env"] }
[profile.release] [profile.release]
lto = "fat" lto = "fat"

View File

@ -17,30 +17,30 @@ struct Cli {
jar: PathBuf, jar: PathBuf,
/// Directory where configs are stored, and where the server will run [default: .] /// 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>, config: Option<PathBuf>,
/// Directory where world files will be saved [default: ../worlds] /// 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>, world: Option<PathBuf>,
/// Directory where backups will be stored [default: ../backups] /// 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>, backup: Option<PathBuf>,
/// Java command to run the server jar with /// 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, java: String,
/// XMS value in megabytes for the server instance /// 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, xms: u64,
/// XMX value in megabytes for the server instance /// 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, xmx: u64,
/// How many backups to keep /// 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, max_backups: u64,
/// How frequently to perform a backup, in minutes; 0 to disable. /// 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, frequency: u64,
} }
@ -50,7 +50,9 @@ fn backups_thread(counter: Arc<Mutex<server::ServerProcess>>, frequency: u64) {
{ {
let mut server = counter.lock().unwrap(); 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 { loop {
input.clear(); input.clear();
stdin.read_line(input);
if stdin.read_line(input).is_err() {
continue;
};
{ {
let mut server = counter.lock().unwrap(); let mut server = counter.lock().unwrap();
if let Err(e) = server.send_command(input) { if let Err(e) = server.send_command(input) {
println!("{}", e); println!("{}", e);
}; };