Skip to content

Instantly share code, notes, and snippets.

@dhensby
Last active October 2, 2022 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dhensby/c2f202247685b792ff84ede52d1fba6a to your computer and use it in GitHub Desktop.
Save dhensby/c2f202247685b792ff84ede52d1fba6a to your computer and use it in GitHub Desktop.
Unattended provisioning of CS:GO LinuxGSM cloud server using Cloud Init / User Data

CS:GO LinuxGSM Server with Cloud Init

This cloud-init config will provision a CS:GO server using LinuxGSM without the need for any manual intervention.

Usage

When provisioning a cloud server with providers such as Digital Ocean, you can provide "user data" to help provision cloud servers.

This configuration allows you to make use of the "user data" to automatically provision the CS:GO server.

How to

  1. Obtain a Game Server Login Token from Steam
  2. Copy the cloud-init.yml file and replace the GSLT value with your token from step 1
  3. Replace the PASSWORDHERE with a password of your choice (or remove the line if you don't want a password for your server)
  4. (optional) change the hostname to something you like
  5. Create a VM with at least 50GB of disk space in a region geographically near you, and paste you cloud-config.yml file into the user data box when prompted

The server will start provisioning. The provisioning process takes about 30 minutes (depending on the speed of your server and network connection), so be patient.

You can SSH into the server execute $ tail -f /var/log/cloud-init-output.log to see the realtime output during the server provisioning.

When the server is provisioned, you can ssh into the server and check it is running using $ systemctl status csgoserver or you can see more information about the game server by running $ su csgo -c 'bash /home/csgo/csgoserver details'

RCON login

To login to the server and use rcon commands, you will need the rcon password. This can be found by performing the following command on the server:

$ su csgo -c 'bash /home/csgo/csgoserver details | grep "RCON password"'

Info on using RCON can be found here: https://www.clanwarz.com/payments/knowledgebase/490/How-To-Use-Your-Rcon-Password-In-Your-CSGO-Game-Server.html

#cloud-config
# Resources:
# https://linuxgsm.com/lgsm/csgoserver/ - general installation and set-up
# https://steamcommunity.com/dev/managegameservers - get an auth token for your server
# https://docs.linuxgsm.com/game-servers/counter-strike-global-offensive - extra detais / settings eg: 128-tick server
#
# Once this VM is provisioned, the CSGO server should be running.
# It will also run on server start/reboot and will automatically attempt to update itself when started - this is useful if booting from a snapshot
# stop the server using `systemctl stop csgoserver`
# start the server using `systemctl start csgoserver`
# restart the server using `systemctl restart csgoserver`
users:
- name: csgo
sudo: False
lock_passwd: true
shell: /bin/bash
runcmd:
- [ufw, default, deny, incoming]
- [ufw, default, allow, outgoing]
- [ufw, allow, '22']
- [ufw, allow, '27015']
- [ufw, allow, '27020/udp']
- [ufw, enable]
- [ufw, reload]
- [runuser, -l, csgo, -c, 'curl -sSL https://linuxgsm.sh -o /home/csgo/linuxgsm.sh']
- [runuser, -l, csgo, -c, 'cd /home/csgo && bash /home/csgo/linuxgsm.sh csgoserver']
- [runuser, -l, csgo, -c, 'cd /home/csgo && bash ./csgoserver auto-install']
- [bash, /home/csgo/csgoserver, auto-install] # running this as root installs server dependencies, but it has to run after the non-root user tries to install
- [runuser, -l, csgo, -c, 'cd /home/csgo && bash ./csgoserver auto-install']
# set GSLT here - https://steamcommunity.com/dev/managegameservers
- printf 'gslt="TOKENHERE"' >> /home/csgo/lgsm/config-lgsm/csgoserver/secrets-csgoserver.cfg
- printf "tickrate=\"128\"\n" >> /home/csgo/lgsm/config-lgsm/csgoserver/csgoserver.cfg
- printf "updateonstart=\"on\"\n" >> /home/csgo/lgsm/config-lgsm/csgoserver/csgoserver.cfg
# set max players here
- printf "maxplayers=\"32\"\n" >> /home/csgo/lgsm/config-lgsm/csgoserver/csgoserver.cfg
- printf "// force 128 tick server\nsv_mincmdrate 128\nsv_minupdaterate 128\n" >> /home/csgo/serverfiles/csgo/cfg/csgoserver.cfg
# set server name here
- [sed, -i, 's/hostname ".*"/hostname "CS:GO Server"/g', /home/csgo/serverfiles/csgo/cfg/csgoserver.cfg]
# set server password here
- [sed, -i, 's/sv_password ".*"/sv_password "PASSWORDHERE"/g', /home/csgo/serverfiles/csgo/cfg/csgoserver.cfg]
- [systemctl, enable, csgoserver]
- [systemctl, start, csgoserver]
write_files:
# cron jobs for keeping the server up-to-date
- content: |
*/5 * * * * csgo /home/csgoserver/csgoserver monitor > /dev/null 2>&1
*/30 * * * * csgo /home/csgoserver/csgoserver update > /dev/null 2>&1
0 0 * * 0 csgo /home/csgoserver/csgoserver update-lgsm > /dev/null 2>&1
path: /etc/cron.d/csgoserver
defer: true
- content: |
[Unit]
Description=LinuxGSM CSGO Serveri
After=network-online.target
Wants=network-online.target
[Service]
Type=forking
User=csgo
WorkingDirectory=/home/csgo
RemainAfterExit=yes #Assume that the service is running after main process exits with code 0
ExecStart=bash /home/csgo/csgoserver start
ExecStop=bash /home/csgo/csgoserver stop
Restart=no
[Install]
WantedBy=multi-user.target
path: /etc/systemd/system/csgoserver.service
defer: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment