Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save husjon/c5225997eb9798d38db9f2fca98891ef to your computer and use it in GitHub Desktop.
Save husjon/c5225997eb9798d38db9f2fca98891ef to your computer and use it in GitHub Desktop.
Script and Instructions to setup a Valheim Dedicated Server using Oracle Cloud Infrastructure

Table of Content

⚠️ Disclaimer ⚠️

Ubuntu version

Currently the only supported version of Ubuntu is Ubuntu 22.04 LTS, please make sure the image Canonical Ubuntu 22.04 Minimal aarch64 is selected during the setup procedure.

This is because changes was done in preparation to how timestamps will be handled prior to 2038.
This was added last minute prior to the Ubuntu 24.04LTS release cycle feature feeeze, which unfortunately impacted armhf which we rely on here, more information can be found at the ubuntu mailing list: https://lists.ubuntu.com/archives/ubuntu-devel-announce/2024-March/001344.html

Box64 configuration

This install script has now been updated with a configuration for box64 which has been tested to work for a few weeks and by different people using this guide.
If you have made any changes to the ~/.box64rc configuration file for the [valheim_server.x86_64] section, please remove it and run the setup script.
If you should experience any issues, please leave a comment.

This script / procedure for setting up a Valheim server on ARM is currently broken as of 7th of November 2023. (https://www.valheimgame.com/news/patch-0-217-28/)

This unfortunately also includes the rollback procedure. Check comments for any updates regarding this issue.

Credit

The original guide is from Reddit user That_Conversation_91 on r/Valheim.
Original post can be found here

Instructions

Note: For this guide a free account is required on the Oracle Cloud Infrastructure allowing us to spin up a server which is decently specced.

In this guide, we'll:

  • Set up a Virtual Machine using the Oracle Cloud Infrastructure, including firewall rules
  • Prepare and use SSH to connect to the Virtual Machine
  • Update the Operating System and install the Valheim Dedicated Server software
  • Finally we'll use Systemd to allow the server to run automatically.

If you have the knowledge of setting up a server on an alternative cloud provider or your own hardware you may skip ahead to Installing the Valheim Dedicated Server

Pre-requisite

Windows

To connect to the server in the section Connecting to the VM Instance we need to do some preparation.

  1. First of all we need an SSH client, namely Putty
  2. Head on over to https://www.putty.org/ and click on the Download PuTTY link
  3. Scroll down to Alternative binary files
    1. click on putty.exe (64-bit x86)
    2. next scroll down and you'll find puttygen click on puttygen.exe (64-bit x86)
  4. Open up puttygen
    1. Press Generate
    2. Copy the whole SSH key starting at ssh-rsa, we'll need this in the next section when Creating the VM Instance
    3. Press Save public key and save it to f.ex your Desktop
    4. Press Save private key and save it to f.ex your Desktop
      It will ask about password protecting the key, this isn't necessary for this setup.

Mac / Linux

Verify that we have a set of SSH key pairs

  1. Open a terminal
  2. Run the command ls -l ~/.ssh/.
    If you see the files id_rsa and id_rsa.pub, you can continue on with OCI (Oracle Cloud Infrastructure)
  3. If you did not see these files, you can run the command ssh-keygen -N '' -f ~/.ssh/id_rsa Now you can re-run the command from step 2 and you should see both files.

OCI (Oracle Cloud Infrastructure)

  1. Head on over to https://cloud.oracle.com/ to sign up for a free account.
    After logging in you will be shown a Get Started page.
    All subsequent section starts from Getting Started.

Creating the VM instance

  1. From the Getting Started dashboard, scroll down a bit and click the Create a VM instance
  2. On the right hand side of Image and shape click Edit
    1. Click Change image and choose a Canonical Ubuntu 22.04 Minimal aarch64 and confirm with the Select image button.
      Note: make sure you select aarch64 which is aimed at ARM server
    2. Click Change shape and set the following:
      • Instance type: Virtual machine
      • Shape series: Ampere
      • Shape: VM.Standard.A1.Flex
      • OCPUs: 4
      • Memory: 24GB
  3. On the right hand side of Networking click Edit
    1. Select Create new virtual cloud network and leave the values as is.
  4. On the right hand side of Add SSH keys click Edit
    • If you're f.ex on Linux or Mac you can find your SSH keys under ~/.ssh/id_rsa.pub In this case you can select Upload public key files (.pub) then navigate to ~/.ssh/id_rsa.pub
    • For Windows, the SSH public key we copied in Pre-requisite for Windows can be pasted in by under Paste public keys
  5. Click Create.
    Note: If you get a warning about Out of Capacity, scroll up to the Placement section and try another Domain (AD 1, AD 2 or AD 3), and try again.
    This will take a couple of minutes while the instance is being provisioned / set up.
    While we wait for it we'll go back to the dashboard and set up the networking.
    Click on the ORACLE Cloud header or click here to go back to the Getting started page.

Configuring the Network and firewall rules

  1. At the top of the Getting started page, click on Dashboard
  2. Under Resource explorer, click Virtual Cloud Networks, then click the network (f.ex vcn-20221120-1500)
  3. On the left hand side, click on Security Lists, then the Default Security List for NETWORKNAME
  4. We will be creating a rule so that we can connect to the server from Valheim.
    1. Under Ingress Rules, click Add Ingress Rules:
      • Source Type: CIDR
      • Source CIDR: 0.0.0.0/0
      • IP Protocol: UDP
      • Source Port Range: All
      • Destination Port Range 2456-2459
  5. Click on the ORACLE Cloud header or click here to go back to the Getting started page.
  6. Navigate back to the Dashboard, under the Resource explorer click on Instances then the instance (f.ex instance-20221120-1503)
  7. On the right hand side you'll see Instance access, click Copy to the right of Public IP address, we need this in the next step.

Connecting to the VM Instance

The IP Address we copied in the previous step will be referenced here as IP_ADDRESS

Windows

  1. Start putty which we downloaded in Pre-requisite for Windows
  2. We'll configure the following parameters:
    • Host Name (or IP address): IP_ADDRESS
    • Port: 22
    • Saved Sessions: Valheim Server
    • Close window on exit: Never
    • Click Save
  3. Next in the navigation tree to the left go to Connection > SSH > Auth > Credentials
    1. Under Private key file for authentication click Browse... and navigate to the Private key we saved using puttygen
  4. Go back up in the navigation tree to Session and click Save
  5. Then click Open
  6. You should within a couple of seconds see a prompt along the lines of ubuntu@instance-20221120-1503:~$
  7. You're now good to go to Installing the Valheim Dedicated Server

Mac / Linux

  1. On Mac and Linux we already have an SSH client installed.
  2. Open up a terminal then execute ssh ubuntu@IP_ADDRESS
  3. You should within a couple of seconds see a prompt along the lines of ubuntu@instance-20221120-1503:~$
  4. You're now good to go to Installing the Valheim Dedicated Server

Installing the Valheim Dedicated Server

  1. Run the following command:

    wget https://gist.githubusercontent.com/husjon/c5225997eb9798d38db9f2fca98891ef/raw/setup_valheim_server.sh
    

    This will download the installation script onto your server allowing it to set up everything which is needed.

  2. Then run the following command:

    bash ./setup_valheim_server.sh

    The first time this is run, the setup script will update the operating system and then reboot. If you get notification about kernel upgrades, or restarting services you may just press Enter, allowing the default values be. After it's done you will be disconnected, wait about 15-20 seconds then reconnect to the server.

  3. Run the same command again

    bash ./setup_valheim_server.sh

    Note: If you're playing on Console or Xbox Game Pass / Microsoft Game Pass, please enable Crossplay.
    Also, read the Crossplay section.

    The installation will take a couple of minutes to complete as the script installs all the necessary packages and set up the server with initial values.
    Once it finishes it let you know that we need to make a small edit to one file then start the server.

Configuring the Valheim Server

  1. Open up the server_credentials file with nano ~/server_credentials (or text editor of choice)
  2. Adjust the SERVER_NAME, WORLD_NAME PASSWORD, PUBLIC as you see fit.
    Note: The setup script populated the password field automatically with a random decently strong password.
  3. When done, Press Ctrl+X, then y and finally Enter.
    Note: Mac users might need to use the Cmd button instead of Ctrl

Starting the Valheim Server

To start the server, run the command valheim_server start
This will take a couple of minutes as the world is being generated.

From within the game, it might not show in the Select Server list, instead click the Add server button and type in the address IP_ADDRESS:2456 (Using the IP address fromConfiguring the Network and firewall rules)

More information can be found in the attached Readme.md file and can be viewed with cat ~/Readme.md

Updating the Valheim Server

Whenever the Valheim client updates, the server also needs to be updated.
To do this, log onto the VM then run the command valheim_server update
This will stop the running server and update the server files.
Once done, you must start the server using valheim_server start

Crossplay (Console / Game Pass)

Note: Crossplay on ARM architecture is currently experimental (thanks to @bitdo1).

During setup you will be asked if crossplay should be enabled or disabled.

If you'd like to enable / disable this after the first setup, you can change it by rerunning the setup script. You will need to restart the server for this to take effect using valheim_server restart

After crossplay has been enabled, the join procedure is the same as normal using IP:port, however you can now also join by using a 6 digit code which can be found in the logs after the server has started (using the valheim_server logs-live command).
Example log message:
Session "My Valheim server" with join code 295265 and IP 12.34.56.78:2456 is active with 0 player(s)

Note: Do keep in mind that the join code will change every time the server is restarted!

Modding

BepInEx currently do not support ARM, hence modding currently seem to not be possible.
If this changes in the future, this section will be updated to reflect that.
An issue has been raised with BepInEx and can be found here BepInEx/BepInEx#336

PS: If you're willing to try to install mods on your ARM instance and are able to so successfully, please do let me know.

As for a guide to install mods, here is one.
https://www.youtube.com/watch?v=h2t9cSFidt0

Installer Self-update

The setup_valheim_server.sh now has a self-update feature which allow it to update itself and apply any bugfixes that should be necessary whenever the script is run.

After updating, it will show what have changed, update itself, then ask the user to restart the setup script.
It is not retroactively applied, hence the script will need to be downloaded again f.ex with:

wget https://gist.github.com/husjon/c5225997eb9798d38db9f2fca98891ef/raw/setup_valheim_server.sh -O ~/setup_valheim_server.sh

This will overwrite the existing script.

This feature was added Thu, 15 Dec 2022 19:56:51 +0100.

Adding Pre-existing worlds

If you already have a world you've played on (f.ex hosted on your own computer) and you'd like to continue using it with this server,
the following steps can be used.

  1. Locate your save folder, navigate to this folder:
    The files we are interested in are the .db and .fwl files.
    • Windows: %userprofile%/AppData/LocalLow/IronGate/Valheim/Worlds
    • Linux: $HOME/.config/unity3d/IronGate/Valheim/worlds
  2. Stop the Valheim Server with valheim_server stop
  3. With an SFTP client (f.ex FileZilla), upload the .db and .fwl file to the folder: /home/${USER}/valheim_data
  4. Edit the ~/server_credentials and update the WORLD_NAME parameter to the name of your World files.
    F.ex if you world file was My_Valheim_World.db and My_Valheim_World.fwl, set it to WORLD_NAME="My_Valheim_World"
  5. Start the Valheim Server with valheim_server start
  6. Within a few moments the server should be back up and running with the world you uploaded.

Troubleshooting

In case you should experience any issues and would need some assistance, the install logs and server logs are helpful to troubleshoot the issue.

To help with this the following steps should be followed:

  1. Create a log output of the running server using the following command:
    journalctl --no-pager --since=-1d --user -u valheim_server > ~/valheim_server.systemd.log
    This will take a snapshot of the logs from the Valheim Server from the last 24 hours.
    In case the Valheim server was never started, this can be omitted.
  2. Download the install_valheim_server.log and valheim_server.systemd.log file located under /home/ubuntu using f.ex FileZilla.
    Note: Use port 22 for SFTP/SSH.
  3. Go to https://gist.github.com/, click Add File for each file, then Create Public / Secret Gist
    This creates a gist (similar to this guide) which we can go through to troubleshoot.
  4. Copy the URL to the gist and create a comment down below describing the issue and adding the link to the gist.

I might be delayed due to work / timezones etc, but hoping to get you going as quickly as possible.

Discord

I've decided to open up my discord server so if you need help or would like to suggest improvements or similar, please tag along.
https://discord.gg/ExnzM4E7pE

Changing versions

This could be useful in case the public version breaks something. Make sure you create a backup of the server before switching versions.

Switcing to the Previous Stable Version

  1. Run SteamCMD to change to the default_old branch
cd ~/steamcmd

./steamcmd.sh \
    +@sSteamCmdForcePlatformType linux \
    +force_install_dir "/home/$USER/valheim_server" \
    +login anonymous \
    +app_update 896660 -beta default_old validate \
    +quit
  1. In Steam, right-click the game, open Properties, go to Betas and select default_old from the dropdown and wait for the game to update (this might take a few minutes).
  2. Start the game and connect to your server as normal.

Switching to the Public Beta Branch

  1. Run SteamCMD to change to the public-test branch
cd ~/steamcmd

./steamcmd.sh \
    +@sSteamCmdForcePlatformType linux \
    +force_install_dir "/home/$USER/valheim_server" \
    +login anonymous \
    +app_update 896660 -beta public-test -betapassword yesimadebackups validate \
    +quit
  1. In Steam, right-click the game, open Properties, go to Betas and select public-test from the dropdown and wait for the game to update (this might take a few minutes).
    If public-test is not in the list, type in yesimadebackups in the Input field below and press Check Code.
  2. Start the game and connect to your server as normal.

Reverting back to the public version

  1. Run SteamCMD to change to the public branch
cd ~/steamcmd

./steamcmd.sh \
    +@sSteamCmdForcePlatformType linux \
    +force_install_dir "/home/$USER/valheim_server" \
    +login anonymous \
    +app_update 896660 -beta public validate \
    +quit
  1. In Steam, right-click the game, open Properties, go to Betas and select None from the dropdown and wait for the game to update (this might take a few minutes).
  2. Start the game and connect to your server as normal.

Oracle and Reclamation of Idle Compute Instances

Oracle have a policy on their Always Free instances whichs allows them to reclaim instances that are idle or using less than a certain percentile (See: Always_Free_Resources).

For the most part using the server should not trigger this.

If the server should be flagged for reclaimation, you'll receive an email saying that it has been flagged for being idle for the last 7 days.
Next it will say that if it continues for another 7 days, the server will be stopped.
This gives us ample time to either back up the data or continue playing.

The only thing needed to do is to log onto your Oracle Cloid Infrastructure, go to your Instances and click the Restart button, this will pause the reclaimation.

TODOs

  • Add ability to update the Valheim server prior to starting the server.
    Tue, 24 Jan 2023 23:01:18 +0100
    Now part of the valheim_server helper command.

  • Add information about adding pre-existing worlds
    Tue, 24 Jan 2023 22:47:19 +0100

  • Add support for users other than ubuntu
    Tue, 24 Jan 2023 22:33:56 +0100
    Made it so that the install script no longer is tied to the ubuntu user.

#!/bin/bash
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
ORANGE=$(tput setaf 3)
BOLD=$(tput bold)
CLEAR=$(tput sgr0)
function warn { echo -en "\n\n${BOLD}${ORANGE}[-] $* ${CLEAR}\n"; }
function success { echo -en "${BOLD}${GREEN}[+] $* ${CLEAR}\n"; }
function info { echo -en "\n\n${BOLD}[ ] $* ${CLEAR}\n"; }
function error { echo -en "${BOLD}${RED}[!] $* ${CLEAR}\n"; }
function notify { echo -en "\n\n${BOLD}${ORANGE}[!] $* ${CLEAR}\n"; }
function perform_self_update {
SETUP_SCRIPT_URL="https://gist.github.com/husjon/c5225997eb9798d38db9f2fca98891ef/raw/setup_valheim_server.sh"
ETAG_CACHE="${HOME}/.cache/setup_valheim_server.etag"
SETUP_SCRIPT_PATH="$(realpath "$0")"
TEMP_SCRIPT_PATH="$(mktemp)"
info "Checking for setup script updates"
curl --silent --etag-save "${ETAG_CACHE}" --etag-compare "${ETAG_CACHE}" -L "${SETUP_SCRIPT_URL}" -o "${TEMP_SCRIPT_PATH}"
if [[ -s "${TEMP_SCRIPT_PATH}" ]]; then
if ! cmp --silent $SETUP_SCRIPT_PATH $TEMP_SCRIPT_PATH; then
echo "Setup script available, updating..."
notify "Changes (< = removed | > = added):"
diff --color --minimal "${SETUP_SCRIPT_PATH}" "${TEMP_SCRIPT_PATH}"
echo
sleep 1
mv "${TEMP_SCRIPT_PATH}" "${SETUP_SCRIPT_PATH}"
success "Updated setup script."
notify "Please re-run the setup script..."
echo
exit 0
fi
fi
success "No update available"
echo
rm -f "${TEMP_SCRIPT_PATH}"
}
function main {
# Stop on error
set -e
if [[ $(lsb_release -rs) != '22.04' ]]; then
error "The release \"$(lsb_release -ds 2>/dev/null)\" is not supported, please re-install using Ubuntu 22.04 LTS."
echo "See https://gist.github.com/husjon/c5225997eb9798d38db9f2fca98891ef#ubuntu-version for more information"
echo
exit 1
fi
cd
while :; do
echo "This script will install the Valheim Dedicated server "
echo -n "Are you sure? [yes/no] "
read -r answer
case $answer in
YES|Yes|yes|y)
break;;
NO|No|no|n)
echo Aborting; exit;;
esac
done
echo
while :; do
echo "Should this server use crossplay?"
echo "Note: this is currenly highly experimental"
echo -n "[yes/no] (default: no) "
read -r answer
case $answer in
YES|Yes|yes|y)
CROSSPLAY_SUPPORT=true
break;;
NO|No|no|n|*)
CROSSPLAY_SUPPORT=false
break;;
esac
done
# Update and upgrade the system
mkdir -p ~/.cache
if [[ ! -f ~/.cache/valheim_server_setup ]]; then
info "First time setup"
info "Adding Architecture"
sudo apt -y update
sudo dpkg --add-architecture armhf
info "Updating and upgrading the OS"
sudo apt -y update
sudo apt -y upgrade && touch ~/.cache/valheim_server_setup
success "Updating and upgrading the OS - Done"
sudo reboot
warn "Rebooting..."
fi
# Prepare box86 and box64
info "Installing required packages"
sudo apt -y install \
build-essential \
cmake \
gcc-arm-linux-gnueabihf \
git \
libc6:armhf \
libncurses6 \
libstdc++6 \
libpulse0 && \
success "Installing required packages - Done"
if uname -p | grep "aarch64" > /dev/null; then
notify "Found system to be 64bit Arm"
# Fetch and build Box 86 and 64
for ARCH in {86,64}; do
cd
if [[ ! -d "$HOME/box${ARCH}" ]]; then
info "Fetching Box${ARCH}"
git clone "https://github.com/ptitSeb/box${ARCH}" && \
mkdir -p "box${ARCH}/build"
success "Fetching Box${ARCH} - Done"
fi
info "Building Box${ARCH}"
cd "$HOME/box${ARCH}/build"
git fetch
if [[ $ARCH == 64 ]] && [[ -n $BOX64_VERSION ]]; then
TAG="${BOX64_VERSION}"
elif [[ $ARCH == 86 ]] && [[ -n $BOX86_VERSION ]]; then
TAG="${BOX86_VERSION}"
else
TAG="$(git tag | tail -n 1)"
fi
git checkout "${TAG}"
cmake .. -DRPI4ARM64=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo
make -j"$(nproc)" && success "Building Box${ARCH} - Done"
info "Installing Box${ARCH}"
sudo make install && success "Installing Box${ARCH} - Done"
done
sudo systemctl restart systemd-binfmt.service
if ! grep -F '[valheim_server.x86_64] #box64 v0.2.6' ~/.box64rc; then
info "Adding box64 configuration"
cat <<-EOF | tee -a ~/.box64rc
[valheim_server.x86_64] #box64 v0.2.6
BOX64_DYNAREC_BLEEDING_EDGE=0
BOX64_DYNAREC_STRONGMEM=3
EOF
fi
fi
# Fetch and initialize steamcmd
if [[ ! -f ~/steamcmd/steamcmd.sh ]]; then
info "Fetching steamcmd"
mkdir -p ~/steamcmd && \
cd ~/steamcmd && \
curl -sqL "https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz" | tar zxvf -
./steamcmd.sh +quit && success "Fetching steamcmd - Done"
fi
# Add steamcmd steamclient.so symlink
info "Adding steamclient.so symlink"
mkdir -p ~/.steam/sdk64 && ln -frs ~/steamcmd/linux64/steamclient.so ~/.steam/sdk64/
# Install the Valheim Dedicated Server from Steam
if [[ ! -f ~/valheim_server/start_server.sh ]]; then
info "Installing Valheim Dedicated Server"
cd ~/steamcmd
./steamcmd.sh \
+@sSteamCmdForcePlatformType linux \
+force_install_dir "/home/$USER/valheim_server" \
+login anonymous \
+app_update 896660 validate \
+quit && \
success "Installing Valheim Dedicated Server - Done"
fi
# Add x86_64 version of libpulse-mainloop-glib.so.0
if [[ $CROSSPLAY_SUPPORT == true ]]; then
if [[ ! -f ~/valheim_server/linux64/libpulse-mainloop-glib.so.0 ]]; then
info "Installing libpulse-mainloop-glib.so.0:x86_64"
pushd "$(mktemp -d)"
wget http://mirrors.kernel.org/ubuntu/pool/main/p/pulseaudio/libpulse-mainloop-glib0_15.99.1+dfsg1-1ubuntu1_amd64.deb
dpkg -x libpulse-mainloop-glib0_15.99.1+dfsg1-1ubuntu1_amd64.deb ./ && \
cp usr/lib/x86_64-linux-gnu/libpulse-mainloop-glib.so.0 "/home/$USER/valheim_server/linux64/"
success "Installing libpulse-mainloop-glib.so.0:x86_64 - Done"
popd
fi
else
rm -f "/home/$USER/valheim_server/linux64/libpulse-mainloop-glib.so.0"
fi
# Initialize the Server Credentials file
if [[ ! -f ~/server_credentials ]]; then
info "Generating server_credentials file"
PASSWORD="$(tr -dc "a-zA-Z0-9" < /dev/urandom | fold -w "32" | head -n 1)"
cat <<-EOF > ~/server_credentials && success "Done"
SERVER_NAME="My server"
WORLD_NAME="My World"
# NOTE: Minimum password length is 5 characters & Password cant be in the server name.
PASSWORD="${PASSWORD}"
# If the server should be listed publically. (1=yes, 0=no)
PUBLIC=0
PORT=2456
EOF
success "Generating server_credentials file - Done"
fi
# Update firewall
info "Updating firewall rules"
RULES=(
"INPUT -p udp -m state --state NEW -m udp --dport 2456 -j ACCEPT"
"INPUT -p udp -m state --state NEW -m udp --dport 2457 -j ACCEPT"
"INPUT -p udp -m state --state NEW -m udp --dport 2458 -j ACCEPT"
)
FIREWALL_RULES_ADDED=false
for RULE in "${RULES[@]}"; do
sudo iptables -C ${RULE} 2> /dev/null || \
sudo iptables -I ${RULE} && FIREWALL_RULES_ADDED=true
done
if $FIREWALL_RULES_ADDED; then
sudo cp /etc/iptables/rules.v4{,.bak}
TMP_FILE=$(mktemp)
sudo iptables-save > "${TMP_FILE}"
sudo mv "${TMP_FILE}" /etc/iptables/rules.v4
fi
success "Done"
# Add Valheim helper
info "Creating Valheim Server helper"
mkdir -p /usr/sbin
cat <<-EOF | sudo tee /usr/sbin/valheim_server > /dev/null
#!/bin/bash
# Stop on error
set -e
function show_usage {
echo "Usage: \$(basename \$0) COMMAND"
echo
echo "Commands:"
echo " update Stops and Updates the Valheim server"
echo " start Start the Valheim server"
echo " stop Stops the Valheim server"
echo " restart Restart the Valheim server"
echo " logs Shows the logs of the Valheim server"
echo " logs-live Shows the live logs of the Valheim server"
echo " help Shows this help message"
echo
}
function start_server {
if ! systemctl --user --quiet is-active valheim_server; then
echo "Starting Server..."
systemctl --user start valheim_server
sleep 2 # sleeping to allow service to start up before validating.
systemctl --user --quiet is-active valheim_server && \
echo "Server Started"
else
echo "Server already running"
fi
}
function stop_server {
if systemctl --user --quiet is-active valheim_server; then
echo "Stopping Server, please wait..."
systemctl --user stop valheim_server
echo "Server Stopped"
else
echo "Server already stopped"
fi
}
function restart_server {
stop_server && start_server
}
case \$1 in
update)
stop_server
/home/\${USER}/steamcmd/steamcmd.sh \\
+@sSteamCmdForcePlatformType linux \\
+force_install_dir "/home/\${USER}/valheim_server" \\
+login anonymous \\
+app_update 896660 validate \\
+quit
echo
echo "Server updated."
echo "Start the server with \"valheim_server start\""
;;
start|stop|restart)
\${1}_server;;
logs)
journalctl --user -u valheim_server;;
logs-live)
journalctl --user -f -u valheim_server;;
help|--help|-h|*)
show_usage;;
esac
EOF
sudo chmod +x /usr/sbin/valheim_server
# Set up the Systemd Service
info "Setting up Systemd Service"
mkdir -p ~/.config/systemd/user/
[[ $CROSSPLAY_SUPPORT == true ]] && CROSSPLAY="-crossplay"
# Add servicefile
cat <<-EOF > ~/.config/systemd/user/valheim_server.service
[Unit]
Description=Valheim Dedicated Server
[Service]
KillSignal=SIGINT
TimeoutStopSec=30
Restart=always
RestartSec=5
WorkingDirectory=/home/${USER}/valheim_server
EnvironmentFile=/home/${USER}/server_credentials
Environment=SteamAppId=892970
Environment=LD_LIBRARY_PATH="./linux64:\$LD_LIBRARY_PATH"
ExecStart=/home/${USER}/valheim_server/valheim_server.x86_64 \\
-nographics \\
-batchmode \\
-port "\${PORT}" \\
-public "\${PUBLIC}" \\
-name "\${SERVER_NAME}" \\
-world "\${WORLD_NAME}" \\
-password "\${PASSWORD}" \\
${CROSSPLAY} \\
-savedir "/home/${USER}/valheim_data"
[Install]
WantedBy=default.target
EOF
# Enable Lingering Systemd user sessions
loginctl enable-linger
# Reload Systemd
systemctl --user daemon-reload
# Enable Valheim Systemd service allowing it to start automatically on boot
systemctl --user enable valheim_server.service && success "Setting up Systemd Service - Done"
info "Creating Readme"
cat <<-EOF > ~/Readme.md && success "Creating Readme - Done"
# Valheim Server Helper Commands
## Help
valheim_server help
## Start server
valheim_server start
## Stop server
valheim_server stop
## Updating the server
valheim_server upgrade
# Enable / Disable crossplay
This can be accomplished by re-running the setup script.
It will ask you of you want crossplay enabled or disabled.
EOF
# Start the Valheim Systemd service
success "Setup finished"
echo "A file named 'server_credentials' have been placed in the home directory"
echo "Edit as you see fit with f.ex 'nano ~/server_credentials'"
echo "Within nano, when done editing, press 'Ctrl+X', then 'y', finally 'Enter'"
echo
echo "Finally, to start the server, the following command can be used:"
echo " valheim_server start"
echo
echo "A readme with additional commands have also been placed in the home directory"
}
if [ `id -u` -eq 0 ]; then
error Please run this script as a regular user.
exit 1
fi
perform_self_update
# Pinned versions for Box 64 / 86
BOX64_VERSION="${BOX64_VERSION:-v0.2.6}"
BOX86_VERSION="${BOX86_VERSION:-1e749beb2e84401344337b2f3865f156a667d946}"
main | tee install_valheim_server.log
@RaDiKalDev
Copy link

Trying to enable crossplay as we have a new player joining us that is xbox based. Here's the sequence:

  1. Ran the installer which updated the script
  2. Ran the installer again and specified yes for crossplay; box was updated
  3. Ran the installer yet again and specified yes for crossplay; libpulse appeared to be installed
  4. Restarted the server but fails during PlayFab initialization (line 2327 in the log)
  5. GIST: https://gist.github.com/RaDiKalDev/24adff709f5986e498636a15eae2323d
  6. Note that this server has been running fine for quite awhile.
    -Ron

@husjon
Copy link
Author

husjon commented Jun 1, 2024

@RaDiKalDev it's really weird that it keeps complaining about libpulse as it should be available.
This seem to happen even if crossplay is not explicitly enabled, but crossplay seem to be heavily dependent on it.
I'm gonna have to look into it further as the way we've done it so far hasn't been the best.
Crossplay is still unfortunately flagged as experimental, see https://gist.github.com/husjon/c5225997eb9798d38db9f2fca98891ef#crossplay-console--game-pass

@RaDiKalDev
Copy link

@RaDiKalDev it's really weird that it keeps complaining about libpulse as it should be available. This seem to happen even if crossplay is not explicitly enabled, but crossplay seem to be heavily dependent on it. I'm gonna have to look into it further as the way we've done it so far hasn't been the best. Crossplay is still unfortunately flagged as experimental, see https://gist.github.com/husjon/c5225997eb9798d38db9f2fca98891ef#crossplay-console--game-pass

Understood. This is my test server instance, so I'm fine messing with it. I understand some folks have gotten this to work and am wondering if it is due to my having initially installed under a much earlier script (prior to the crossplay bits being added). If you come up with anything to try, I'm happy to experiment.

-Ron

@husjon
Copy link
Author

husjon commented Jun 1, 2024

I've decided to add my discord server to the guide for troubleshooting, see #discord

Hope to see you there.

@husjon
Copy link
Author

husjon commented Jun 1, 2024

@RaDiKalDev it's really weird that it keeps complaining about libpulse as it should be available. This seem to happen even if crossplay is not explicitly enabled, but crossplay seem to be heavily dependent on it. I'm gonna have to look into it further as the way we've done it so far hasn't been the best. Crossplay is still unfortunately flagged as experimental, see https://gist.github.com/husjon/c5225997eb9798d38db9f2fca98891ef#crossplay-console--game-pass

Understood. This is my test server instance, so I'm fine messing with it. I understand some folks have gotten this to work and am wondering if it is due to my having initially installed under a much earlier script (prior to the crossplay bits being added). If you come up with anything to try, I'm happy to experiment.

-Ron

Ah good to know, so far I've not yet done much with crossplay, but I do hope that we do get it a somewhat stable state at some point :)

@RaDiKalDev
Copy link

RaDiKalDev commented Jun 2, 2024

@RaDiKalDev it's really weird that it keeps complaining about libpulse as it should be available. This seem to happen even if crossplay is not explicitly enabled, but crossplay seem to be heavily dependent on it. I'm gonna have to look into it further as the way we've done it so far hasn't been the best. Crossplay is still unfortunately flagged as experimental, see https://gist.github.com/husjon/c5225997eb9798d38db9f2fca98891ef#crossplay-console--game-pass

Understood. This is my test server instance, so I'm fine messing with it. I understand some folks have gotten this to work and am wondering if it is due to my having initially installed under a much earlier script (prior to the crossplay bits being added). If you come up with anything to try, I'm happy to experiment.
-Ron

Ah good to know, so far I've not yet done much with crossplay, but I do hope that we do get it a somewhat stable state at some point :)

I see that I've been running all of this as root and using sudo bash ./setup_valheim_server.sh This may contribute to Playfab (crossplay) not being found during startup. I'll look at a reinstall on my test server with a non-system/non-root user established first.

The setup instructions do not include creating a non-root user before running the install script but I see you referring to that in these postings.

@husjon
Copy link
Author

husjon commented Jun 2, 2024

That could be.

I've added a check for the script to see if it's being run as root or with sudo, you do however need to update it for it to take effect. :)

@RaDiKalDev
Copy link

RaDiKalDev commented Jun 2, 2024

That could be.

I've added a check for the script to see if it's being run as root or with sudo, you do however need to update it for it to take effect. :)

Nice. Recognizing that I'm logged in as user ubuntu by default, the bash ./setup_valheim_server.sh fails on permission:

ubuntu@vh:~$ bash ./setup_valheim_server.sh
bash: ./setup_valheim_server.sh: Permission denied
ubuntu@vh:~$

valhiem_server start executes fine.

Not sure what needs to be done to enable permission. Would that be chmod u+x setup_valheim_server.sh?

@husjon
Copy link
Author

husjon commented Jun 2, 2024

Not sure what needs to be done to enable permission. Would that be chmod u+x setup_valheim_server.sh?

Since bash didn't have permission to run it, it might be missing read permissions, since you mentioned that you used root previously, check the owner of the file and change it to the ubuntu user, run sudo chown ubuntu:ubuntu ./setup_valheim_server.sh

@RaDiKalDev
Copy link

Not sure what needs to be done to enable permission. Would that be chmod u+x setup_valheim_server.sh?

Since bash didn't have permission to run it, it might be missing read permissions, since you mentioned that you used root previously, check the owner of the file and change it to the ubuntu user, run sudo chown ubuntu:ubuntu ./setup_valheim_server.sh

Worked perfectly.

This also addressed the issue with Playfab not working. Got a Playfab connection code on server startup. I connected via Steam as usual and that worked fine. I've passed the code to our Xbox buddy to give it a try and will update when I get evidence one way or the other.

-Ron

@RaDiKalDev
Copy link

Update on crossplay (Playfab):

Had three Steam players and one Xbox player join a crossplay enabled world running Box64 2.6. Things ran fine for about 10 minutes and then we all experience a flashing lag icon notification and while we could move about, we could not interact with the world (open/close trunks). After about 3 minutes, we were all kicked off. Server continued to be available at the existing connection code but looking at the logs, it crashed and restarted:

=================================================================
Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
=================================================================
Native stacktrace:
=================================================================
0x7fff031151fe - /home/ubuntu/valheim_server/valheim_server_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so : mono_breakpoint_clean_code
0x7fff030bded9 - /home/ubuntu/valheim_server/valheim_server_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so : mono_unity_backtrace_from_context
0x7fff03110bdd - /home/ubuntu/valheim_server/valheim_server_Data/MonoBleedingEdge/x86_64/libmonobdwgc-2.0.so : mono_breakpoint_clean_code
0x7fff0e6fa440 - /home/ubuntu/valheim_server/valheim_server_Data/Plugins/libparty.so : _Z11DbgLogBytesPKcmPKv
0xffff3803a600 - Unknown
=================================================================
Telemetry Dumper:
=================================================================
Could not exec mono-hang-watchdog, expected on path '/home/ubuntu/valheim_server/valheim_server_Data/MonoBleedingEdge/etc/../bin/mono-hang-watchdog' (errno 2)
vh systemd[991]: valheim_server.service: Main process exited, code=killed, status=6/ABRT
vh systemd[991]: valheim_server.service: Failed with result 'signal'.
vh systemd[991]: valheim_server.service: Scheduled restart job, restart counter is at 1.
vh systemd[991]: Stopped Valheim Dedicated Server.
vh systemd[991]: Started Valheim Dedicated Server.

@RaDiKalDev
Copy link

RaDiKalDev commented Jun 3, 2024

I'll look at getting v2.8 of Box64 up and running and give it another try later in the week

Note: I'm posting updates into the Discord (Box64 v2.8 on Ubuntu wr.04.4 LTS isn't stable even w/out crossplay enabled).

@dsadsadwasdas
Copy link

Hi, the Discord link seems to be invalid; I have been trying to get the server working for crossplay (me and my friends play Valheim in Xbox) for days now. It seems like the server cannot establish a connection to PlayFab. (Logs: https://gist.github.com/dsadsadwasdas/4c97260b3cfc1b4a94c78fb95d902235)

I have tried changing Box64 versions from 0.24 to 0.28 (though I'm not sure if this is related or not), but that didn't seem to fix the issue. I don't know if this is duplicated but I have read through this entire thread and seems like no one here had the same problem as mine.

Thank you for your assistance.

@husjon
Copy link
Author

husjon commented Jun 13, 2024

Hi @dsadsadwasdas sorry about that, I had forgotten to set the link to not expire (was set to only 7 days).
Here's the invite new link https://discord.gg/ExnzM4E7pE

@marciz34
Copy link

marciz34 commented Oct 8, 2024

is there a way to use an android ssh app instead of putty if im going to be away from my pc?

@husjon
Copy link
Author

husjon commented Oct 8, 2024

Hey @marciz34, absolutely, in my case I've been using JuiceSSH on android.
Just provide the server ip / address + username and password (or public / private key) when connecting and everything else should be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment