Compare commits
No commits in common. "a21219eaa5b889876b7435286b911877fabcd38b" and "a985279db38a7d3c10dca792fbf81e99d2537f85" have entirely different histories.
a21219eaa5
...
a985279db3
@ -1,7 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
set -Eeuo pipefail
|
||||
|
||||
cd blastmud-repo
|
||||
echo Running tests
|
||||
cargo test --target-dir ../target --profile release-with-debug
|
||||
cargo build --target-dir ../target --profile release-with-debug
|
@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
exec fly -t bm set-pipeline -c .concourse.yml -p blastmud-build
|
@ -11,14 +11,9 @@ jobs:
|
||||
type: registry-image
|
||||
source:
|
||||
repository: rust
|
||||
inputs:
|
||||
- name: blastmud-repo
|
||||
caches:
|
||||
- path: target
|
||||
outputs:
|
||||
- name: target
|
||||
run:
|
||||
path: blastmud-repo/.ci/build
|
||||
path: echo
|
||||
args: ["Hello", "world!"]
|
||||
resources:
|
||||
- name: blastmud-repo
|
||||
type: git
|
||||
@ -27,3 +22,4 @@ resources:
|
||||
source:
|
||||
uri: https://git.blastmud.org/blasthavers/blastmud.git
|
||||
branch: main
|
||||
|
||||
|
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -188,7 +188,6 @@ dependencies = [
|
||||
"blastmud_interfaces",
|
||||
"futures",
|
||||
"log",
|
||||
"nix",
|
||||
"once_cell",
|
||||
"rand",
|
||||
"serde",
|
||||
@ -1039,9 +1038,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.26.2"
|
||||
version = "0.26.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a"
|
||||
checksum = "46a58d1d356c6597d08cde02c2f09d785b09e28711837b1ed667dc652c08a694"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
|
@ -9,7 +9,6 @@ edition = "2021"
|
||||
blastmud_interfaces = { path = "../blastmud_interfaces" }
|
||||
futures = "0.3.25"
|
||||
log = "0.4.17"
|
||||
nix = "0.26.2"
|
||||
once_cell = "1.17.0"
|
||||
rand = "0.8.5"
|
||||
serde = { version = "1.0.149", features = ["derive", "serde_derive"] }
|
||||
|
@ -1,5 +1,4 @@
|
||||
use std::vec::Vec;
|
||||
use std::path::Path;
|
||||
use std::collections::BTreeMap;
|
||||
use std::error::Error;
|
||||
use std::net::SocketAddr;
|
||||
@ -25,14 +24,12 @@ use warp::{
|
||||
self, filters::ws, Filter, Reply
|
||||
};
|
||||
use std::time::Instant;
|
||||
use nix::{sys::signal::{kill, Signal}, unistd::Pid};
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
struct Config {
|
||||
listeners: Vec<String>,
|
||||
ws_listener: String,
|
||||
gameserver: String,
|
||||
pidfile: String,
|
||||
}
|
||||
|
||||
type DResult<A> = Result<A, Box<dyn Error + Send + Sync>>;
|
||||
@ -640,51 +637,14 @@ async fn start_websocket(bind: String, active_sessions: SessionMap, server_sende
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn replace_old_listener(pidfile: &str) -> DResult<()> {
|
||||
match fs::read_to_string(pidfile) {
|
||||
Err(e) =>
|
||||
if e.kind() == std::io::ErrorKind::NotFound {
|
||||
info!("pidfile not found, assuming not already running");
|
||||
Ok(())
|
||||
} else {
|
||||
info!("Error reading pidfile (other than NotFound): {}", e);
|
||||
Err(Box::new(e) as Box::<dyn Error + Send + Sync>)
|
||||
}
|
||||
Ok(f) => {
|
||||
let pid: Pid = Pid::from_raw(f.parse().map_err(|e| Box::new(e) as Box::<dyn Error + Send + Sync>)?);
|
||||
match fs::read_to_string(format!("/proc/{}/cmdline", pid)) {
|
||||
Ok(content) =>
|
||||
if content.contains("blastmud_listener") {
|
||||
info!("pid in pidfile references blastmud_listener; starting cutover");
|
||||
kill(pid, Signal::SIGTERM)
|
||||
.map_err(|e| Box::new(e) as Box<dyn Error + Send + Sync>)
|
||||
} else {
|
||||
info!("Pid in pidfile is for process not including blastmud_listener - ignoring pidfile");
|
||||
Ok(())
|
||||
}
|
||||
Err(_) => {
|
||||
info!("Pid in pidfile is gone - ignoring pidfile");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}?;
|
||||
info!("Writing new pidfile");
|
||||
fs::write(Path::new(pidfile), format!("{}", std::process::id()))
|
||||
.map_err(|e| Box::new(e) as Box::<dyn Error + Send + Sync>)
|
||||
}
|
||||
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
SimpleLogger::new().with_level(LevelFilter::Info).init().unwrap();
|
||||
|
||||
|
||||
let listener_id = Uuid::new_v4();
|
||||
let mut config = read_latest_config()?;
|
||||
let active_sessions: SessionMap =
|
||||
Arc::new(Mutex::new(SessionIndexes { by_uuid: BTreeMap::new(), count_by_source: BTreeMap::new() }));
|
||||
replace_old_listener(&config.pidfile)?;
|
||||
let server_sender = start_server_task(listener_id, config.gameserver, active_sessions.clone());
|
||||
|
||||
start_pinger(listener_id, server_sender.clone());
|
||||
|
@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Note: This script runs /app/exe/* at startup, and then any files moved into /app/exe/
|
||||
# (note - create files elsewhere and move them to avoid race conditions).
|
||||
# This allows deployments to work from a different Docker container by simply pushing
|
||||
# into a volume mounted in the correct place.
|
||||
# Remove the old file from /app/exe/ before moving the new one.
|
||||
# It doesn't kill off the old process, instead the new one kills the old one.
|
||||
|
||||
for EXE in /app/exe/*; do
|
||||
"$EXE"&
|
||||
done
|
||||
|
||||
inotifywait --quiet --monitor -e moved_to --format "%f" /app/exe |\
|
||||
while read MOVED
|
||||
do
|
||||
"/app/exe/$MOVED"&
|
||||
done
|
Loading…
Reference in New Issue
Block a user