mirror of
https://github.com/mbround18/valheim-docker.git
synced 2021-10-22 21:53:54 +03:00
Removed generation of useless container and added wait for stop (#44)
This commit is contained in:
18
.run/docker-compose.yml_ Compose Deployment.run.xml
Normal file
18
.run/docker-compose.yml_ Compose Deployment.run.xml
Normal 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>
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 "$@"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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!")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user