-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_task.ps1
More file actions
61 lines (52 loc) · 2.04 KB
/
setup_task.ps1
File metadata and controls
61 lines (52 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# setup_task.ps1 -- Register the support agent as a Windows Task Scheduler task
# that starts at system boot and restarts on failure.
#
# Usage (run as Administrator):
# powershell -ExecutionPolicy Bypass -File setup_task.ps1
$ErrorActionPreference = "Stop"
$TaskName = "SupportAgentBot"
$BotDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$PythonExe = (Get-Command python).Source
$BotScript = Join-Path $BotDir "bot.py"
$LogFile = Join-Path $BotDir "bot.log"
Write-Host "Task name : $TaskName"
Write-Host "Working dir: $BotDir"
Write-Host "Python : $PythonExe"
Write-Host "Script : $BotScript"
Write-Host "Log file : $LogFile"
Write-Host ""
# Remove existing task if present
$existing = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
if ($existing) {
Write-Host "Removing existing task '$TaskName'..."
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
}
# Build the action: python bot.py, redirect stdout+stderr to log
$Action = New-ScheduledTaskAction `
-Execute $PythonExe `
-Argument "`"$BotScript`" >> `"$LogFile`" 2>&1" `
-WorkingDirectory $BotDir
# Trigger: at system startup
$Trigger = New-ScheduledTaskTrigger -AtStartup
# Settings: restart on failure, don't stop on idle, run indefinitely
$Settings = New-ScheduledTaskSettingsSet `
-AllowStartIfOnBatteries `
-DontStopIfGoingOnBatteries `
-StartWhenAvailable `
-RestartCount 3 `
-RestartInterval (New-TimeSpan -Minutes 1) `
-ExecutionTimeLimit (New-TimeSpan -Days 0)
# Register the task to run as SYSTEM (no password prompt)
Register-ScheduledTask `
-TaskName $TaskName `
-Action $Action `
-Trigger $Trigger `
-Settings $Settings `
-RunLevel Highest `
-User "SYSTEM" `
-Description "Homebase Discord support agent (AI-powered)"
Write-Host ""
Write-Host "Task '$TaskName' registered successfully."
Write-Host "Start it now with: Start-ScheduledTask -TaskName '$TaskName'"
Write-Host "Check status with: Get-ScheduledTask -TaskName '$TaskName'"
Write-Host "View logs at: $LogFile"