Linux Dedicated Server Hosting

From Garry's Mod
Jump to: navigation, search

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 derratives (Ubuntu, ChromiumOS, Mint...) so you may need to do some conversion on other distributions

Contents

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
  • A terminal running as steam (su - steam) or an SSH session with steam as logged in user.
  • Basic knowledge of Linux


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, open nano and create the file update_gmod.sh

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 doesn't exist
 	if [ ! -d "$DIR" ]; then
 		mkdir "$DIR"
 	fi
 
 	#Uh-oh, looks like we didn't create the directory. Stop
 	if [ ! -d "$DIR" ]; then
 		#Tell what went wrong
 		echo "ERROR! Cannot create $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 "$DIR" +app_update $APP_ID validate +quit
 }
 
 #Call update_server with the app id (4020 is Garry's Mod) andthe folder we want the server in
 update_server 4020 "~/server_1"
 #Add any additional servers here, repeat the line above, but change the directory.
 
 #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

The server will now download, this might take a while.

Adding content

Of course, we want to be able to use stuff from Team Fortress 2, Counter-Strike: Source and other supported games. Using the script above, this is simple process.

However, since we want to save on download time, we are going to put all this content in a seperate folder, so if we have 5 servers, we only need to update the content once if a content update gets released.

Let's create a directory for our content

mkdir content

Now we are going to modify the script mentioned [#Getting_Garry.27s_Mod above]. Add the following line where it says "Add any additional servers here". Here, we add Team Fortress 2.

update_server 232250 "~/content/tf2"

Now, when we run update_gmod.sh the script will verify (and, if required, update) Garry's Mod (since we downloaded it in the step above) and then install Team Fortress 2 in ~/content/tf2.

For a list of IDs for the servers, you can have a look at the Valve Developer Community page.

Starting the server

To start the server, we run the file called srcds_run, which is located in the root directory of each server. The command below starts the server with 12 slots on gm_flatgrass.

~/server_1/srcds_run -game garrysmod +maxplayers 12 +map gm_flatgrass

The script (srcds_run) will keep the server alive, should it crash, but it won't restart when you restart linux and if you close the terminal the server will close. We will fix this later on in this article.

Updating the server

To update the server, or to update the content, we simply call our download script. You need to make sure your servers are off, or else the update will fail.

Update our scripts by just calling this (from the home directory)

./update_gmod.sh

Keeping the server alive after a reboot

To keep the server alive we use crontab. We add an entry to crontab which will call srcds_run when the server has loaded.

Open crontab

crontab -e

Now, add the following line at the end

@reboot /home/steam/server_1/srcds_run -game garrysmod +maxplayers 12 +map gm_flatgrass

Now save the file. Usually crontab opens in nano so the commands would, again, be Ctrl+O, ↵ Enter, Ctrl+X.

Now, after you reboot the linux server, the Garry's Mod Server will auto start.

Additional notes

Of course, there are better ways of keeping your server alive, but they can become quite complex in no-time so they are not discussed here. If you want to know more, Google around or ask on Facepunch.

Troubleshooting

32-bit binaries

If you're running a 64-bit version of Linux, you need 32 bit binaries, since SteamCMD is only available as 32 bit.

If you get the error message

 ./steamcmd.sh: line 29: /home/$USER/Steam/linux32/steamcmd: No such file or directory

You are most likely running 64 a bit system and missing 32 bit libraries.

To do so, you need to install ia32-libs. To do so, run the following bit of code:

dpkg --add-architecture i386
apt-get update
apt-get install ia32-libs

The package is big (~200MB isn't uncommon) and has a lot of dependancies so it may take some time.

For other linux distrubutions, see the Valve wiki article

Personal tools
Navigation