Markasium CS2 sheetSheet Note N1 · Sheet 07 TR / EN

Note N1 · Markasium CS2

EIGHT MODES, ONE SERVER

Switching game modes on a CS2 server: change plugins with a restart, not at runtime

Sheet
MARKASIUM CS2
Topic
CS2 · CounterStrikeSharp · Bash
Source
scripts/set-mode.sh
Date
2026-11-12
Reading
3 min

Short answer: when changing the game mode on a CS2 server, don't load and unload plugins on the running server. Stop the server, leave only the target mode's plugins in the active folder, write the config file atomically and start the server again; don't call the job done until you see the server listening on its port. This way public, retake, deathmatch, AWP, aim, 5v5 match, 1v1 arena and jailbreak all run from the same install.

01Why not at runtime

The Markasium CS2 server runs eight official modes on a single CS2 process. Each mode has its own plugin: RetakesPlugin for retake, MatchZy for matches, K4-Arenas for arena, Jailbreak for jailbreak. CounterStrikeSharp allows loading plugins at runtime, but on CS2 this is not reliable: an unloaded plugin's registered events, timers or changed settings can be left behind.

So a mode switch is a restart. A few seconds of downtime is cheaper than a half-unloaded plugin crashing the server mid-match.

02Stopping

If the server is installed as a systemd user service, the service is stopped; otherwise the CS2 process and the launcher script are found with pgrep and sent SIGTERM. Processes started by hand or left orphaned while the service was down are caught by the same scan.

for i in $(seq 1 20); do
    pgrep -f -- "^${GAME_DIR}/bin/linuxsteamrt64/cs2 .*dedicated" >/dev/null || break
    sleep 1
done
# SIGKILL if it hasn't stopped in 20 seconds

Shutdown is limited to 20 seconds. CS2 sometimes crashes on shutdown, a known issue; the script doesn't wait for it, kills the process when time runs out and removes the old pid file.

03Swapping the plugin set

Every plugin is a folder. Active ones sit under plugins/, disabled ones under plugins/disabled/; a mode switch moves folders between the two. Plugins to disable are moved first, then the ones to enable. The operation can be rerun: a plugin already in place is skipped as "already active", a missing folder is skipped with a warning.

The list for the eight official modes is fixed in the script. Other modes (bhop, surf, kz, gungame...) are read from modes/<mode>/manifest.json and follow one rule:

to disable = this mode's disablePlugins
           ∪ every other mode's enablePlugins
           − this mode's enablePlugins

So adding a new mode needs no change to the other modes' lists: another mode's plugin switches off on its own when that mode isn't active. The map voting plugin (RockTheVote) is off in every mode; AllInOneCore does the voting itself.

04Writing the config atomically

AllInOneCore's config file also holds the database password. A mode switch only changes the default mode in it; if the file were left half-written, the server would not start. It is written to a temporary file in the same folder and swapped into place in one move:

fd, tmp = tempfile.mkstemp(prefix=".aio-", dir=os.path.dirname(path))
with os.fdopen(fd, "w", encoding="utf-8") as fh:
    json.dump(data, fh, indent=2, ensure_ascii=False)
os.chmod(tmp, 0o600)
os.replace(tmp, path)   # atomic on the same file system

The password is never printed or logged; the file and the .mode file holding the chosen mode are 0600.

05Proving the job is done

"I started it" is not enough. The script waits up to 60 seconds for the server to listen on UDP 27015; if it doesn't, it fails and prints the last 30 lines of the latest server log. So that back-to-back mode switches don't hit systemd's restart limit, systemctl --user reset-failed runs before starting.

At the end the active and disabled plugins are listed; which plugins run in which mode is visible at a glance.

06Mode-specific details

  • In jailbreak, team models are copied from a template; in other modes that file is removed and players' own model choices apply.
  • The mode name is lowercased and only [a-z0-9_-] is allowed; the common folder cannot be chosen as a mode.
  • Plugin names read from a manifest go into an array (mapfile), not a shell variable; a name with spaces or special characters is not split.

→More notes from this project

—End of notewritten by MUHAMMEDPYZ