Public/Running/Start-EdenLocalService.ps1
function Start-EdenLocalService { [CmdletBinding()] param( [Parameter()] # The name of the local or global settins file to pass to the Eden script. [Alias("sn")] [String]$SettingsName = "Default", [Parameter()] [Alias("c")] [Switch]$Continuous ) $location = Get-Location try { if (Test-Path "./Eden/Running/Start-LocalService.ps1") { $localCommand = "Running/Start-LocalService" if ($Continuous) { $localCommand = "Running/Start-LocalServiceContinuous" } Invoke-EdenCommandStandardFlow ` -LocalCommandPath $localCommand ` -SettingsName $SettingsName ` -CommandGroup "Running" ` -Message "Starting the service." ` -AdditionalArguments $AdditionalArguments } else { try { $settings = Get-EdenSettings -Name $SettingsName $loggingPrefix = "$($settings.SolutionName) $($settings.ServiceName) Running $($settingsName)" $startCommand = "Start-EdenLocalServiceApplication" if ($Continuous) { $startCommand = "Start-EdenLocalServiceApplicationContinuous" } $serviceJob = Start-EdenCommand ` -EdenCommand $startCommand ` -SettingsName $SettingsName ` -LoggingPrefix $loggingPrefix $tunnelJob = Start-EdenCommand ` -EdenCommand "Start-EdenLocalServiceTunnel" ` -SettingsName $SettingsName ` -LoggingPrefix $loggingPrefix $serviceReady = $false $publicUrl = $null $subscriptionsDeployed = $false # Write-Verbose "Before: Service Job: $($serviceJob.State)" # Write-Verbose "Before: Tunnel Job: $($tunnelJob.State)" # Write-Verbose "Before: Testing Job: $($testingJob.State)" While($true) { if ([string]::IsNullOrEmpty($publicUrl)) { $publicUrl = Get-EdenLocalServicePublicUrl -SettingsName $SettingsName } if(![string]::IsNullOrEmpty($publicUrl) -and !$serviceReady) { $serviceReady = Get-EdenLocalServiceStatus ` -SettingsName $SettingsName ` -AdditionalArguments @{ ` Url = $publicUrl ` } } if ($serviceReady -and !$subscriptionsDeployed) { Deploy-EdenLocalServiceSubscriptions ` -SettingsName $SettingsName ` -AdditionalArguments @{ ` Url = $publicUrl ` } $subscriptionsDeployed = $true } $serviceJob | Receive-Job | Write-Verbose $tunnelJob | Receive-Job | Write-Verbose Start-Sleep 1 if ($serviceJob.State -eq "Failed") { $serviceJob | Receive-Job throw "Local service failed to run. Status Message: '$($serviceJob.JobStateInfo.Reason.Message)'" } if ($tunnelJob.State -eq "Failed") { $tunnelJob | Receive-Job throw "Local tunnel failed to run. Status Message: '$($tunnelJob.JobStateInfo.Reason.Message)'" } } } finally { # Write-EdenInfo "Stopping the service job." $loggingPrefix # $serviceJob.StopJob() Write-EdenInfo "Removing the service job." $loggingPrefix $serviceJob | Remove-Job -Force # Write-EdenInfo "Stopping the tunnel job." $loggingPrefix # $tunnelJob.StopJob() Write-EdenInfo "Removing the tunnel job." $loggingPrefix $tunnelJob | Remove-Job -Force Write-EdenInfo "Stopped." $loggingPrefix } } } catch { Write-EdenError "$($_ | Out-String)" Write-EdenError "Stopping and removing jobs due to exception. Message: '$($_.Exception.Message)'" $loggingPrefix } finally { Set-Location $location } } New-Alias ` -Name e-rs ` -Value Start-EdenLocalService ` -Force |