mirror of
https://codeberg.org/spire/dispenser.git
synced 2026-06-03 18:14:06 +02:00
take existing server if more cases
This commit is contained in:
parent
7744e93533
commit
cdb8452cb6
1 changed files with 15 additions and 10 deletions
25
src/main.rs
25
src/main.rs
|
|
@ -34,7 +34,7 @@ pub enum Error {
|
||||||
#[error("Error while updating dyndns: {0}")]
|
#[error("Error while updating dyndns: {0}")]
|
||||||
DynDns(#[from] DynDnsError),
|
DynDns(#[from] DynDnsError),
|
||||||
#[error("Already running")]
|
#[error("Already running")]
|
||||||
AlreadyRunning,
|
AlreadyRunning(Server),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
Schedule(#[from] cron::error::Error),
|
Schedule(#[from] cron::error::Error),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
|
|
@ -70,12 +70,8 @@ async fn setup(ssh: &mut SshSession, config: &ServerConfig) -> Result<(), Error>
|
||||||
tv_name = config.tv_name,
|
tv_name = config.tv_name,
|
||||||
password = config.password,
|
password = config.password,
|
||||||
rcon = config.rcon,
|
rcon = config.rcon,
|
||||||
demostf = config
|
demostf = config.demostf_key.as_deref().unwrap_or_default(),
|
||||||
.demostf_key.as_deref()
|
logstf = config.logstf_key.as_deref().unwrap_or_default(),
|
||||||
.unwrap_or_default(),
|
|
||||||
logstf = config
|
|
||||||
.logstf_key.as_deref()
|
|
||||||
.unwrap_or_default(),
|
|
||||||
league = config.config_league,
|
league = config.config_league,
|
||||||
mode = config.config_mode,
|
mode = config.config_mode,
|
||||||
image = config.image
|
image = config.image
|
||||||
|
|
@ -141,6 +137,9 @@ async fn run_loop(
|
||||||
println!("Starting server");
|
println!("Starting server");
|
||||||
match start(cloud.as_ref(), &config).await {
|
match start(cloud.as_ref(), &config).await {
|
||||||
Ok(server) => active_server = Some(server),
|
Ok(server) => active_server = Some(server),
|
||||||
|
Err(Error::AlreadyRunning(server)) if config.server.manage_existing => {
|
||||||
|
active_server = Some(server);
|
||||||
|
}
|
||||||
Err(e) => eprintln!("{:#}", e),
|
Err(e) => eprintln!("{:#}", e),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -188,9 +187,15 @@ async fn run_loop(
|
||||||
|
|
||||||
async fn start(cloud: &dyn Cloud, config: &Config) -> Result<Server, Error> {
|
async fn start(cloud: &dyn Cloud, config: &Config) -> Result<Server, Error> {
|
||||||
let list = cloud.list().await?;
|
let list = cloud.list().await?;
|
||||||
if !list.is_empty() {
|
let count = list.len();
|
||||||
eprintln!("Non empty server list while starting: {:?}", list);
|
let first = list.into_iter().next();
|
||||||
return Err(Error::AlreadyRunning);
|
if let Some(first) = first {
|
||||||
|
eprintln!(
|
||||||
|
"Non empty server list while starting: {:?}, and {} more",
|
||||||
|
first,
|
||||||
|
count - 1
|
||||||
|
);
|
||||||
|
return Err(Error::AlreadyRunning(first));
|
||||||
}
|
}
|
||||||
|
|
||||||
let ssh_key = if let Some(key) = config.server.ssh_key.as_ref() {
|
let ssh_key = if let Some(key) = config.server.ssh_key.as_ref() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue