Skip to main content

Overview

Templates in GamePanelX V3 are compressed archives of game server files that enable rapid server deployment. The CreateTemplate script packages server directories into reusable templates.

What Are Templates?

Templates are .tar.gz archives stored in ~/templates/ containing:
  • Game server binaries
  • Configuration files
  • Maps and assets
  • Any customizations or mods
Each template is identified by a unique ID and can be used to create multiple server instances.

Creating Templates

The CreateTemplate script is located at ~/_SERVERS/scripts/CreateTemplate.

Basic Usage

./CreateTemplate -p tmp/mygame -i 23
This creates a template from ~/tmp/mygame with ID 23, resulting in ~/templates/23.tar.gz.

Command-Line Parameters

-p
string
required
File PathPath to the directory containing the server files, relative to $HOME.Example: tmp/mygame refers to ~/tmp/mygame
-i
string
required
Template IDUnique identifier for the template. Used for the output filename: {id}.tar.gz
-u
string
Callback URLURL to notify about template creation status. Receives status updates as the template is created.
-s
string
From SteamSet to yes if this template is being created from a SteamCMD download. Enables automatic cleanup of source files.
-d
string
Debug ModeEnable debug output for troubleshooting template creation.

Template Creation Process

1

Validation

Validates that:
  • Required parameters (-p, -i) are provided
  • Source directory exists at ~/{file_path}
  • Directory is not empty
2

Started Callback

If a callback URL is provided:
{callback_url}&do=tpl_status&status=started
3

Archive Creation

Creates a compressed tar archive:
cd ~/{file_path}
tar -czf ~/templates/{template_id}.tar.gz * &
The tar process ID is saved to ~/templates/.gpx_{template_id} for monitoring.
4

Progress Monitoring

A background loop checks every 3 seconds if the tar process has completed.
5

Completion Callback

When archiving finishes, sends a callback with the template size:
{callback_url}&do=tpl_status&status=complete&size={size}
Where {size} is the human-readable size (e.g., “1.2G”, “500M”).
6

Cleanup (Optional)

If -s yes was specified (Steam template), removes the original source directory:
rm -fr ~/{file_path}
This is safe because the template source was in ~/tmp/{template_id} from a SteamCMD download.

Template Storage

Templates are stored in a standardized location:
~/templates/
├── 1.tar.gz                    # Template ID 1
├── 2.tar.gz                    # Template ID 2
├── 23.tar.gz                   # Template ID 23
├── .gpx_1                      # Tracking file for template 1
└── .gpx_23                     # Tracking file for template 23

Tracking Files

During creation, temporary tracking files (.gpx_{id}) store the tar process PID. These files are used to monitor creation progress.

Using Templates to Create Servers

Once a template is created, use it with the CreateServer script:
./CreateServer -u user123 -i 192.168.10.10 -p 27015 -x 23
The -x 23 parameter references template ID 23 (~/templates/23.tar.gz).
See Creating Servers for detailed information on deploying servers from templates.

Creating Templates from SteamCMD

A common workflow is downloading game files via SteamCMD and creating a template:
1

Download Game Files

Use SteamCMD to download game server files to a temporary directory:
mkdir -p ~/tmp/23
cd ~/tmp/23
./steamcmd.sh +login anonymous \
  +force_install_dir $(pwd) \
  +app_update 232330 validate \
  +quit
2

Create Template

Package the downloaded files into a template:
~/scripts/CreateTemplate -p tmp/23 -i 23 -s yes
The -s yes flag ensures the temporary directory is cleaned up after template creation.
3

Deploy Servers

Use the new template to create servers:
~/scripts/CreateServer -u user1 -i 192.168.1.10 -p 27015 -x 23

Template Creation Workflow

Manual File Preparation

For custom server configurations or modded servers:
  1. Prepare Source Directory
    mkdir -p ~/tmp/custom_server
    # Copy/configure your server files
    cp -r /source/gameserver/* ~/tmp/custom_server/
    
  2. Customize Server
    • Edit configuration files
    • Add mods or plugins
    • Set default settings
    • Add custom maps
  3. Create Template
    ~/scripts/CreateTemplate -p tmp/custom_server -i 42 \
      -u "https://panel.example.com/callback.php?id=42"
    
  4. Verify Template
    ls -lh ~/templates/42.tar.gz
    

From Existing Server

Create a template from a running server’s directory:
# Copy existing server to temp location
cp -r ~/accounts/user123/192.168.1.100.27015 ~/tmp/template_source

# Clean up runtime files
rm -f ~/tmp/template_source/.gpx*
rm -f ~/tmp/template_source/*.log

# Create template
~/scripts/CreateTemplate -p tmp/template_source -i 50

Status Callbacks

When a callback URL is provided with -u, the script sends HTTP requests at key stages:
StatusWhen TriggeredAdditional Data
startedTemplate creation beginsNone
completeArchive creation finishedsize={human_readable_size}
failedError occurredNone
Callback format:
{callback_url}&do=tpl_status&status={started|complete|failed}&size={size}

Example Callback URLs

https://panel.example.com/callback.php?id=23&do=tpl_status&status=started
https://panel.example.com/callback.php?id=23&do=tpl_status&status=complete&size=1.2G
https://panel.example.com/callback.php?id=23&do=tpl_status&status=failed

Logging

Template creation is logged to ~/logs/templates.log:
CreateTemplate: (2026-03-05 10:30:15) Connecting to callback URL ...
CreateTemplate: (2026-03-05 10:30:15) Beginning archive of template directory (~/tmp/mygame) ...
CreateTemplate: (2026-03-05 10:30:16) Archive of template directory started (Script PID 12345, tar PID 12346) ...
CreateTemplate: (2026-03-05 10:35:42) Archive creation completed
CreateTemplate: (2026-03-05 10:35:42) Running callback url for completed
CreateTemplate: (2026-03-05 10:35:43) Completed removal of original template files

Examples

# Create template from directory
./CreateTemplate -p tmp/csserver -i 10

Template Management

Listing Templates

# List all templates with sizes
du -sh ~/templates/*.tar.gz

Inspecting Template Contents

# View contents without extracting
tar -tzf ~/templates/23.tar.gz | less

# Extract to inspect
mkdir ~/tmp/inspect
tar -xzf ~/templates/23.tar.gz -C ~/tmp/inspect/

Deleting Templates

# Remove a template
rm ~/templates/23.tar.gz
rm ~/templates/.gpx_23  # If it exists

Template Versioning

Implement a versioning scheme for templates:
# Version 1.0
./CreateTemplate -p tmp/csserver -i 100

# Version 1.1 (after updates)
./CreateTemplate -p tmp/csserver_v1.1 -i 101

# Version 2.0 (major changes)
./CreateTemplate -p tmp/csserver_v2.0 -i 200

Error Handling

Common Issues:
  • Directory not found: Source directory doesn’t exist at ~/{file_path}
  • Empty directory: Cannot create template from empty directory
  • Insufficient space: Not enough disk space in ~/templates/
  • Permission denied: Check write permissions on ~/templates/

Validation Errors

The script exits immediately if:
CreateTemplate: Required settings were left out. Exiting.
  • Missing -p or -i parameters
CreateTemplate: That directory was not found (~/path/to/dir)! Exiting.
  • Source directory doesn’t exist
CreateTemplate: Failed: Template directory (~/path/to/dir) is empty. Exiting.
  • Source directory exists but contains no files

Best Practices

  1. Unique IDs: Use meaningful, unique template IDs
  2. Documentation: Maintain a list of templates with descriptions
  3. Clean Source: Remove logs, PIDs, and runtime files before creating templates
  4. Test First: Test server configurations before creating templates
  5. Versioning: Use version numbers in template IDs for tracking
  6. Callbacks: Implement callback URLs for web panel integration
  7. Storage: Monitor ~/templates/ disk usage regularly
  8. Cleanup: Remove old/unused templates to save space

Integration with Web Panels

Templates enable powerful web panel features:
  1. Template Library: Display available templates with details
  2. One-Click Deployment: Create servers from templates via web interface
  3. Progress Tracking: Use callbacks to show real-time creation status
  4. Template Updates: Re-create templates when game updates are released
  5. Mod Packs: Create templates for popular mod configurations

Example Callback Handler (PHP)

<?php
if ($_GET['do'] === 'tpl_status') {
    $template_id = $_GET['id'];
    $status = $_GET['status'];
    $size = $_GET['size'] ?? null;
    
    // Update database
    $db->update('templates', [
        'status' => $status,
        'size' => $size,
        'updated_at' => time()
    ], ['id' => $template_id]);
    
    echo 'OK';
}
?>

Build docs developers (and LLMs) love