Compare commits
No commits in common. "ce3dcdd4b1e49d64938e9154457cc8a8f96845e7" and "acb3cfd8e6c172a2f4201d051bd222e99e4c8130" have entirely different histories.
ce3dcdd4b1
...
acb3cfd8e6
|
|
@ -7,14 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased](https://git.rustybever.be/Chewing_Bever/alex/src/branch/dev)
|
## [Unreleased](https://git.rustybever.be/Chewing_Bever/alex/src/branch/dev)
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
* `--dry` flag to inspect command that will be run
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
* JVM flags now narrowely follow Aikar's specifications
|
|
||||||
|
|
||||||
## [0.2.0](https://git.rustybever.be/Chewing_Bever/alex/src/tag/0.2.0)
|
## [0.2.0](https://git.rustybever.be/Chewing_Bever/alex/src/tag/0.2.0)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ RUN cargo build && \
|
||||||
|
|
||||||
# We use ${:-} instead of a default value because the argument is always passed
|
# We use ${:-} instead of a default value because the argument is always passed
|
||||||
# to the build, it'll just be blank most likely
|
# to the build, it'll just be blank most likely
|
||||||
FROM eclipse-temurin:18-jre-alpine
|
FROM eclipse-temurin:17-jre-alpine
|
||||||
|
|
||||||
# Build arguments
|
# Build arguments
|
||||||
ARG MC_VERSION=1.19.4
|
ARG MC_VERSION=1.19.4
|
||||||
|
|
|
||||||
15
src/main.rs
15
src/main.rs
|
|
@ -66,11 +66,6 @@ struct Cli {
|
||||||
/// 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, env = "ALEX_FREQUENCY")]
|
#[arg(short = 't', long, default_value_t = 0, env = "ALEX_FREQUENCY")]
|
||||||
frequency: u64,
|
frequency: u64,
|
||||||
|
|
||||||
/// Don't actually run the server, but simply output the server configuration that would have
|
|
||||||
/// been ran
|
|
||||||
#[arg(short, long, default_value_t = false)]
|
|
||||||
dry: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn backups_thread(counter: Arc<Mutex<server::ServerProcess>>, frequency: u64) {
|
fn backups_thread(counter: Arc<Mutex<server::ServerProcess>>, frequency: u64) {
|
||||||
|
|
@ -90,7 +85,7 @@ fn main() -> io::Result<()> {
|
||||||
let (_, mut signals) = signals::install_signal_handlers()?;
|
let (_, mut signals) = signals::install_signal_handlers()?;
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
let mut cmd = server::ServerCommand::new(cli.type_, &cli.server_version)
|
let cmd = server::ServerCommand::new(cli.type_, &cli.server_version)
|
||||||
.java(&cli.java)
|
.java(&cli.java)
|
||||||
.jar(cli.jar)
|
.jar(cli.jar)
|
||||||
.config(cli.config)
|
.config(cli.config)
|
||||||
|
|
@ -99,14 +94,6 @@ fn main() -> io::Result<()> {
|
||||||
.xms(cli.xms)
|
.xms(cli.xms)
|
||||||
.xmx(cli.xmx)
|
.xmx(cli.xmx)
|
||||||
.max_backups(cli.max_backups);
|
.max_backups(cli.max_backups);
|
||||||
cmd.canonicalize()?;
|
|
||||||
|
|
||||||
if cli.dry {
|
|
||||||
print!("{}", cmd);
|
|
||||||
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let counter = Arc::new(Mutex::new(cmd.spawn()?));
|
let counter = Arc::new(Mutex::new(cmd.spawn()?));
|
||||||
|
|
||||||
if cli.frequency > 0 {
|
if cli.frequency > 0 {
|
||||||
|
|
|
||||||
|
|
@ -105,19 +105,14 @@ impl ServerCommand {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Canonicalize all paths to absolute paths. Without this command, all paths will be
|
pub fn spawn(self) -> std::io::Result<ServerProcess> {
|
||||||
/// interpreted relatively from the config directory.
|
|
||||||
pub fn canonicalize(&mut self) -> std::io::Result<()> {
|
|
||||||
// To avoid any issues, we use absolute paths for everything when spawning the process
|
// To avoid any issues, we use absolute paths for everything when spawning the process
|
||||||
self.jar = self.jar.canonicalize()?;
|
let jar = self.jar.canonicalize()?;
|
||||||
self.config_dir = self.config_dir.canonicalize()?;
|
let config_dir = self.config_dir.canonicalize()?;
|
||||||
self.world_dir = self.world_dir.canonicalize()?;
|
let world_dir = self.world_dir.canonicalize()?;
|
||||||
self.backup_dir = self.backup_dir.canonicalize()?;
|
let backup_dir = self.backup_dir.canonicalize()?;
|
||||||
|
|
||||||
Ok(())
|
self.accept_eula()?;
|
||||||
}
|
|
||||||
|
|
||||||
fn create_cmd(&self) -> std::process::Command {
|
|
||||||
let mut cmd = Command::new(&self.java);
|
let mut cmd = Command::new(&self.java);
|
||||||
|
|
||||||
// Apply JVM optimisation flags
|
// Apply JVM optimisation flags
|
||||||
|
|
@ -131,6 +126,15 @@ impl ServerCommand {
|
||||||
"-XX:+UnlockExperimentalVMOptions",
|
"-XX:+UnlockExperimentalVMOptions",
|
||||||
"-XX:+DisableExplicitGC",
|
"-XX:+DisableExplicitGC",
|
||||||
"-XX:+AlwaysPreTouch",
|
"-XX:+AlwaysPreTouch",
|
||||||
|
"-XX:G1HeapWastePercent=5",
|
||||||
|
"-XX:G1MixedGCCountTarget=4",
|
||||||
|
"-XX:G1MixedGCLiveThresholdPercent=90",
|
||||||
|
"-XX:G1RSetUpdatingPauseTimePercent=5",
|
||||||
|
"-XX:SurvivorRatio=32",
|
||||||
|
"-XX:+PerfDisableSharedMem",
|
||||||
|
"-XX:MaxTenuringThreshold=1",
|
||||||
|
"-Dusing.aikars.flags=https://mcflags.emc.gs",
|
||||||
|
"-Daikars.new.flags=true",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if self.xms > 12 * 1024 {
|
if self.xms > 12 * 1024 {
|
||||||
|
|
@ -139,84 +143,36 @@ impl ServerCommand {
|
||||||
"-XX:G1MaxNewSizePercent=50",
|
"-XX:G1MaxNewSizePercent=50",
|
||||||
"-XX:G1HeapRegionSize=16M",
|
"-XX:G1HeapRegionSize=16M",
|
||||||
"-XX:G1ReservePercent=15",
|
"-XX:G1ReservePercent=15",
|
||||||
|
"-XX:InitiatingHeapOccupancyPercent=20",
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
cmd.args([
|
cmd.args([
|
||||||
"-XX:G1NewSizePercent=30",
|
"-XX:G1NewSizePercent=30",
|
||||||
"-XX:G1MaxNewSizePercent=40",
|
"-XX:G1MaxNewSizePercent=40",
|
||||||
"-XX:G1HeapRegionSize=8M",
|
"-XX:G1HeapRegionSize=8M",
|
||||||
"-XX:G1ReservePercent=20",
|
"-XX:G1ReservePercent=15",
|
||||||
|
"-XX:InitiatingHeapOccupancyPercent=15",
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.args(["-XX:G1HeapWastePercent=5", "-XX:G1MixedGCCountTarget=4"]);
|
cmd.current_dir(&config_dir)
|
||||||
|
|
||||||
if self.xms > 12 * 1024 {
|
|
||||||
cmd.args(["-XX:InitiatingHeapOccupancyPercent=20"]);
|
|
||||||
} else {
|
|
||||||
cmd.args(["-XX:InitiatingHeapOccupancyPercent=15"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd.args([
|
|
||||||
"-XX:G1MixedGCLiveThresholdPercent=90",
|
|
||||||
"-XX:G1RSetUpdatingPauseTimePercent=5",
|
|
||||||
"-XX:SurvivorRatio=32",
|
|
||||||
"-XX:+PerfDisableSharedMem",
|
|
||||||
"-XX:MaxTenuringThreshold=1",
|
|
||||||
"-Dusing.aikars.flags=https://mcflags.emc.gs",
|
|
||||||
"-Daikars.new.flags=true",
|
|
||||||
]);
|
|
||||||
|
|
||||||
cmd.current_dir(&self.config_dir)
|
|
||||||
.arg("-jar")
|
.arg("-jar")
|
||||||
.arg(&self.jar)
|
.arg(&jar)
|
||||||
.arg("--universe")
|
.arg("--universe")
|
||||||
.arg(&self.world_dir)
|
.arg(&world_dir)
|
||||||
.arg("--nogui")
|
.arg("--nogui")
|
||||||
.stdin(Stdio::piped());
|
.stdin(Stdio::piped());
|
||||||
|
|
||||||
cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn spawn(&mut self) -> std::io::Result<ServerProcess> {
|
|
||||||
let mut cmd = self.create_cmd();
|
|
||||||
self.accept_eula()?;
|
|
||||||
let child = cmd.spawn()?;
|
let child = cmd.spawn()?;
|
||||||
|
|
||||||
Ok(ServerProcess::new(
|
Ok(ServerProcess::new(
|
||||||
self.type_,
|
self.type_,
|
||||||
self.version.clone(),
|
self.version,
|
||||||
self.config_dir.clone(),
|
config_dir,
|
||||||
self.world_dir.clone(),
|
world_dir,
|
||||||
self.backup_dir.clone(),
|
backup_dir,
|
||||||
self.max_backups,
|
self.max_backups,
|
||||||
child,
|
child,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ServerCommand {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
let cmd = self.create_cmd();
|
|
||||||
|
|
||||||
writeln!(f, "Command: {}", self.java)?;
|
|
||||||
writeln!(f, "Working dir: {}", self.config_dir.as_path().display())?;
|
|
||||||
|
|
||||||
// Print command env vars
|
|
||||||
writeln!(f, "Environment:")?;
|
|
||||||
|
|
||||||
for (key, val) in cmd.get_envs().filter(|(_, v)| v.is_some()) {
|
|
||||||
let val = val.unwrap();
|
|
||||||
writeln!(f, " {}={}", key.to_string_lossy(), val.to_string_lossy())?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print command arguments
|
|
||||||
writeln!(f, "Arguments:")?;
|
|
||||||
|
|
||||||
for arg in cmd.get_args() {
|
|
||||||
writeln!(f, " {}", arg.to_string_lossy())?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue