Run RTSP Server as Windows Service

Deploy Happytimesoft RTSP Server as a background service for auto-start, reliability, and unattended operation on Windows.

Why Run as a Service?

Running your RTSP Server as a Windows Service offers critical advantages:

  • Auto-Start: The server starts automatically when Windows boots, even before user login.
  • Background Operation: Runs silently in the background without a user interface.
  • Reliability: Managed by the Windows Service Control Manager (SCM) for better stability.
  • Unattended Operation: Ideal for servers or headless systems that run 24/7.

The Solution: SrvStart

This guide uses SrvStart, a lightweight and reliable open-source tool to create Windows Services from any executable.

SrvStart acts as a wrapper, allowing your RTSP Server to integrate seamlessly with the Windows service architecture.

[Windows SCM] ←→ [SrvStart Service] ←→ [RTSP Server Executable]

Step 1: Download and Install SrvStart

1. Visit the SrvStart GitHub page and download the latest release.

2. Extract the contents to a folder on your system (e.g., C:\tools\srvstart\).

Step 2: Create the Configuration File

Create an INI file (e.g., rtspserver.ini) to define your service. Replace the paths with your actual installation.

rtspserver.ini
; Configuration for RTSP Server Service
[rtspserver]
startup="C:\Program Files\Happytimesoft\RTSPServer\RTSPServer.exe"
startup_dir=C:\Program Files\Happytimesoft\RTSPServer
shutdown_method=winmessage

Explanation:

  • startup: Full path to the RTSP Server executable.
  • startup_dir: Working directory for the service.
  • shutdown_method=winmessage: Sends a close message to gracefully stop the server.

Step 3: Create the Windows Service

Run the following command in an Administrator Command Prompt:

Command: Install the Service
srvstart install rtspserver -c C:\tools\srvstart\rtspserver.ini

If successful, you'll see a "SUCCESS" message. The service is now registered with Windows.

Step 4: Manage Your Service

Use these commands to control your new service:

Common SrvStart Commands
; Start the service
net start rtspserver

; Stop the service
net stop rtspserver

; Remove the service (if needed)
srvstart remove rtspserver

You can also manage the service via the Windows Services GUI (services.msc).

Best Practices

  • Administrator Rights: Always run Command Prompt as Administrator when installing/removing services.
  • Path Accuracy: Double-check all file paths in the INI file. Use quotes if paths contain spaces.
  • Testing: Test the RTSP Server manually before installing it as a service.
  • Logs: Ensure your RTSP Server logs to a file for troubleshooting service issues.
  • Security: Run the service under a dedicated, low-privilege user account if possible.