Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaneri committed Nov 29, 2024
1 parent ac4cbb9 commit 5c8bb3d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
1 change: 0 additions & 1 deletion examples/HelloService/HelloService.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ param(
[securestring]
$Password,


[switch]
$Agent,

Expand Down
43 changes: 21 additions & 22 deletions examples/HelloService/HelloServices.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
.PARAMETER Password
A secure password for the service account (Windows only). If omitted, the service account will be 'NT AUTHORITY\SYSTEM'.
.PARAMETER Agent
Defines the service as an Agent instead of a Daemon.(macOS only)
.PARAMETER Unregister
Unregisters all services specified in the hashtable. Use with -Force to force unregistration.
Expand Down Expand Up @@ -81,6 +84,9 @@ param(
[securestring]
$Password,

[switch]
$Agent,

[Parameter(Mandatory = $true, ParameterSetName = 'Unregister')]
[switch]
$Unregister,
Expand Down Expand Up @@ -133,53 +139,46 @@ catch {
# If there is any error during the module import, throw the error
throw
}
$services=@{
'HelloService1'=8081
'HelloService2'=8082
'HelloService3'=8083
$services = @{
'HelloService1' = 8081
'HelloService2' = 8082
'HelloService3' = 8083
}

if ( $Register.IsPresent) {
$services.GetEnumerator() | ForEach-Object { Register-PodeService -Name $($_.Key) -ParameterString "-Port $($_.Value)" -Password $Password }
exit
return $services.GetEnumerator() | ForEach-Object { Register-PodeService -Name $($_.Key) -Agent:($Agent.IsPresent) -ParameterString "-Port $($_.Value)" -Password $Password }
}
if ( $Unregister.IsPresent) {
$services.GetEnumerator() | ForEach-Object { try{Unregister-PodeService -Name $($_.Key) -Force:$Force }catch{Write-Error -Exception $_.Exception}}
exit
return $services.GetEnumerator() | ForEach-Object { try { Unregister-PodeService -Name $($_.Key) -Agent:($Agent.IsPresent) -Force:$Force }catch { Write-Error -Exception $_.Exception } }

}
if ($Start.IsPresent) {
$services.GetEnumerator() | ForEach-Object { Start-PodeService -Name $($_.Key) }
exit
return $services.GetEnumerator() | ForEach-Object { Start-PodeService -Name $($_.Key) -Agent:($Agent.IsPresent) }
}

if ($Stop.IsPresent) {
$services.GetEnumerator() | ForEach-Object { Stop-PodeService -Name $($_.Key) }
exit
return $services.GetEnumerator() | ForEach-Object { Stop-PodeService -Name $($_.Key) -Agent:($Agent.IsPresent) }
}

if ($Query.IsPresent) {
$services.GetEnumerator() | ForEach-Object { Get-PodeService -Name $($_.Key) }
exit
return $services.GetEnumerator() | ForEach-Object { Get-PodeService -Name $($_.Key) -Agent:($Agent.IsPresent) }
}

if ($Resume.IsPresent) {
$services.GetEnumerator() | ForEach-Object { Resume-PodeService -Name $($_.Key) }
exit
return $services.GetEnumerator() | ForEach-Object { Resume-PodeService -Name $($_.Key) -Agent:($Agent.IsPresent) }
}

if ($Query.IsPresent) {
$services.GetEnumerator() | ForEach-Object { Get-PodeService -Name $($_.Key) }
exit
return $services.GetEnumerator() | ForEach-Object { Get-PodeService -Name $($_.Key) -Agent:($Agent.IsPresent) }
}

if ($Restart.IsPresent) {
$services.GetEnumerator() | ForEach-Object { Restart-PodeService -Name $($_.Key) }
exit
return $services.GetEnumerator() | ForEach-Object { Restart-PodeService -Name $($_.Key) -Agent:($Agent.IsPresent) }
}

# Start the Pode server
Start-PodeServer {
New-PodeLoggingMethod -File -Name "errors-$port" -MaxDays 4 -Path './logs' | Enable-PodeErrorLogging
New-PodeLoggingMethod -File -Name "errors-$port" -MaxDays 4 -Path './logs' | Enable-PodeErrorLogging -Levels Informational

# Add an HTTP endpoint listening on localhost at port 8080
Add-PodeEndpoint -Address localhost -Port $Port -Protocol Http
Expand Down
2 changes: 1 addition & 1 deletion src/Public/Service.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
Specifies the username under which the service will run on Linux. Defaults to the current user if not provided.
.PARAMETER Agent
A switch to create an Agent instead of a Daemon on macOS (macOS only).
Create an Agent instead of a Daemon on macOS (macOS only).
.PARAMETER Start
A switch to start the service immediately after registration.
Expand Down

0 comments on commit 5c8bb3d

Please sign in to comment.