Skip to content

Commit 0cf1f7e

Browse files
committed
safety
1 parent 66a91c7 commit 0cf1f7e

File tree

11 files changed

+701
-59
lines changed

11 files changed

+701
-59
lines changed

docs/slides/awesome-hello-world.py

100644100755
Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,68 @@
1-
#!/usr/bin/env python3
1+
#!/nix/store/qfcbvbm2wzpgh2m1j5b8yd61y8y8x5nw-isd-tui-env/bin/python
22
import http.server
3-
import socketserver
43
import time
5-
import threading
64
import sys
75
import random
8-
from pathlib import Path
96

107
PORT = 8181
11-
HELLO_FILE = Path("/opt/hello/hello.txt")
128

139

1410
class HelloHandler(http.server.SimpleHTTPRequestHandler):
11+
def __init__(self, *args, **kwargs):
12+
super().__init__(*args, **kwargs)
13+
1514
def do_GET(self):
1615
self.send_response(200)
1716
self.send_header("Content-type", "text/plain; charset=utf-8")
1817
self.end_headers()
19-
time.sleep(5)
20-
try:
21-
text = HELLO_FILE.read_text()
22-
except Exception as e:
23-
text = f"ERROR: cannot read {HELLO_FILE}: {e}"
24-
self.wfile.write(text.encode("utf-8"))
25-
26-
27-
def noisy_logger():
28-
"""Generate noisy logs forever"""
29-
while True:
30-
r = random.randint(0, 2)
31-
if r == 0:
32-
print(
33-
f"{time.ctime()} DEBUG: heartbeat from awesome-hello-world",
34-
file=sys.stderr,
35-
flush=True,
36-
)
37-
elif r == 1:
38-
print(
39-
f"{time.ctime()} WARN: pretending to have triggered an warning in awesome-hello-world",
40-
file=sys.stderr,
41-
flush=True,
42-
)
43-
else:
44-
print(
45-
f"{time.ctime()} LOG: pretending to log in awesome-hello-world",
46-
file=sys.stderr,
47-
flush=True,
48-
)
49-
50-
time.sleep(0.5)
18+
self.wfile.write("Hello World!".encode("utf-8"))
19+
20+
21+
def log_debug():
22+
print(
23+
f"{time.ctime()} DEBUG: heartbeat",
24+
file=sys.stderr,
25+
flush=True,
26+
)
27+
28+
29+
def log_log():
30+
print(
31+
f"{time.ctime()} LOG: logging something interesting...",
32+
file=sys.stderr,
33+
flush=True,
34+
)
5135

5236

5337
if __name__ == "__main__":
5438
# Start background noisy logger
55-
threading.Thread(target=noisy_logger, daemon=True).start()
39+
# add some noisy output
40+
for _ in range(30):
41+
r = random.randint(0, 1)
42+
if r == 0:
43+
log_debug()
44+
if r == 2:
45+
log_log()
46+
47+
try:
48+
import socketserver
49+
50+
with socketserver.TCPServer(("", PORT), HelloHandler) as httpd:
51+
# print(f"Serving on port {PORT}, reading from {HELLO_FILE}", flush=True)
52+
httpd.serve_forever()
53+
except Exception as e:
54+
# simulate shutting down
55+
print(
56+
f"{time.ctime()} ERROR: {e}",
57+
file=sys.stderr,
58+
flush=True,
59+
)
60+
print(
61+
f"{time.ctime()} STOPPING: shutting down with delay",
62+
file=sys.stderr,
63+
flush=True,
64+
)
65+
for _ in range(20):
66+
log_debug()
5667

57-
with socketserver.TCPServer(("", PORT), HelloHandler) as httpd:
58-
# print(f"Serving on port {PORT}, reading from {HELLO_FILE}", flush=True)
59-
httpd.serve_forever()
68+
exit(1)

docs/slides/awesome-hello-world.service

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ Description=Awesome Hello World Server
33
After=network.target
44

55
[Service]
6-
ExecStart=/opt/hello/serve-hello.py
7-
ProtectSystem=strict
8-
ProtectHome=yes
6+
ExecStart=/opt/hello/awesome-hello-world.py
7+
DynamicUser=yes
8+
PrivateTmp=yes
9+
RestrictAddressFamilies=AF_UNIX AF_INET6
10+
SystemCallFilter=~@chown @clock @cpu-emulation @privileged
911

1012
[Install]
1113
WantedBy=multi-user.target

docs/slides/custom.tape

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
Set TypingSpeed 100ms
2+
3+
Set Shell "fish"
4+
# Set PlaybackSpeed 0.4
5+
Set Padding 1
6+
Set Margin 1
7+
Set FontSize 16
8+
Output out.gif
9+
# Set Width 850
10+
# Set Height 200
11+
12+
Hide
13+
Type@10ms `rm ~/.config/isd_tui/config.yaml` Enter
14+
Type@10ms `ISD_CACHE_INPUT=false ISD_STARTUP_MODE=system ISD_FULL_REFRESH_INTERVAL_SEC=1 my_asciinema rec --overwrite --quiet --window-size 85x27 --command 'fish --private --init-command="set -g fish_autosuggestion_enabled 0"' custom.cast`
15+
Enter
16+
17+
Sleep 0.5s
18+
Show
19+
20+
Sleep 1s
21+
Type "isd" Sleep 0.5s Enter
22+
Sleep 1s
23+
Ctrl+N
24+
Ctrl+P
25+
Sleep 1s
26+
Type "config"
27+
Sleep 1s
28+
Ctrl+N
29+
Enter
30+
Sleep 1s
31+
Ctrl+N
32+
Down@50ms 11
33+
Type "o"
34+
Type "journal_p" Sleep 1s Tab
35+
Sleep 3s Enter
36+
Type "c0" Escape
37+
Ctrl+N
38+
Type "i" Backspace
39+
Type "lnav" Enter
40+
Sleep 1s
41+
Type "theme: " Escape
42+
Sleep 1s
43+
Ctrl+N
44+
Type "inord" Enter
45+
Sleep 1s
46+
Escape
47+
Ctrl+N
48+
Type ":wq" Enter
49+
50+
Sleep 1s
51+
Ctrl+N
52+
Sleep 1s
53+
Ctrl+Q
54+
Sleep 1s
55+
Type "isd"
56+
Ctrl+N
57+
58+
Type "awesome-"
59+
Sleep 1s
60+
Tab@100ms 3
61+
Right Sleep 1s
62+
Enter
63+
Sleep 1s
64+
Ctrl+N
65+
Sleep 1s
66+
Type ":filter-in DEBUG"
67+
Sleep 2s
68+
Enter
69+
Sleep 1s
70+
Ctrl+N
71+
Sleep 1s
72+
Type "q"
73+
74+
Ctrl+D
75+

docs/slides/dist/theme/night.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ section.has-light-background h6 {
6161
--r-code-font: 'CascadiaCodeNF';
6262
}
6363

64+
q {
65+
quotes: "„" "“" "‚" "‘";
66+
}
67+
68+
q::before {
69+
content: open-quote;
70+
}
71+
72+
q::after {
73+
content: close-quote;
74+
}
75+
6476
.ap-wrapper pre.ap-terminal {
6577
/* border-width: 0em; */
6678
padding: 0;
@@ -86,6 +98,10 @@ section.has-light-background h6 {
8698
height: 100%;
8799
}
88100

101+
.large {
102+
font-size: var(--r-heading2-size);
103+
}
104+
89105
.vfill::after {
90106
content: "";
91107
flex: .2;
@@ -413,4 +429,4 @@ section.has-light-background h6 {
413429
.backgrounds {
414430
background-color: var(--r-background-color);
415431
}
416-
}
432+
}

docs/slides/example.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
```sh
2+
3+
rm -f /run/systemd/system/awesome-hello-world.service.d/override.conf
4+
5+
# asciinema rec --overwrite --quiet old_workflow.cast
6+
7+
curl localhost:8181
8+
9+
systemctl status awesome-hello-world.service
10+
11+
journalctl -xeu awesome-hello-world.service
12+
13+
journalctl --user -xeu awesome-hello-world.service
14+
15+
journalctl -xeu awesome-hello-world.service
16+
17+
# UP for 10sek
18+
# q
19+
20+
systemctl edit --runtime awesome-hello-world.service
21+
22+
# ah yeah, requires sudo
23+
24+
sudo systemctl edit --runtime awesome-hello-world.service
25+
# TYPE:
26+
# [Service] ENTER
27+
# RestrictAddressFamilies=AF_UNIX AF_INET6 AF_INET ENTER
28+
# Ctrl+X
29+
# Y
30+
31+
curl localhost:8181
32+
33+
# ah yeah, forgot to restart the service
34+
35+
sudo systemctl restart awesome-hello-world.service
36+
37+
curl localhost:8181
38+
39+
40+
# rm /run/systemd/system/awesome-hello-world.service.d/override.conf
41+
42+
```

0 commit comments

Comments
 (0)