Run Garry's Mod Dedicated Server as Windows Service: Step-by-Step Guide
Running a Garry's Mod dedicated server as a Windows service is the most reliable way to ensure your community never experiences downtime. Unlike manually launching a batch file, a service operates in the background independently of user login sessions, automatically recovering from crashes and maintaining persistence through reboots.
Understanding Windows Services and GMod
Before diving into the configuration, it is essential to understand the relationship between a Windows service and a sandbox dedicated server. A Windows service is a long-running executable that performs specific system functions, while the Garry's Mod server (srcds) is a console application designed to run interactively. The challenge lies in bridging this gap, ensuring the console application behaves correctly when managed by the Service Control Manager (SCM).
Why Bother with a Service?
The primary advantage of converting your srcds instance into a service is resilience. If you run the server via Command Prompt or Task Scheduler, closing the window or missing a scheduled task can stop the map. As a Windows service, the application will restart automatically if it fails, and you can start it during the boot sequence before any user logs in. This professionalism is critical for public servers aiming to maintain a consistent player base.
Method 1: Using NSSM (The Recommended Approach)
The Non-Sucking Service Manager (NSSM) is the industry standard for running console applications as a service. It handles the complexities of the Windows API, ensuring that the sandbox operates correctly without requiring complex code modifications. This method is robust, clean, and widely used by IT professionals.
Installation and Configuration
To implement this solution, follow these steps. First, download the NSSM executable and place it in a permanent directory on your server machine. Open an elevated Command Prompt and use the `install` command to register the service, pointing the application path to the srcds executable and the startup directory to your server folder.
| Parameter | Example Value | Description |
|---|---|---|
| Service Name | GModServer | The identifier you will use to manage the service. |
| Path | C:\Servers\GMod\srcds.exe | The location of the Source Dedicated Server executable. |
| Start Directory | C:\Servers\GMod | Where the server looks for maps and configurations. |
| Application | -game garrysmod -console -usercon +map gm_construct | The launch parameters for your specific instance. |
Method 2: Using Built-in sc Command
For users who prefer to avoid third-party tools, Windows provides the `sc` command-line utility to create a basic service. While this method is viable, it often requires tweaking the binary parameters to prevent the service from terminating prematurely due to console interaction issues.
Basic sc Command Syntax
You can create a service by opening an elevated Command Prompt and entering a command that defines the service binary and its interaction flags. The critical addition here is the `-windowed` flag combined with specific handling to ensure the sandbox does not attempt to access the desktop, which is usually restricted in modern Windows versions.
Troubleshooting Common Issues
Even with the correct setup, you might encounter error 5 (Access Denied) or the service failing to start. This usually indicates a permissions issue with the folder structure or a conflict with the firewall. Ensure the account running the service has full read/write permissions to the server directory, and add an inbound rule to allow the Garry's Mod port (typically 27015) through the Windows Defender Firewall.
Finalizing and Managing Your Server
Once the service is active, you can manage it through the Services management console (services.msc) or via the command line using `net start` and `net stop` commands. Monitoring the Windows Event Viewer is also a best practice, as it will log any errors related to the startup or runtime of the sandbox that might not appear in the console window.