Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Commit

Permalink
Install the support requests job automatically (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Feb 1, 2019
1 parent 1c9da41 commit ad6faf5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
31 changes: 0 additions & 31 deletions src/CopyAzureContainer/Scripts/Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,3 @@ Function Install-AzCopy
Remove-Item $bootstrap -Recurse -Force
}
}

Function Uninstall-NuGetService() {
Param ([string]$ServiceName)

if (Get-Service $ServiceName -ErrorAction SilentlyContinue)
{
Write-Host Removing service $ServiceName...
Stop-Service $ServiceName -Force
sc.exe delete $ServiceName
Write-Host Removed service $ServiceName.
} else {
Write-Host Skipping removal of service $ServiceName - no such service exists.
}
}

Function Install-NuGetService() {
Param ([string]$ServiceName, [string]$ServiceTitle, [string]$ScriptToRun)

Write-Host Installing service $ServiceName...

$installService = "nssm install $ServiceName $ScriptToRun"
cmd /C $installService

Set-Service -Name $ServiceName -DisplayName "$ServiceTitle - $ServiceName" -Description "Runs $ServiceTitle." -StartupType Automatic
sc.exe failure $ServiceName reset= 30 actions= restart/5000

# Run service
net start $ServiceName

Write-Host Installed service $ServiceName.
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<files>
<file src="bin\$configuration$\*.*" target="bin"/>

<file src="Scripts\OnCallDailyNotification.cmd" />
<file src="Scripts\WeeklySummaryNotification.cmd" />
<file src="Scripts\*.cmd" />
<file src="Scripts\*.ps1" />

<file src="Settings\*.json" target="bin" />
</files>
Expand Down
31 changes: 31 additions & 0 deletions src/NuGet.SupportRequests.Notifications/Scripts/Functions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Function Install-DailyTask
{
$trigger = New-ScheduledTaskTrigger -DaysInterval 1 -At "12pm" -Daily

Install-NuGetScheduledTask $trigger "Support Request Daily Notification" "OnCallDailyNotification.cmd"
}

Function Install-WeeklyTask
{
$trigger = New-ScheduledTaskTrigger -Weekly -WeeksInterval 1 -DaysOfWeek Monday -At "12pm"

Install-NuGetScheduledTask $trigger "Support Requests Weekly Notification" "WeeklySummaryNotification.cmd"
}

Function Install-NuGetScheduledTask
{
param($Trigger, $Name, $Command)

#Action to run as
$cmdExe = [system.environment]::getenvironmentvariable("ComSpec")
$action = New-ScheduledTaskAction -Execute $cmdExe -Argument "/c $PSScriptRoot\$Command" -WorkingDirectory $PSScriptRoot

#Configure when to stop the task and how long it can run for. In this example it does not stop on idle and uses the maximum possible duration by setting a timelimit of 0
$settings = New-ScheduledTaskSettingsSet -DontStopOnIdleEnd -ExecutionTimeLimit ([TimeSpan]::Zero) -MultipleInstances IgnoreNew

#Configure the principal to use for the scheduled task and the level to run as
$principal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel "Highest"

#Register the new scheduled task
Register-ScheduledTask -TaskName $Name -Action $action -Trigger $Trigger -Principal $principal -Settings $settings -Force
}
10 changes: 10 additions & 0 deletions src/NuGet.SupportRequests.Notifications/Scripts/PostDeploy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
. .\Functions.ps1

## The daily task is broken right now due to Pin
# Write-Host Register the daily scheduled task
# Install-DailyTask
# Write-Host Registered the daily scheduled task

Write-Host Register the weekly scheduled task
Install-WeeklyTask
Write-Host Registered the weekly scheduled task

0 comments on commit ad6faf5

Please sign in to comment.