Removed generation of useless container and added wait for stop (#44)

This commit is contained in:
Michael
2021-02-10 20:12:30 -07:00
committed by GitHub
parent e6516e3fe2
commit dcb45483b6
6 changed files with 43 additions and 10 deletions

View File

@@ -0,0 +1,18 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="docker-compose.yml: Compose Deployment" type="docker-deploy" factoryName="docker-compose.yml" server-name="Docker">
<deployment type="docker-compose.yml">
<settings>
<option name="removeVolumesOnComposeDown" value="true" />
<option name="commandLineOptions" value="--build" />
<option name="services">
<list>
<option value="odin" />
<option value="valheim" />
</list>
</option>
<option name="sourceFilePath" value="docker-compose.yml" />
</settings>
</deployment>
<method v="2" />
</configuration>
</component>

View File

@@ -24,8 +24,9 @@ RUN apt-get update \
&& apt-get install -y \
htop net-tools nano \
netcat curl wget \
cron sudo gosu \
&& gosu nobody true
cron sudo gosu dos2unix \
&& gosu nobody true \
&& dos2unix
# Set up timezone information
ENV TZ=America/Los_Angeles
@@ -47,8 +48,8 @@ ENV PUBLIC "1"
ENV PASSWORD "12345"
ENV AUTO_UPDATE "0"
COPY --from=ScriptSanitize --chmod=755 /data/scripts/*.sh /home/steam/scripts/
COPY --from=ScriptSanitize --chmod=755 /data/scripts/entrypoint.sh /entrypoint.sh
COPY --chmod=755 ./src/scripts/*.sh /home/steam/scripts/
COPY --chmod=755 ./src/scripts/entrypoint.sh /entrypoint.sh
COPY --from=RustBuilder --chmod=755 /data/odin/target/release /home/steam/.odin
#WORKDIR /home/steam/valheim

View File

@@ -1,4 +1,4 @@
use crate::utils::{get_working_dir, server_installed, send_shutdown};
use crate::utils::{get_working_dir, server_installed, send_shutdown, wait_for_server_exit};
use log::{info, error};
use clap::ArgMatches;
@@ -13,5 +13,6 @@ pub fn invoke(args: &ArgMatches) {
return;
}
send_shutdown();
wait_for_server_exit();
}
}

View File

@@ -48,6 +48,6 @@ chown -R ${STEAM_UID}:${STEAM_GID} /home/steam/valheim
log "Launching as steam..."
cd /home/steam/valheim || exit 1
trap 'exec goso steam cd /home/steam/valheim && odin stop' INT TERM EXIT
#trap 'exec goso steam cd /home/steam/valheim && odin stop' INT TERM
exec gosu steam "$@"

View File

@@ -44,23 +44,24 @@ log "Starting server..."
odin start || exit 1
trap 'cleanup' INT TERM EXIT
cleanup() {
log "Halting server! Received interrupt!"
if [[ -n $TAIL_PID ]];then
kill $TAIL_PID
fi
odin stop
exit
}
trap 'cleanup' INT TERM
initialize "
Valheim Server Started...
Keep an eye out for 'Game server connected' in the log!
(this indicates its online without any errors.)
" >> /home/steam/valheim/output.log
tail -f /home/steam/valheim/output.log &
export TAIL_PID=$!
wait $TAIL_PID

View File

@@ -39,7 +39,6 @@ pub fn server_installed() -> bool {
Path::new(&[get_working_dir(), "valheim_server.x86_64".to_string()].join("/")).exists()
}
pub fn send_shutdown() {
info!("Scanning for Valheim process");
let mut system = System::new();
@@ -58,3 +57,16 @@ pub fn send_shutdown() {
}
}
}
pub fn wait_for_server_exit() {
info!("Waiting for server to completely shutdown...");
let mut system = System::new();
loop {
system.refresh_all();
let processes = system.get_process_by_name("valheim_server.x86_64");
if processes.is_empty() {
break
}
}
info!("Server has been shutdown successfully!")
}