Refactor to use only one volume, one for the entire contents of the user's home directory. This simplifies a lot.

Make all bash changes to the dayzserver script instead of creating a wrapper.
Handle the server config and Battle Eye string substitution.
Add the default.cfg from upstream and handle it locally.
This commit is contained in:
Daniel Ceregatti 2022-03-25 23:17:55 -07:00
parent 3c91314b49
commit b141d2b0da
9 changed files with 139 additions and 84 deletions

2
.dockerignore Normal file
View file

@ -0,0 +1,2 @@
**
!files

View file

@ -37,24 +37,8 @@ ENV LC_ALL en_US.UTF-8
RUN groupadd user && \
useradd -l -m -g user user
# Add the server script.
# From https://steamcommunity.com/sharedfiles/filedetails/?id=1517338673
ADD dayzserver /home/user
# Add the serverDZ.cfg from the same URL as above
ADD serverDZ.cfg /home/user
# Add our wrapper too
ADD server.sh /home/user
# Make sure the volumes can be written to by the local user
RUN cd /home/user && \
mkdir -p serverfiles serverprofile Steam steamcmd
# Create the files the dayzserver script expects so we can take charge of populating them
RUN cd /home/user && touch .steamlogin
RUN cd /home/user && chown user:user /home/user -R
# The volume needs to be owned by the user
RUN cd /home/user; rm -rf *; rm -rf .*; chown user:user /home/user -R
# Use our non-privileged user
USER user
@ -63,4 +47,4 @@ USER user
WORKDIR /home/user
# Run the server.
CMD ["./server.sh"]
CMD ["/files/dayzserver", "start"]

View file

@ -2,10 +2,10 @@
A Linux DayZ server in a Docker container.
Edit docker-compose.yml and set the variables:
Edit docker-compose.yml and set the server name:
```
- SERVERNAME="DayZ on Linux for Linux"
- SERVERNAME=DayZ on Linux
```
Build the container, run it, tail the logs:
```

View file

@ -1,10 +1,7 @@
version: "3.3"
volumes:
steam:
steamcmd:
serverfiles:
serverprofile:
homedir:
services:
@ -14,10 +11,10 @@ services:
- "2302:2302/udp"
- "27016:27016/udp"
volumes:
- steam:/home/user/Steam
- steamcmd:/home/user/steamcmd
- serverfiles:/home/user/serverfiles
- serverprofile:/home/user/serverprofile
- homedir:/home/user
- ./files:/files
environment:
# Escape any forwardslashes: SERVERNAME="My thing \/ My other thing"
# Don't use double quotes. Escape any forward slashes: SERVERNAME=My thing \/ My other thing
- SERVERNAME=DayZ on Linux for Linux
# Set your own RCON password. Otherwise, a random one will be generated and shown in the log on the first run.
# - RCON_PASSWORD=H4CKM3

3
files/beserver_x64.cfg Normal file
View file

@ -0,0 +1,3 @@
RConPassword RCON_PASSWORD
RestrictRCon 1
RConPort 2302

View file

@ -36,34 +36,70 @@ fn_checkroot_dayz(){
}
fn_loadconfig_dayz(){
# default config
if [ ! -f "${HOME}/.default.cfg" ]; then
wget -P ${HOME}/ -qN https://raw.githubusercontent.com/thelastnoc/dayz-sa_linuxserver/master/script/.default.cfg
fi
source ${HOME}/.default.cfg
cp serverDZ.cfg "${HOME}/serverfiles/serverDZ.cfg"
sed -i "${HOME}/serverfiles/serverDZ.cfg" -e "s/EXAMPLE NAME/${SERVERNAME}/"
# battleye config and rconpassword setup
if [ ! -f "${HOME}/serverfiles/battleye/beserver_x64.cfg" ]; then
wget -P ${HOME}/serverfiles/battleye/ -qN https://raw.githubusercontent.com/thelastnoc/dayz-sa_linuxserver/master/script/beserver_x64.cfg
passwd=$(openssl rand -base64 8 | tr -dc 'A-Za-z0-9')
if [ "${passwd}" == "" ]; then
passwd=$(< /dev/urandom tr -dc 'A-Za-z0-9' | head -c10)
fi
if [ "${passwd}" == "" ]; then
printf "[ ${red}FAIL${default} ] Could not generate a passwort for RCON!\nOpen the Battleye config with './dayzserver cfg' and enter '3' to open it."
exit 1
else
sed -i "/RConPassword/ s/CHANGEME/${passwd}/" "${HOME}/serverfiles/battleye/beserver_x64.cfg"
printf "[ ${cyan}INFO${default} ] ${yellow}New "
grep RConPassword ${HOME}/serverfiles/battleye/beserver_x64.cfg
printf "${default}"
fi
fi
# workshop
if [ ! -f "${HOME}/.workshop.cfg" ]; then
wget -P ${HOME}/ -qN https://raw.githubusercontent.com/thelastnoc/dayz-sa_linuxserver/master/script/.workshop.cfg
source /files/default.cfg
# Handle adding the server name from the environment to the serverFZ.cfg file.
if [ ! -f ${HOME}/serverfiles/serverDZ.cfg ]
then
cp /files/serverDZ.cfg "${HOME}/serverfiles/serverDZ.cfg"
sed -i "${HOME}/serverfiles/serverDZ.cfg" -e "s/SERVER_NAME/${SERVER_NAME}/"
fi
# Set a random RCON password, unless one's set in the environment
if [ ! -f "${HOME}/serverfiles/battleye/beserver_x64.cfg" ]
then
echo -n "Creating Battle Eye RCON file "
cp /files/beserver_x64.cfg "${HOME}/serverfiles/battleye/beserver_x64.cfg"
if [[ ${RCON_PASSWORD} != "" ]]
then
echo "using the RCON_PASSWORD in the environment."
else
RCON_PASSWORD=$(< /dev/urandom tr -dc 'A-Za-z0-9' | head -c10)
echo -e "using random RCON password ${yellow}${RCON_PASSWORD}"
fi
sed -i "${HOME}/serverfiles/battleye/beserver_x64.cfg" -e "s/RCON_PASSWORD/${RCON_PASSWORD}/"
fi
# # default config
# if [ ! -f "${HOME}/.default.cfg" ]; then
# wget -P ${HOME}/ -qN https://raw.githubusercontent.com/thelastnoc/dayz-sa_linuxserver/master/script/.default.cfg
# fi
# source ${HOME}/.default.cfg
# # script config
# if [ ! -f "${HOME}/.dayzserver.cfg" ] || [ "$(grep dayzparameter ${HOME}/.dayzserver.cfg)" == "" ]; then
# cp ${HOME}/.default.cfg ${HOME}/.dayzserver.cfg
# fi
# source ${HOME}/.dayzserver.cfg
# hostname/servername
# if [ ! -f "${HOME}/serverfiles/serverDZ.cfg" ]; then
# wget -P ${HOME}/serverfiles/ -q https://raw.githubusercontent.com/thelastnoc/dayz-sa_linuxserver/master/script/serverDZ.cfg
# fi
# defaultservername=$(grep -rwi ${HOME}/serverfiles/serverDZ.cfg -e 'EXAMPLE NAME')
# if [ "${defaultservername}" != "" ]; then
# printf "[ ${magenta}SERVER${default} ] Servername is set on default! 'EXAMPLE NAME'\n\n"
# read -p "Enter a new Servername: " servername
# sed -i "/hostname/ s/EXAMPLE NAME/${servername}/" "${HOME}/serverfiles/serverDZ.cfg"
# fi
# # battleye config and rconpassword setup
# if [ ! -f "${HOME}/serverfiles/battleye/beserver_x64.cfg" ]; then
# wget -P ${HOME}/serverfiles/battleye/ -qN https://raw.githubusercontent.com/thelastnoc/dayz-sa_linuxserver/master/script/beserver_x64.cfg
# passwd=$(openssl rand -base64 8 | tr -dc 'A-Za-z0-9')
# if [ "${passwd}" == "" ]; then
# passwd=$(< /dev/urandom tr -dc 'A-Za-z0-9' | head -c10)
# fi
# if [ "${passwd}" == "" ]; then
# printf "[ ${red}FAIL${default} ] Could not generate a passwort for RCON!\nOpen the Battleye config with './dayzserver cfg' and enter '3' to open it."
# exit 1
# else
# sed -i "/RConPassword/ s/CHANGEME/${passwd}/" "${HOME}/serverfiles/battleye/beserver_x64.cfg"
# printf "[ ${cyan}INFO${default} ] ${yellow}New "
# grep RConPassword ${HOME}/serverfiles/battleye/beserver_x64.cfg
# printf "${default}"
# fi
# fi
# # workshop
# if [ ! -f "${HOME}/.workshop.cfg" ]; then
# wget -P ${HOME}/ -qN https://raw.githubusercontent.com/thelastnoc/dayz-sa_linuxserver/master/script/.workshop.cfg
# fi
}
fn_status_dayz(){
@ -77,11 +113,23 @@ fn_start_dayz(){
# exit 1
# else
printf "[ ${green}DayZ${default} ] Starting server...\n"
sleep 0.5
# sleep 0.5
fn_loadconfig_dayz
sleep 0.5
# sleep 0.5
cd ${HOME}/serverfiles
exec ./DayZServer $dayzparameter "$workshop"
./DayZServer $dayzparameter "$workshop" || (
echo
echo -e "${yellow}========================================== error.log =========================================="
find /home/user -name error.log -exec cat {} \; -exec rm -f {} \;
echo
echo -e "${yellow}========================================== script*.log ========================================"
find /home/user -name "script*.log" -exec cat {} \; -exec rm -f {} \;
echo
echo -e "${yellow}========================================== *.RPT =============================================="
find /home/user -name "*.RPT" -exec cat {} \; -exec rm -f {} \;
echo
echo -e "${yellow}========================================== End crash log ======================================"
)
# tmux new-session -d -x 23 -y 80 -s $(whoami)-tmux ./DayZServer $dayzparameter "$workshop"
# sleep 1
# cd ${HOME}
@ -421,17 +469,29 @@ fn_opt_usage(){
exit 1
}
# Make sure we don't start collecting core files
ulimit -c 0
# start functions
fn_checkroot_dayz
#fn_checktmux
#fn_checkscreen
# Use an anonymous login for the server files
if [ ! -f ${HOME}/.steamlogin ]
then
echo "steamlogin=anonymous" > ${HOME}/.steamlogin
fi
getopt=$1
if [ ! -f "${HOME}/steamcmd/steamcmd.sh" ] || [ ! -f "${HOME}/serverfiles/DayZServer" ] && [ "${getopt}" != "cfg" ]; then
printf "[ ${yellow}INFO${default} ] No installed steamcmd and/or serverfiles found!\n"
chmod u+x ${HOME}/dayzserver
# chmod u+x ${HOME}/dayzserver
fn_install_dayz
if [ -f "${HOME}/steamcmd/steamcmd.sh" ] && [ -f "${HOME}/serverfiles/DayZServer" ]; then
fn_opt_usage
exec fn_start_dayz
fi
echo "Something failed? Shouldn't make it here..."
exit
else
### Check if user commands exist and run corresponding scripts, or display script usage

30
files/default.cfg Normal file
View file

@ -0,0 +1,30 @@
######################################
# dayzserver config file #
# the parameter have to be within "" #
# otherwise the server wont start! #
############################################################################
# https://forums.dayz.com/topic/239635-dayz-server-files-documentation/
# launch parameters documentation
#############################################################################
# DayZ SteamID
appid=1042420
dayz_id=221100
#stable=223350
#exp_branch=1042420
# IMPORTANT PARAMETERS - DO NOT REMOVE!
config=serverDZ.cfg
port=2302
# DayZ Mods from Steam Workshop
# to enable mods, remove the # below and list the Mods like this: "-mod=@Mod1;@Mod2;@Mod3"
#workshop="-mod="
# optional - just remove the # to enable
BEpath="-BEpath=${HOME}/serverfiles/battleye/"
profiles="-profiles=${HOME}/serverprofile/"
#logs="-dologs -adminlog -netlog"
# modify carefully! server won't start if syntax is corrupt!
dayzparameter=" -config=${config} -port=${port} -freezecheck ${BEpath} ${profiles} ${logs}"

View file

@ -1,4 +1,4 @@
hostname = "EXAMPLE NAME"; // Server name
hostname = "SERVER_NAME"; // Server name
password = ""; // Password to connect to the server
passwordAdmin = ""; // Password to become a server admin

View file

@ -1,21 +0,0 @@
#!/usr/bin/env bash
# Make sure we don't start collecting core files
ulimit -c 0
# This script will take environment variables and put them into the files the script expects.
echo "steamlogin=anonymous" > .steamlogin
sed -i serverDZ.cfg -e "s/SERVERNAME/${SERVERNAME}/"
./dayzserver start || (
echo
echo "========================================== error.log =========================================="
find /home/user -name error.log -exec cat {} \; -exec rm -f {} \;
echo
echo "========================================== script*.log =========================================="
find /home/user -name "script*.log" -exec cat {} \; -exec rm -f {} \;
echo
echo "========================================== *.RPT =========================================="
find /home/user -name "*.RPT" -exec cat {} \; -exec rm -f {} \;
)