-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathContainer.start.ps1
More file actions
75 lines (59 loc) · 1.87 KB
/
Copy pathContainer.start.ps1
File metadata and controls
75 lines (59 loc) · 1.87 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<#
.SYNOPSIS
Starts the container.
.DESCRIPTION
Starts a container.
This script should be called from the Dockerfile as the ENTRYPOINT (or from within the ENTRYPOINT).
It should be deployed to the root of the container image.
#>
param()
$env:IN_CONTAINER = $true
$PSStyle.OutputRendering = 'Ansi'
$mountedDrives = @(if (Test-Path '/proc/mounts') {
(Select-String "\S+\s(?<p>\S+).+rw?,.+symlinkroot=/mnt/host" "/proc/mounts").Matches.Groups |
Where-Object Name -eq p |
Get-Item -path { $_.Value }
})
if ($global:ContainerInfo.MountedPaths) {
"Mounted $($mountedDrives.Length) drives:" | Out-Host
$mountedDrives | Out-Host
}
function / {
"Hello from Fun."
"It is $([DateTime]::Now.ToString())."
"Here's a random number $([Random]::new().next())."
}
if ($args) {
# If there are arguments, output them (you could handle them in a more complex way).
$remainingArgs = @(foreach ($arg in $args) {
if ($arg -match '\.ps1$' -and (Test-Path $arg)) {
. $arg
} else {
$arg
}
})
$fun = fun "http://*/" @remainingArgs
# Launch three replicas
$fun.Start();$fun.Start();$fun.Start()
} else {
if (Test-Path ./Fun.fun.ps1) {
. ./Fun.fun.ps1
} else {
function / { "Hello from Fun" }
}
$fun = fun "http://*/"
# Launch three replicas
$fun.Start();$fun.Start();$fun.Start()
}
# If you want to do something when the container is stopped, you can register an event.
# This can call a script that does some cleanup, or sends a message as the service is exiting.
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action {
Get-Job |
Where-Object HttpListener |
ForEach-Object {
$_.HttpListener.Stop()
}
if (Test-Path '/Container.stop.ps1') {
& /Container.stop.ps1
}
} | Out-Null