Skip to content

Commit 90fac48

Browse files
committed
Pass sigterm to wrapped executable
1 parent 8269957 commit 90fac48

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ modified, and then executes a wrapped executable.
2828

2929
Save the following to `Dockerfile`:
3030

31-
```
31+
```dockerfile
3232
FROM python:3
3333

34-
RUN apt-get update; apt-get install -y jq
34+
RUN apt-get update; apt-get install -y jq curl
3535

3636
# Download the latest version of udl
37-
RUN curl -s https://api.github.com/repos/mcasperson/UltimateDockerLauncher/releases/latest | jq '.assets[] | select(.name|match("udl$")) | .browser_download_url' | xargs -I {} curl -L -o /opt/udl {}
37+
RUN curl -s https://api.github.com/repos/mcasperson/UltimateDockerLauncher/releases/latest | \
38+
jq '.assets[] | select(.name|match("udl$")) | .browser_download_url' | \
39+
xargs -I {} curl -L -o /opt/udl {}
3840
RUN chmod +x /opt/udl
3941

4042
# UDL_WRITEFILE[filename] environment variables are used to save files
@@ -52,6 +54,29 @@ print(f.read())' >> /app/main.py
5254
CMD [ "/opt/udl", "python", "/app/main.py" ]
5355
```
5456

57+
Here is another example Dockerfile using UDL with Apache, this time using bash to execute UDL before the main app:
58+
59+
```dockerfile
60+
FROM httpd:2.4
61+
62+
RUN apt-get update; apt-get install -y jq curl
63+
64+
# Download the latest version of udl
65+
RUN curl -s https://api.github.com/repos/mcasperson/UltimateDockerLauncher/releases/latest | \
66+
jq '.assets[] | select(.name|match("udl$")) | .browser_download_url' | \
67+
xargs -I {} curl -L -o /opt/udl {}
68+
RUN chmod +x /opt/udl
69+
70+
# UDL_WRITEFILE[filename] environment variables are used to save files
71+
ENV UDL_WRITEFILE[/usr/local/apache2/htdocs/config.json]='{"whatever": ["hello"]}'
72+
73+
# UDL_SETVALUE[file][key] environment variables are used to set values inside configuration files like JSON, YAML, INI etc
74+
ENV UDL_SETVALUE[/usr/local/apache2/htdocs/config.json][whatever:0]="world"
75+
76+
# Here we use bash to call UDL before calling the main application
77+
CMD [ "/bin/bash", "-c", "/opt/udl; httpd-foreground" ]
78+
```
79+
5580
Build the image with:
5681

5782
```bash

cmd/internal/executors/execute_and_wait.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"context"
55
"os"
66
"os/exec"
7+
"os/signal"
78
"runtime"
9+
"syscall"
810
"time"
911
)
1012

@@ -60,11 +62,16 @@ func (e ExecuteAndWait) wait(ctx context.Context, cmd *exec.Cmd, interrupt os.Si
6062
panic("waitOrStop requires a non-nil interrupt signal")
6163
}
6264

65+
cancelChan := make(chan os.Signal, 1)
66+
// catch SIGETRM or SIGINTERRUPT
67+
signal.Notify(cancelChan, syscall.SIGTERM, syscall.SIGINT)
68+
6369
errc := make(chan error)
6470
go func() {
6571
select {
6672
case errc <- nil:
6773
return
74+
case interrupt = <-cancelChan:
6875
case <-ctx.Done():
6976
}
7077

0 commit comments

Comments
 (0)