A Revista Cadernos de Cultura e Ciência é de caráter nacional e multidisciplinar, cadastrada com o ISSN 1980-5861.

Comentários do leitor

GitHub - lloesche/valheim-server-docker: Valheim dedicated gameserver with automatic update, World backup, BepInEx and ValheimPlus mod support

por Kara Catt (2022-08-11)


lloesche/valheim-server-docker.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Git or checkout with SVN using the web URL.
Work fast with our official CLI. Learn more.
Launching GitHub Desktop.
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop.
If nothing happens, download GitHub Desktop and try again.
Launching Xcode.
If nothing happens, download Xcode and try again.
Launching Visual Studio Code.
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit.
Git stats.
Files.
Failed to load latest commit information.
README.md.
lloesche/valheim-server Docker image.
Valheim Server in a Docker Container (with BepInEx and ValheimPlus support) This project is hosted at https://github.com/lloesche/valheim-server-docker.
Table of contents.
Basic Docker Usage.
The name of the Docker image is ghcr.io/lloesche/valheim-server .
Volume mount the server config directory to /config within the Docker container.
If you have an existing world on a Windows system you can copy it from e.g. C:\Users\Lukas\AppData\LocalLow\IronGate\Valheim\worlds_local to e.g. $HOME/valheim-server/config/worlds_local and run the image with $HOME/valheim-server/config volume mounted to /config inside the container. The container directory /opt/valheim contains the downloaded server. It can optionally be volume mounted to avoid having to download the server on each fresh start.
Warning: SERVER_PASS must be at least 5 characters long. Otherwise valheim_server.x86_64 will refuse to start!
A fresh start will take several minutes depending on your Internet connection speed as the container will download the Valheim dedicated server from Steam (~1 GB).
Do not forget to modify WORLD_NAME to reflect the name of your world! For existing worlds that is the filename in the worlds_local/ folder without the .db/.fwl extension.
If you want to play with friends over the Internet and are behind NAT make sure that UDP ports 2456-2457 are forwarded to the container host. Also ensure they are publicly accessible in any firewall.
There is more info in section Finding Your Server.
For more deployment options see the Deployment section.
Granting CAP_SYS_NICE to the container is optional. It allows the Steam library that Valheim uses to give itself more CPU cycles. Without it you will see a message Warning: failed to set thread priority in the startup log.
All variable names and values are case-sensitive!
Name Default Purpose SERVER_NAME My Server Name that will be shown in the server browser SERVER_PORT 2456 UDP start port that the server will listen on WORLD_NAME Dedicated Name of the world without .db/.fwl file extension SERVER_PASS secret Password for logging into the server - min. 5 characters! SERVER_PUBLIC true Whether the server should be listed in the server browser ( true ) or not ( false ) SERVER_ARGS Additional Valheim server CLI arguments ADMINLIST_IDS Space separated list of admin SteamIDs in SteamID64 format. Overrides any existing adminlist.txt entries! BANNEDLIST_IDS Space separated list of banned SteamIDs in SteamID64 format. Overrides any existing bannedlist.txt entries! PERMITTEDLIST_IDS Space separated list of whitelisted SteamIDs in SteamID64 format. Overrides any existing permittedlist.txt entries! UPDATE_CRON */15 * * * * Cron schedule for update checks (disabled if set to an empty string or if the legacy UPDATE_INTERVAL is set) IDLE_DATAGRAM_WINDOW 3 The time window, in seconds, to wait for incoming UDP datagrams on non-public servers before determining if the server is idle IDLE_DATAGRAM_MAX_COUNT 30 The number of incoming UDP datagrams the container should tolerate (including useless datagrams such as mDNS, as well as useful datagrams like queries against the UDP query port and active connections by players) on non-public servers before deciding that the server is not idle UPDATE_IF_IDLE true Only run update check if no players are connected to the server ( true or false ) RESTART_CRON 0 5 * * * Cron schedule for server restarts (disabled if set to an empty string) RESTART_IF_IDLE true Only run daily restart if no players are connected to the server ( true or false ) TZ Etc/UTC Container time zone BACKUPS true Whether the server should create periodic backups ( true or false ) BACKUPS_CRON 0 * * * * Cron schedule for world backups (disabled if set to an empty string or if the legacy BACKUPS_INTERVAL is set) BACKUPS_DIRECTORY /config/backups Path to the backups directory BACKUPS_MAX_AGE 3 Age in days after which old backups are flushed BACKUPS_MAX_COUNT 0 Maximum number of backups kept, 0 means infinity BACKUPS_IF_IDLE true Backup even when no players have been connected for a while BACKUPS_IDLE_GRACE_PERIOD 3600 Grace period in seconds after the last player has disconnected in which we will still create backups when BACKUPS_IF_IDLE=false BACKUPS_ZIP true Compress Backups with zip . If set to false Backups will be stored uncompressed. PERMISSIONS_UMASK 022 Umask to use for backups, config files and directories STEAMCMD_ARGS validate Additional steamcmd CLI arguments VALHEIM_PLUS false Whether ValheimPlus mod should be loaded (config in /config/valheimplus , additional plugins in /config/valheimplus/plugins ). Can not be used together with BEPINEX . VALHEIM_PLUS_RELEASE latest Which version of ValheimPlus to download. Will default to latest available. To specify a specific tag set to tags/0.9.9.8 BEPINEX false Whether BepInExPack Valheim mod should be loaded (config in /config/bepinex , plugins in /config/bepinex/plugins ). Can not be used together with VALHEIM_PLUS . SUPERVISOR_HTTP false Turn on supervisor's http server SUPERVISOR_HTTP_PORT 9001 Set supervisor's http server port SUPERVISOR_HTTP_USER admin Supervisor http server username SUPERVISOR_HTTP_PASS Supervisor http server password STATUS_HTTP false Turn on the status http server. Only useful on public servers ( SERVER_PUBLIC=true ). STATUS_HTTP_PORT 80 Status http server tcp port STATUS_HTTP_CONF /config/httpd.conf Path to the busybox httpd config STATUS_HTTP_HTDOCS /opt/valheim/htdocs Path to the status httpd htdocs where status.json is written SYSLOG_REMOTE_HOST Remote syslog host or IP to send logs to SYSLOG_REMOTE_PORT 514 Remote syslog UDP port to send logs to SYSLOG_REMOTE_AND_LOCAL true When sending logs to a remote syslog server also log local PUID 0 UID to run valheim-server as PGID 0 GID to run valheim-server as.
There are a few undocumented environment variables that could break things if configured wrong. They can be found in defaults .
Valheim server by default logs a lot of noise. These env variables allow users to remove unwanted lines from the log.
Prefix Default Purpose VALHEIM_LOG_FILTER_EMPTY true Filter empty log lines VALHEIM_LOG_FILTER_UTF8 true Filter invalid UTF-8 characters VALHEIM_LOG_FILTER_MATCH Filter log lines exactly matching VALHEIM_LOG_FILTER_STARTSWITH (Filename: Filter log lines starting with VALHEIM_LOG_FILTER_ENDSWITH Filter log lines ending with VALHEIM_LOG_FILTER_CONTAINS Filter log lines containing VALHEIM_LOG_FILTER_REGEXP Filter log lines matching regexp.
The default filter removes:
Empty log lines Log lines consisting of a single space (wtf?) A repeating line saying (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35) Lines flodding the log with Assertion Failed warnings on packet processing timeouts (See #104) If ValheimPlus is turned on lines starting with Fallback handler could not load library.
Log filter event hooks.
If an environment variable prefixed with ON_ exists for an identically named log filter, instead of removing the log line the contents of the variable will be executed when the filter matches with the log line piped on stdin.
Prefix Purpose ON_VALHEIM_LOG_FILTER_MATCH Run command hook on log lines exactly matching ON_VALHEIM_LOG_FILTER_STARTSWITH Run command hook on log lines starting with ON_VALHEIM_LOG_FILTER_ENDSWITH Run command hook on log lines ending with ON_VALHEIM_LOG_FILTER_CONTAINS Run command hook on log lines containing ON_VALHEIM_LOG_FILTER_REGEXP Run command hook on regexp match.
All environment variables except for VALHEIM_LOG_FILTER_EMPTY and VALHEIM_LOG_FILTER_UTF8 are prefixes. Meaning you can define multiple matches like so:
Discord log filter event hook example.
Sends a Discord message whenever a player spawns.
See Notify on Discord below for proper quoting in env and compose files.
If you are running ValheimPlus and this filter triggers twice, check this ValheimPlus issue. The cause is a misconfigured BepInEx.cfg that causes all log lines to be duplicated.
The following environment variables can be populated to run commands whenever specific events happen.
Name Default Purpose PRE_SUPERVISOR_HOOK Command to be executed before supervisord is run. Startup is blocked until this command returns. PRE_BOOTSTRAP_HOOK Command to be executed before bootstrapping is done. Startup is blocked until this command returns. POST_BOOTSTRAP_HOOK Command to be executed after bootstrapping is done and before the server or any services are started. Can be used to install additional packages or perform additional system setup. Startup is blocked until this command returns. PRE_BACKUP_HOOK Command to be executed before a backup is created. The string @BACKUP_FILE@ will be replaced by the full path of the future backup zip file. Backups are blocked until this command returns. POST_BACKUP_HOOK Command to be executed after a backup is created. The string @BACKUP_FILE@ will be replaced by the full path of the backup zip file. Backups are blocked until this command returns. See Copy backups to another location for details. PRE_UPDATE_CHECK_HOOK Command to be executed before an update check is performed. Current update is blocked until this command returns. POST_UPDATE_CHECK_HOOK Command to be executed after an update check was performed. Future updates are blocked until this command returns. PRE_START_HOOK Command to be executed before the first server start is performed by the valheim-updater. Current start is blocked until this command returns. POST_START_HOOK Command to be executed after the first server start was performed by the valheim-updater. Future restarts and update checks are blocked until this command returns. PRE_RESTART_HOOK Command to be executed before a server restart is performed by the valheim-updater. Current restart is blocked until this command returns. PRE_SERVER_LISTENING_HOOK Command to be executed after the server runs, but before it's able to accept connections. The loop that checks connection status will be blocked until this command returns. POST_SERVER_LISTENING_HOOK Command to be executed once the server is available for players to connect! The hook only fires after status is updated to running . POST_RESTART_HOOK Command to be executed after a server restart was performed by the valheim-updater. Future restarts and update checks are blocked until this command returns. PRE_SERVER_RUN_HOOK Command to be executed before the server is started. Server startup is blocked until this command returns. POST_SERVER_RUN_HOOK Command to be executed after the server has finished running. Server shutdown is blocked until this command returns or a shutdown timeout is triggered after 29 seconds. PRE_SERVER_SHUTDOWN_HOOK Command to be executed before the server is shut down. Server shutdown is blocked until this command returns. If PRE_SERVER_SHUTDOWN_HOOK holds the shutdown process for more than 90 seconds, the entire process will be hard-killed by supervisord . POST_SERVER_SHUTDOWN_HOOK Command to be executed after the server has finished shutting down. PRE_BEPINEX_CONFIG_HOOK Command to be executed before writing BepInEx.cfg. POST_BEPINEX_CONFIG_HOOK Command to be executed after writing BepInEx.cfg. Can be used to write your own mod config using env2cfg .
Event hook examples.
Install extra packages.
Copy backups to another location.
After a backup ZIP has been created the command specified by $POST_BACKUP_HOOK will be executed if set to a non-zero string. Within that command the string @BACKUP_FILE@ will be replaced by the full path to the just created ZIP file.
Notify on Discord.
Because proper string quoting on the shell vs. inside a docker-compose.yaml vs. an env_file can be challenging, here are examples for each use case.
Using the commandline.
Delay restarts by 1 minute and notify on Discord.
Notify on Discord with server's name in the message.
Inside an env_file.
Notify on Matrix, inside an env_file.
Create an account for your bot, log in and join the room you want to post to. The room ID is noted in the room's settings.
Note the $(date +%s-%N) is used for the required unique txnId.
Mod config from Environment Variables.
Mod config can be specified in environment variables using the syntax __= .
Predefined prefix list.
Prefix Mod File VPCFG ValheimPlus /config/valheimplus/valheim_plus.cfg BEPINEXCFG BepInEx /config/valheimplus/BepInEx.cfg or /config/bepinex/BepInEx.cfg depending on whether VALHEIM_PLUS=true or BEPINEX=true.
Translation table Some characters that are allowed as section names in the config files are not allowed as environment variable names. They can be encoded using the following translation table.
Variable name string Replacement _DOT_ . _HYPHEN_ - _UNDERSCORE_ _ _PLUS_ +
turns into /config/valheimplus/valheim_plus.cfg.
All existing configuration in those files is retained and a backup of the old config is created as e.g. /config/valheimplus/valheim_plus.cfg.old before writing the new config file.
You could generate your own custom plugin config from environment variables using the POST_BEPINEX_CONFIG_HOOK event hook and env2cfg .
On our system while idle with no players connected Valheim server consumes around 2.8 GB RSS. All the while using around 30% of one CPU Core on a 2.40 GHz Intel Xeon E5-2620 v3. Valheim server is making use of many threads with two of them seemingly doing the bulk of the work each responsible for around 8-10% of the 30% of idle load.
The picture changes when players connect. The first player increased overall load to 42%, the second player to 53%. In the thread view we see that a thread that was previously consuming 10% is now hovering around 38%. Meaning while Valheim server creates 50 threads on our system it looks like there is a single thread doing the bulk of all work (~70%) with no way for the Kernel to distribute the load to many cores.
Therefor our minimum requirements would be a dual core system with 4 GB of RAM and our recommended system would be a high clocked 4 core server with 8 GB of RAM. A few very high clocked cores will be more beneficial than having many cores. I.e. two 5 GHz cores will yield better performance than six 2 GHz cores. This holds especially true the more players are connected to the system.
Deploying with Docker and systemd.
Create a config file /etc/sysconfig/valheim-server.
Then enable the Docker container on system boot.
Deploying with docker-compose.
Copy'paste the following into your shell.
Deploying to Kubernetes.
Kubernetes manifests using this container image, along with a helm chart, are available from the following repository: https://github.com/Addyvan/valheim-k8s.
The chart is also available directly using:
Deploying to AWS ECS.
CDK Project for spinning up a Valheim game server on AWS Using ECS Fargate and Amazon EFS is available here: https://github.com/rileydakota/valheim-ecs-fargate-cdk.
Deploying to Nomad.
By default the container will check for Valheim server updates every 15 minutes if no players are currently connected to the server. If an update is found it is downloaded and the server restarted. This update schedule can be changed using the UPDATE_CRON environment variable.
The container will on startup and periodically create a backup of the worlds_local/ directory.
The default is once per hour but can be changed using the BACKUPS_CRON environment variable.
Default backup directory is /config/backups/ within the container. A different directory can be set using the BACKUPS_DIRECTORY environment variable. It makes sense to have this directory be a volume mount from the host. Warning: do not make the backup directory a subfolder of /config/worlds_local/ . Otherwise each backup will backup all previous backups.
By default 3 days worth of backups will be kept. A different number can be configured using BACKUPS_MAX_AGE . The value is in days.
It is possible to configure a maximum number of to-be-kept backup files with BACKUPS_MAX_COUNT . When going over this limit, the oldest file(s) will be deleted. The default is 0 which means no limit. Note that BACKUPS_MAX_AGE will always be respected: if backups get too old, they will be deleted even if BACKUPS_MAX_COUNT was not yet reached (or is 0 ).
Beware that backups are performed while the server is running. As such files might be in an open state when the backup runs. However the worlds_local/ directory also contains a .db.old file for each world which should always be closed and in a consistent state.
See Copy backups to another location for an example of how to copy backups offsite.
If BACKUPS_IF_IDLE=false then backups are only created if there has been recent player activity. Once the last player disconnects there is a grace period BACKUPS_IDLE_GRACE_PERIOD in seconds after which backups are still being created. The reason for this is that Valheim dedicated server only saves the world in 20 minute intervals and on shutdown. So to make sure that we have a consistent world file backup of the most recent changes we want to wait out one world save. This grace period also needs to be long enough so that our BACKUPS_CRON had a chance to run.
BACKUPS_ZIP=false can be used to store backups uncompressed in the backup directory. Please note that this will increase the filesize of the backups, due to no compression.
Sending SIGHUP to the valheim-backup service or restarting the service will create a backup. If BACKUPS_IF_IDLE=false sending SIGHUP only creates a backup if there has been recent player activity. Restarting valheim-backup will always create a backup.
The PID of the running service can be found in /var/run/valheim-backup.pid.
Assuming your container's name is valheim-server here's how both would work:

Should you cherished this post and also you wish to acquire more details with regards to dedicated server valheim generously check out the internet site.



ISSN: 1980-5861