diff --git a/src/CopyAzureContainer/Scripts/Functions.ps1 b/src/CopyAzureContainer/Scripts/Functions.ps1 index 41c296a7b..b7dc6f5c4 100644 --- a/src/CopyAzureContainer/Scripts/Functions.ps1 +++ b/src/CopyAzureContainer/Scripts/Functions.ps1 @@ -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. -} \ No newline at end of file diff --git a/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.nuspec b/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.nuspec index 3c461cab3..768585b2c 100644 --- a/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.nuspec +++ b/src/NuGet.SupportRequests.Notifications/NuGet.SupportRequests.Notifications.nuspec @@ -12,8 +12,8 @@ - - + + diff --git a/src/NuGet.SupportRequests.Notifications/Scripts/Functions.ps1 b/src/NuGet.SupportRequests.Notifications/Scripts/Functions.ps1 new file mode 100644 index 000000000..b6286275b --- /dev/null +++ b/src/NuGet.SupportRequests.Notifications/Scripts/Functions.ps1 @@ -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 +} diff --git a/src/NuGet.SupportRequests.Notifications/Scripts/PostDeploy.ps1 b/src/NuGet.SupportRequests.Notifications/Scripts/PostDeploy.ps1 new file mode 100644 index 000000000..f6737ecaf --- /dev/null +++ b/src/NuGet.SupportRequests.Notifications/Scripts/PostDeploy.ps1 @@ -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