Skip to content

Instantly share code, notes, and snippets.

@kasymovga
Last active July 10, 2022 16:46
Show Gist options
  • Save kasymovga/e3da7003a5d7933f69601597e5dba4c3 to your computer and use it in GitHub Desktop.
Save kasymovga/e3da7003a5d7933f69601597e5dba4c3 to your computer and use it in GitHub Desktop.
Rexuiz multi-instance server setup

Requirements:

  • Any modern linux distribution with systemd (CentOS Stream, Oracle Linux 8, Ubuntu 18.04, Ubuntu 20.04, Ubuntu 22.04).
  • Public IP address
  • Basic skills of working with linux console

Step 0. Prepare your system

Disable or setup firewall. For CentOS:

sudo systemctl stop firewalld
sudo systemctl disable firewalld

For Ubuntu:

sudo systemctl stop ufw
sudo systemctl disable ufw

In case of other linux distros check their documentation.

For CentOS you will need disable SELinux:

sudo setenforce 0
sudo sed -i s/SELINUX=enforcing/SELINUX=disabled/ /etc/selinux/config

Also for CentOS you will need enable EPEL repository:

sudo yum install epel-release

Step 1. Install screen and curl

For CentOS-like systems:

sudo yum install screen curl

For Debian-like systems:

sudo apt-get install screen curl

Step 2. Create user

sudo useradd -s /bin/bash -U -m rexuiz

Step 3. Install rexuiz

sudo -u rexuiz curl https://raw.githubusercontent.com/kasymovga/rexuiz/master/scripts/update.sh --output /home/rexuiz/rexuiz_install.sh
sudo -u rexuiz bash /home/rexuiz/rexuiz_install.sh /home/rexuiz/Rexuiz/
sudo -u rexuiz chmod 755 /home/rexuiz/Rexuiz/server/rexuiz-linux-dedicated-x86_64

Step 4. Create systemd unit

Open /etc/systemd/system/rexuiz.service with you preferred text editor (nano in example):

sudo nano /etc/systemd/system/rexuiz@.service

Write this content in file:

[Unit]
Description=rexuiz
After=network.target
[Service]
#Environment=REXUIZ_NOUPDATE=1
#Environment=REXUIZ_LOGDIR=/home/rexuiz/%i/
#Environment=REXUIZ_SYSLOG=%i
Environment=REXUIZ_UPDATE_HOOK=/home/rexuiz/rexuiz_update_hook.sh
User=rexuiz
Group=rexuiz
ExecStart=/usr/bin/screen -DmS rexuiz%i /bin/sh /home/rexuiz/Rexuiz/server/rexuiz-linux-dedicated-x86_64 -userdir /home/rexuiz/%i/
ExecStop=/usr/bin/screen -p 0 -S rexuiz%i -X eval 'stuff "quit"\015'
Restart=always
[Install]
WantedBy=multi-user.target

Save file and close editor (ctrl-o and ctrl-x in nano, look man nano for details).

Step 5. Create update hook

Open /home/rexuiz/rexuiz_update_hook.sh with you preferred text editor (nano in example):

sudo -u rexuiz nano /home/rexuiz/rexuiz_update_hook.sh

Write this content in file:

#!/bin/sh

update_cmd() {
        screen -p 0 -S "$1" -X eval 'stuff "quit_when_empty 1"\015'
}

sessions=$(screen -ls | tail -n +2 | head -n -1 | cut -f 2 | cut -d . -f 2 | grep rexuiz)
for S in $sessions
do
        update_cmd "$S"
done

Make file executable:

sudo -u rexuiz chmod 755 /home/rexuiz/rexuiz_update_hook.sh

Step 6. Create instance

Name of instance will be "test" in this example.

Copy and edit example config file:

sudo -u rexuiz mkdir -p /home/rexuiz/test/data
sudo -u rexuiz cp /home/rexuiz/Rexuiz/data/server-example.cfg /home/rexuiz/test/data/server.cfg
sudo -u rexuiz nano /home/rexuiz/test/data/server.cfg

Be sure that each instance use different port! Better use port with value much higher than default (26100 for example).

Step 7. Run your instance

Start systemd service:

sudo systemctl enable rexuiz@test
sudo systemctl start rexuiz@test

Use this command if you need access to server console:

sudo -u rexuiz script -q -c 'screen -r rexuiztest' /dev/null

If you login as rexuiz user, you can use just:

sudo -u rexuiz screen -r rexuiztest

Press CTRL-A and when d to leave server console.

Look man screen for details.

Repeat steps 6-7 for each instance.

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