ThirdBlog-Top

Thursday, July 2, 2015

And on Linux?


ON LINUX:

Linux Dedicated Server Hosting

This article will handle as many aspects as possible about hosting a Garry's Mod server on Linux.

This article has been written for Debian and derivatives (Ubuntu, ChromiumOS, Mint...) so you may need to do some conversion on other distributions

Notice

Valve appear to have used Ubuntu 12.04 32-bit as their main development environment. This means that if you do exactly the same and use Ubuntu Server 12.04 32-bit, you will have fewer nasty surprises. You can of course use a newer version of Ubuntu and that should also work since it is backwards-compatible.
This guide is written with any Debian-based distribution in mind - but can be simplified if you just use the same system that Valve used (you won't have to install extra compatibility libraries).
Requirements

Make sure you meet the following requirements before you begin:

A user to run the server as ('steam' is recommended, with home directory /home/steam)
Enough disk space for the content you wish to install
An open command-line terminal running as the user 'steam' (su - steam) or an SSH session with steam as logged in user.
Experience with basic Linux command-line usage.

Installing SteamCMD

The following script will download SteamCMD, extract it and update it. SteamCMD is needed to download and update garrysmod.

cd ~
mkdir bin
cd bin
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar -xvzf steamcmd_linux.tar.gz
./steamcmd.sh +login anonymous +quit
Installing Garry's Mod

The following script will download the latest version of Garry's Mod for you with a single command.

We are using the text editor nano for this, but you can use your own if you prefer a different editor.

First, lets go to our home directory.

cd ~
To create the script, use your preferred text-editor tool. In this example, we are using "nano", but any other such as "vi", "vim", "pico" or "emacs" will also work.

$ nano update_gmod.sh
Paste the following script in nano:

# !/bin/bash

# A convenience function, to save us some work
update_server() {
                # Read the app id and the directory into a variable

                APP_ID=$1
                DIR=$2

                # Create the directory ( if it does not exist already )
                if [ ! -d "$HOME/$DIR" ]; then
                                mkdir -p "$HOME/$DIR"
                fi

                # Uh-oh, it looks like we still have no directory. Report an error.
                if [ ! -d "$HOME/$DIR" ]; then
                                # Describe what went wrong
                                echo "ERROR! Cannot create directory $HOME/$DIR!"

                                # Exit with status code 1 ( which indicates an error )
                                exit 1
                fi

                # Call SteamCMD with the app ID we provided and tell it to install
                ./bin/steamcmd.sh +login anonymous +force_install_dir "$HOME/$DIR" +app_update $APP_ID validate +quit
}

# Now the script actually runs update_server ( which we just declared above ) with the id of the application ( 4020 is Garry's Mod ) and the name of the directory we want the server to be hosted from:

update_server 4020 "server_1"

# Add any additional servers here by repeating the above, but using a different directory name.

# Exit with status code 0 ( which means OK )
exit 0
Now we save the file. In nano, saving a file is done by pressing Ctrl+O, followed by Enter. Now we close the file by pressing Ctrl+X.

Before we can run this file, we need to give it 'execute' rights. This is done with the following command:

chmod +x ./update_gmod.sh
Now, lets update the server

./update_gmod.sh
If you get "*/linux32/steamcmd: No such file or directory" error, this is most likely because you do not have the required 32-bit libraries. Go here for more information on how to fix this: https://developer.valvesoftware.com/wiki/SteamCMD#32-bit_libraries_on_64-bit_Linux_systems

The server will now download the necessary content. Steam will show you the percentage of progress it is making with the download.


No comments:

Post a Comment