Running a Valheim game server in Azure with an (almost) one-button-push deploy.
This repository contains scripts to:
- Create a Docker container with a configured Valheim game server
- Create the necessary infrastructure in Azure to run the container
- Deploy the container to an Azure container instance
- Everything is setup in 1 Azure resource group, nothing is created outside of this resource group
- You can easily backup the game server
- You can easily update the game server
- Game server management by courtesy of LinuxGSM
Steps to get the Valheim game server up-and-running in Azure:
- Have Docker up and running on your local machine, and supporting linux containers
- Install the Azure CLI and make sure your current terminal window is logged on before running the Azure setup scripts
- Install the Azure CLI
- Login through
az login
- more info here
- Scripts are
.sh
files, so you are expected to be running abash
shell - Have this repository cloned on your local machine
- Set the Valheim game server settings - Set the
servername
andserverpassword
parameters in thevhserver.cfg
config file (the password needs to be at least 5 chars long, otherwise the server will not start) - Set the Azure settings - Set the parameters in the
config.sh
file, the most important parameter to change is the name of theCONTAINER_REGISTRY
- Run script
bash ./docker/build-docker-image.sh
- this builds the docker container locally - Run script
bash ./azure/create-azure-infrastructure.sh
- this creates the necessary infrastructure in Azure - Run script
bash ./azure/push-and-run-docker-container.sh
- this deploys the container to an Azure container registry and boots it up in an Azure container instance
Run the scripts above in sequential order -and- from the root folder, wait until one script is done before running the next one.
If all went well, you now have a Valheim game server up and running in Azure :party:
How to play:
- Get the ip address of the container instance
- Edit the properties of Valheim in Steam and add the following in the
LAUNCH OPTIONS
field:+connect <ip-address>:2456
(e.g.+connect 51.138.124.34:2456
) - there is a way to have your game server show up in the Valheim server list, but apparently this is kinda buggy and I have not tried setting it up. - Start Valheim through Steam and provide the password you configured earlier in the
vhserver.cfg
file.
If the password is not accepted and you get a disconnect, something went wrong :-( You can start troubleshooting by seeing if the server is online or by connecting to the running container intance to check the server. If you want to see if the server is running, you can execute the following command ./vhserver details
.
The software that is used to manage the Valheim game server is called LinuxGSM. It's a game server management system that supports several different games and provides a lot of funtionality out of the box: server install, backup, monitor, update, etc. It's an open source project that is available on Github and it seems to work really well.
I borrowed some code from their Docker implementation.
You can get the IP address by running this script bash ./azure/show-container-instance-ip.sh
You can connect to the docker container in Azure by running this script bash ./azure/connect-with-container-in-azure.sh
You can use this website to check if your Valheim game server works correctly: https://geekstrom.de/valheim/check/
- Go through steps 1-4 above
- Run the docker container by running this script
bash ./docker/run-local-interactive.sh
- Make Steam connect on the IP of your local machine
You can throw away everything that was created in Azure by running this script bash ./azure/cleanup_azure.sh
- this will remove the entire resource group AND your Valheim game world, so be careful when running this command. See section Backup the game world locally if you want to backup your game world before removing everything in Azure.
The backup procedure is not yet automated, at this moment you need to launch the backup process manually. You can do this by following these steps:
- Connect to the running container in Azure
- Run this command in the container
./vhserver backup
- The backup will be placed outside of the container on the file share of the created storage account
The backup is done to the storage account file share that was automatically created. If you go to the storage account and to File shares
you will find a file share there that contains the backup files (.tar.gz
files). You can download these files locally, they contain a complete backup of the server
With the .tar.gz
backup file you can restore the entire server.
If you want you can even:
- Remove the entire Azure resource group
- Recreate it again from scratch
- Stop the game server
- Restore the backup file, by extracting the
.tar.gz
backup and overwriting the existing files, this is the command to extract the backup filetar -xvf <backupfilename>.tar.gz -C /home/linuxgsm
No automation has been setup, but it's pretty simple. Just follow the instructions from LinuxGSM.
Beware! Backup your game server first. Valheim is still a little buggy, and I had my game world destroyed after an update :-(
If you would like to contribute, these are the optimisations I have in mind:
- Create a start/stop script to easily stop the Azure services and save on cost
- Automate the backups every night
- Make the Azure setup part run in a Docker container so the only dependency on the host is Docker and installing the Azure CLI is not needed anymore
- Create a real one button push setup (create vhserver docker container + azure setup)
Nice to have:
- Making the game server show up in the browse server list
- Add error handling
- Automate linuxgsm and valheimserver updates (and do a backup right before)
- Make this project game server generic (put the game that linuxgsm needs to install in config)
https://stackoverflow.com/questions/47574755/docker-created-files-disappear-between-layers
Try running docker system prune
, and building again afterwards.
I tried doing the Azure stuff through the Docker Azure CLI Container, but there are two issues I need to work around:
- Authentication to Azure for the Azure CLI 'az login` when running in the Docker container
- How to push the local docker image from the Azure CLI Docker