Skip to content

Commit 50c199d

Browse files
committed
feat: add windows-rdp-keepalive module
1 parent faff2be commit 50c199d

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Windows RDP Keep Alive
2+
3+
This module runs a background script on Windows workspaces that detects active RDP sessions and prevents the workspace from shutting down due to inactivity.
4+
5+
## Usage
6+
7+
```hcl
8+
module "rdp_keepalive" {
9+
source = "[registry.coder.com/modules/windows-rdp-keepalive/coder](https://registry.coder.com/modules/windows-rdp-keepalive/coder)"
10+
version = "1.0.0"
11+
agent_id = coder_agent.main.id
12+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
required_providers {
4+
coder = {
5+
source = "coder/coder"
6+
version = ">= 0.12"
7+
}
8+
}
9+
}
10+
11+
variable "agent_id" {
12+
description = "The ID of the Coder agent."
13+
type = string
14+
}
15+
16+
variable "interval" {
17+
description = "Interval in seconds to check for RDP connections."
18+
type = number
19+
default = 60
20+
}
21+
22+
resource "coder_script" "rdp_keepalive" {
23+
agent_id = var.agent_id
24+
display_name = "RDP Keep Alive"
25+
icon = "/icon/remote-desktop.svg"
26+
run_on_start = true
27+
28+
# We run a PowerShell loop in the background
29+
script = <<EOT
30+
$Interval = ${var.interval}
31+
32+
Write-Host "Starting RDP Keep Alive Monitor..."
33+
34+
while ($true) {
35+
# check for active RDP-Tcp sessions
36+
$rdpSession = query user | Select-String "rdp-tcp" | Select-String "Active"
37+
38+
if ($rdpSession) {
39+
# RDP is active. We need to generate 'activity' to prevent shutdown.
40+
# Since Coder monitors network/ssh, the simplest way to bump activity
41+
# is to simulate a state change or write to stdout which the agent captures.
42+
43+
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
44+
Write-Host "[$timestamp] RDP Active - Sending KeepAlive signal"
45+
46+
# This subtle output to the agent's log is often enough to reset the "idleness" timer
47+
# because the PTY receives data.
48+
}
49+
50+
Start-Sleep -Seconds $Interval
51+
}
52+
EOT
53+
}

0 commit comments

Comments
 (0)