-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocker-init.html
805 lines (708 loc) · 26.8 KB
/
docker-init.html
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Docker Init</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/black.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<!-- Title -->
<section>
<h1>Docker Init</h1>
<p>Syazwan <[email protected]></p>
</section>
<!-- TLDR -->
<section>
<h1>tl;dr</h1>
<p><code>docker run --init</code></p>
</section>
<!-- Slide: What is Init -->
<section>
<section>
<h2>What is it?</h2>
</section>
<section>
<p>
<blockquote>
<span class="fragment">In Unix-based computer operating systems,</span>
<span class="fragment"> init is the <strong>first process started</strong> during booting of the computer system.</span>
<span class="fragment"> Init is a daemon process that continues running until the system is shut down.</span>
<span class="fragment"><br/> … <br/></span>
<span class="fragment">Init is typically assigned <strong>process identifier 1</strong>.</span>
</blockquote>
<p style="text-align: right;">—Wikipedia</p>
</p>
</section>
</section>
<!-- Slide: Why Init -->
<section>
<section>
<h2>I don't care</h2>
<ul>
<li class="fragment">Zombies use resources. If kernel process table fills, it will be impossible to create new processes</li>
<li class="fragment">"I only run 1 service per container!" <span class="fragment">But are you sure the service doesn't spawn processes?</span></li>
<li class="fragment">How many have written custom init scripts?</li>
</ul>
</section>
<section>
<h2>When to use?</h2>
<ul>
<li class="fragment">Proper signal handling from host machine (SIGTERM spam anyone?)</li>
<li class="fragment">Long-running service that potentially spawns many children (zombies)</li>
<li class="fragment">More than 1 service (!) (restarts)</li>
<li class="fragment">Exit code forwarding</li>
<aside class="notes">Signal handling with bash requires trapping and handling manually</aside>
</ul>
</section>
<section>
<h3>
But, bash can adopt orphans!!!
</h3>
<ul>
<li class="fragment">Gotcha: single cmd will be exec'd</li>
<pre style="width: 100%; margin: -14px 0;" class="fragment">
<code data-noescape data-trim>
<div class="fragment fade-in-then-semi-out">
docker run --rm ubuntu:xenial bash -c 'ps'
PID TTY TIME CMD
<mark>1</mark> pts/0 00:00:00 ps
</div>
<div class="fragment fade-in-then-semi-out">
docker run --rm ubuntu:xenial bash -c 'echo; ps'
PID TTY TIME CMD
1 ? 00:00:00 <mark>bash</mark>
8 ? 00:00:00 ps
</div>
</code>
</pre>
<li class="fragment">No signal forwarding</li>
<li class="fragment">Unreliable exit code (eg. restart policy)</li>
</ul>
</section>
<section>
<p>
Roll-up your own (and miss plenty of edge cases)
</p>
<pre>
<code data-trim data-noescape class="stretch fragment">
#!/bin/bash
# Exit on error
set -e
# Let functions inherit ERR traps which otherwise they won't
# Equivalent to -o errtrace
set -E
cleanup() {
...
}
<mark>trap cleanup EXIT</mark>
trap 'exit 1' HUP INT QUIT TERM ERR
</code>
</pre>
</section>
<section>
<p>
phusion wrote 400+ lines of init script: <br/><a href="https://github.com/phusion/baseimage-docker/blob/master/image/bin/my_init">baseimage-docker/image/bin/my_init</a>
</p>
<pre>
<code data-trim data-noescape>
#!/usr/bin/python3 -u
# -*- coding: utf-8 -*-
import argparse
import errno
import json
import os
import os.path
import re
import signal
import stat
import sys
import time
ENV_INIT_DIRECTORY = os.environ.get('ENV_INIT_DIRECTORY', '/etc/my_init.d')
KILL_PROCESS_TIMEOUT = int(os.environ.get('KILL_PROCESS_TIMEOUT', 30))
KILL_ALL_PROCESSES_TIMEOUT = int(os.environ.get('KILL_ALL_PROCESSES_TIMEOUT', 30))
LOG_LEVEL_ERROR = 1
LOG_LEVEL_WARN = 1
LOG_LEVEL_INFO = 2
LOG_LEVEL_DEBUG = 3
SHENV_NAME_WHITELIST_REGEX = re.compile('\W')
log_level = None
terminated_child_processes = {}
_find_unsafe = re.compile(r'[^\w@%+=:,./-]').search
class AlarmException(Exception):
pass
def error(message):
if log_level >= LOG_LEVEL_ERROR:
sys.stderr.write("*** %s\n" % message)
def warn(message):
if log_level >= LOG_LEVEL_WARN:
sys.stderr.write("*** %s\n" % message)
def info(message):
if log_level >= LOG_LEVEL_INFO:
sys.stderr.write("*** %s\n" % message)
def debug(message):
if log_level >= LOG_LEVEL_DEBUG:
sys.stderr.write("*** %s\n" % message)
def ignore_signals_and_raise_keyboard_interrupt(signame):
signal.signal(signal.SIGTERM, signal.SIG_IGN)
signal.signal(signal.SIGINT, signal.SIG_IGN)
raise KeyboardInterrupt(signame)
def raise_alarm_exception():
raise AlarmException('Alarm')
def listdir(path):
try:
result = os.stat(path)
except OSError:
return []
if stat.S_ISDIR(result.st_mode):
return sorted(os.listdir(path))
else:
return []
def is_exe(path):
try:
return os.path.isfile(path) and os.access(path, os.X_OK)
except OSError:
return False
def import_envvars(clear_existing_environment=True, override_existing_environment=True):
if not os.path.exists("/etc/container_environment"):
return
new_env = {}
for envfile in listdir("/etc/container_environment"):
name = os.path.basename(envfile)
with open("/etc/container_environment/" + envfile, "r") as f:
# Text files often end with a trailing newline, which we
# don't want to include in the env variable value. See
# https://github.com/phusion/baseimage-docker/pull/49
value = re.sub('\n\Z', '', f.read())
new_env[name] = value
if clear_existing_environment:
os.environ.clear()
for name, value in new_env.items():
if override_existing_environment or name not in os.environ:
os.environ[name] = value
def export_envvars(to_dir=True):
if not os.path.exists("/etc/container_environment"):
return
shell_dump = ""
for name, value in os.environ.items():
if name in ['HOME', 'USER', 'GROUP', 'UID', 'GID', 'SHELL']:
continue
if to_dir:
with open("/etc/container_environment/" + name, "w") as f:
f.write(value)
shell_dump += "export " + sanitize_shenvname(name) + "=" + shquote(value) + "\n"
with open("/etc/container_environment.sh", "w") as f:
f.write(shell_dump)
with open("/etc/container_environment.json", "w") as f:
f.write(json.dumps(dict(os.environ)))
def shquote(s):
""Return a shell-escaped version of the string *s*.""
if not s:
return "''"
if _find_unsafe(s) is None:
return s
# use single quotes, and put single quotes into double quotes
# the string $'b is then quoted as '$'"'"'b'
return "'" + s.replace("'", "'\"'\"'") + "'"
def sanitize_shenvname(s):
""Return string with [0-9a-zA-Z_] characters""
return re.sub(SHENV_NAME_WHITELIST_REGEX, "_", s)
# Waits for the child process with the given PID, while at the same time
# reaping any other child processes that have exited (e.g. adopted child
# processes that have terminated).
def waitpid_reap_other_children(pid):
global terminated_child_processes
status = terminated_child_processes.get(pid)
if status:
# A previous call to waitpid_reap_other_children(),
# with an argument not equal to the current argument,
# already waited for this process. Return the status
# that was obtained back then.
del terminated_child_processes[pid]
return status
done = False
status = None
while not done:
try:
# https://github.com/phusion/baseimage-docker/issues/151#issuecomment-92660569
this_pid, status = os.waitpid(pid, os.WNOHANG)
if this_pid == 0:
this_pid, status = os.waitpid(-1, 0)
if this_pid == pid:
done = True
else:
# Save status for later.
terminated_child_processes[this_pid] = status
except OSError as e:
if e.errno == errno.ECHILD or e.errno == errno.ESRCH:
return None
else:
raise
return status
def stop_child_process(name, pid, signo=signal.SIGTERM, time_limit=KILL_PROCESS_TIMEOUT):
info("Shutting down %s (PID %d)..." % (name, pid))
try:
os.kill(pid, signo)
except OSError:
pass
signal.alarm(time_limit)
try:
try:
waitpid_reap_other_children(pid)
except OSError:
pass
except AlarmException:
warn("%s (PID %d) did not shut down in time. Forcing it to exit." % (name, pid))
try:
os.kill(pid, signal.SIGKILL)
except OSError:
pass
try:
ATUS(status)))
sys.exit(1)
def run_command_killable_and_import_envvars(*argv):
run_command_killable(*argv)
import_envvars()
export_envvars(False)
def kill_all_procespath.join(ENV_INIT_DIRECTORY, name)
if is_exe(filename):
info("Running %s..." % filename)
run_command_killable_and_import_envvars(filename)
# Run /etc/rc.local.
if is_exe("/etc/rc.local"):
info("Running llable(filename)
def start_runit():
info("Booting runit daemon...")
pid = os.spawnl(os.P_NOWAIT, "/usr/bin/runsvdir", "/usr/bin/runsvdir",
"-P", "/etc/service")
info("Runit started as PID %d" % pid)
return pid
def wait_for_runit_or_interrupt(pid):
status = waitpid_reap_other_children(pid)
return (True, status)
def shutdown_runit_services(quiet=False):
if not quiet:
debug("Begin shutting down runit services...")
os.system("/usr/bin/sv -w %d force-stop /etc/service/* > /dev/null" % KILL_PROCESS_TIMEOUT)
def wait_for_runit_services():
debug("Waiting for runit services to exit...")
done = False
while not done: info("Runit exited with status %d" % exit_status)
else:
info("Running %s..." % " ".join(argstdown_scripts()
shutdown_runit_services()
if not runit_exited:
stop_child_process("runit daemon", runit_pid)
wait_for_runit_services()
run_post_shutdown_scripts()
# Parse options.
parser = argparse.ArgumentParser(description='Initialize the system.')
parser.add_argument('main_command', metavar='MAIN_COMMAND', type=str, nargs='*',
help='The main command t system aborted.")
exit(2)
finally:
if args.kill_all_on_exit:
kill_all_processes(KILL_ALL_PROCESSES_TIMEOUT)"')))")")")'"'
</code>
</pre>
</section>
<section>
<h1>Just Stop.</h1>
</section>
</section>
<!-- Slide: Init options -->
<section>
<section>
<h2>Init options</h2>
</section>
<section>
<ul>
<li>supervisord</li>
<li>monit</li>
<li>runit</li>
<li>tini</li>
<li>dumb-init</li>
<li>s6</li>
<li>…</li>
</ul>
</section>
</section>
<!-- Slide: tini -->
<section>
<section>
<h2>tini</h2>
<p>https://github.com/krallin/tini</p>
</section>
<section>
<p>
- Docker engine was using grimes until late 2016
</p>
<p class="fragment">
- Docker CE with tini officially released early 2017 as part of <a href="https://docs.docker.com/release-notes/docker-engine/#1130-2017-01-18">v1.13</a> <span class="fragment"><strong>(but not running by default!)</strong><br/> See PRs <a href="https://github.com/docker/docker/pull/26061">#26061</a> & <a href="https://github.com/docker/docker/pull/28037">#28037</a></span>
</p>
<p class="fragment">
- Images without tini will work with tini without any code change. <strong>Zero config</strong>. So use it.
</p>
</section>
<section>
<h2>tini included</h2>
<p><a href="https://github.com/docker/engine/blob/master/Dockerfile#L157" data-preview-link>docker/engine/blob/master/Dockerfile#L157</a></p>
<pre><code data-trim>
FROM base AS tini
RUN apt-get update && apt-get install -y cmake vim-common
COPY hack/dockerfile/install/install.sh ./install.sh
ENV INSTALL_BINARY_NAME=tini
COPY hack/dockerfile/install/$INSTALL_BINARY_NAME.installer ./
RUN PREFIX=/build ./install.sh $INSTALL_BINARY_NAME
...
COPY --from=tini /build/ /usr/local/bin/
</code></pre>
</section>
<!-- docker run with init -->
<section>
<pre>
<code data-trim data-noescape>
~ docker run --rm -it alpine sh
/ # ps
<span class="fragment">PID USER TIME COMMAND
1 root 0:00 sh
8 root 0:00 ps
</span><span class="fragment">
~ docker run --rm -it <mark>--init</mark> alpine sh
/ # ps
</span><span class="fragment">PID USER TIME COMMAND
1 root 0:00 <mark>/dev/init -- sh</mark>
8 root 0:00 sh
9 root 0:00 ps
/ #
</span>
</code>
</pre>
</section>
<!-- docker compose with init -->
<section>
<h2>init in compose requires 2.2</h2>
<pre>
<code data-trim data-noescape>
version: <mark>'2.2'</mark>
services:
web-1:
image: alpine:latest
init: true
web-2:
image: alpine:latest
init: /usr/libexec/docker-init
</span>
</code>
</pre>
</section>
<!-- docker image build with tini -->
<section>
<h2>Make it default in case users forget to add init config</h2>
<pre>
<code data-trim data-noescape>
ENV TINI_VERSION v0.18.0
RUN set -x \
&& curl -fSL "https://github.com/krallin/tini/releases/download/$TINI_VERSION/tini" -o /usr/local/bin/tini \
&& curl -fSL "https://github.com/krallin/tini/releases/download/$TINI_VERSION/tini.asc" -o /usr/local/bin/tini.asc \
&& export GNUPGHOME="$(mktemp -d)" \
&& gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys 6380DC428747F6C393FEACA59A84159D7001A4E5 \
&& gpg --batch --verify /usr/local/bin/tini.asc /usr/local/bin/tini \
&& rm -r "$GNUPGHOME" /usr/local/bin/tini.asc \
&& chmod +x /usr/local/bin/tini \
&& tini -h
ENTRYPOINT ["/usr/local/bin/tini"]
</code>
</pre>
</section>
</section>
<!-- Slide: dumb-init -->
<section>
<section>
<h2>dumb-init</h2>
<p>https://github.com/Yelp/dumb-init</p>
</section>
<section>
<pre>
<code data-trim data-noescape>
# Installing
# via apt
apt install dumb-init
# via pip
pip install dumb-init
# download binary during build
RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_amd64
RUN chmod +x /usr/local/bin/dumb-init
# Using
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
</code>
</pre>
</section>
</section>
<!-- Slide: tini or dumb-init? -->
<section>
<section>
<h2>tini or dumb-init?</h2>
<ul>
<li class="fragment">compiled against glibc or musl, both < 1MB </li>
<li class="fragment">need signal <a data-preview-link href="https://github.com/Yelp/dumb-init#signal-rewriting">rewrite</a>? dumb-init</li>
<li class="fragment">need <a data-preview-link href="https://github.com/krallin/tini#subreaping">subreaping</a>? tini</li>
<li class="fragment">not sure? Any of them will do!</li>
</ul>
</section>
</section>
<!-- Slide: S6 -->
<section>
<section>
<h2>s6-overlay</h2>
<p>https://github.com/just-containers/s6-overlay</p>
</section>
<section>
<h3>Stages</h3>
<ol>
<li class="fragment">Startup of s6</li>
<li class="fragment">User's files:
<ul>
<li class="fragment">Fix ownership & perms: /etc/fix-attrs.d</li>
<li class="fragment">Exec init scripts: /etc/cont-init.d</li>
<li class="fragment">Services: /etc/services.d</li>
</ul>
</li>
<li class="fragment">Shutdown & cleanup: /etc/cont-finish.d <br/>(with SIGTERM followed by SIGKILL after grace period)</li>
</ol>
<p class="fragment">About 3MB uncompressed</p>
</section>
</section>
<!-- Slide: S6 -->
<section>
<section>
<h2>S6</h2>
<pre>
<code data-trim>
FROM alpine:3.8
ADD https://github.com/just-containers/s6-overlay/releases/download/v1.21.8.0/s6-overlay-amd64.tar.gz /tmp/
RUN tar zxvf /tmp/s6-overlay-amd64.tar.gz -C /
ENTRYPOINT ["/init"]
</code>
<code data-trim>
$ docker build -t s6base .
</code>
</pre>
</section>
<section>
<pre>
<code data-trim>
$ docker run --rm -it s6base sh
</code>
<code data-trim>
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
/ # ^C
/ # [cmd] sh exited 130
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] syncing disks.
[s6-finish] sending all processes the TERM signal.
[s6-finish] sending all processes the KILL signal and exiting.
</code>
</pre>
</section>
<section>
<h2>Example use-case</h2>
<pre>
<code data-trim>
docker/etc/
├── cont-init.d
│ ├── 001-apache-modules
│ └── 001-disable-opcache-for-dev
├── cont-finish.d
│ └── cleanup
├── fix-attrs.d
│ └── www
└── services.d
└── php-fpm
└── run
</code>
</pre>
</section>
<section>
<p>cont-init.d/001-apache-modules</p>
<pre>
<code data-trim>
#!/usr/bin/with-contenv sh
a2enmod rewrite proxy proxy_fcgi proxy_http setenvif > /dev/null
a2enconf php7.2-fpm > /dev/null
</code>
</pre>
</section>
<section>
<p>cont-init.d/001-disable-opcache-for-dev</p>
<pre>
<code data-trim data-noescape>
#!/usr/bin/<mark>with-contenv</mark> sh
if [ "<mark>$MY_ENV</mark>" = "development" ]; then
sed -i /etc/php/7.2/fpm/php.ini -e 's/opcache.enable=1/opcache.enable=0/'
fi
</code>
</pre>
</section>
<section>
<p>cont-finish.d/cleanup</p>
<pre>
<code data-trim data-noescape>
#!/usr/bin/with-contenv sh
echo "Cleaning up..."
</code>
</pre>
</section>
<section>
<p>fix-attrs.d/www</p>
<pre>
<code data-trim>
/path recurse account file_perm dir_perm
</code>
<code data-trim>
/var/www/html/ true www-data,1001:1001 0644 0755
</code>
</pre>
<p class="fragment">
Recursively set permission to www-data or fallback to 1001:1001. Files are set 0644, folders 0755.
</p>
</section>
<section>
<p>services.d/php-fpm/run</p>
<pre>
<code data-trim>
#!/usr/bin/execlineb -P
php-fpm7.2 -F
</code>
</pre>
<p class="fragment">
No env is passed. Starts PHP-FPM in foreground.
</p>
</section>
<section>
<p>services.d/php-fpm/finish</p>
<pre>
<code data-trim>
#!/usr/bin/execlineb -S1
if { s6-test ${1} -ne 0 }
if { s6-test ${1} -ne 256 }
s6-svscanctl -t /var/run/s6/services
</code>
</pre>
<p class="fragment">
Terminate all services in /var/run/s6/services/ <br/>if php-fpm crashed
</p>
</section>
</section>
<!-- Slide: s6 cool features -->
<section>
<section>
<h2>Other features</h2>
</section>
<section>
<h2>Drop privileges</h2>
<pre>
<code data-trim>
#!/usr/bin/execlineb -P
s6-setuidgid www-data
nginx -g "daemon off;"
</code>
</pre>
<p>
À la gosu, su-exec, et al.<br/>
(check out other <code>s6-*</code> bins)
</p>
</section>
<section>
<h2>Container env</h2>
<pre>
<code data-trim>
#!/usr/bin/with-contenv sh
</code>
</pre>
<p class="fragment">
Use <code>with-contenv</code> helper or set <code>S6_KEEP_ENV=1</code>
</p>
</section>
<section>
<h2>Don't change permission</h2>
<pre>
<code data-trim>
S6_READ_ONLY_ROOT=1
</code>
</pre>
<p class="fragment" style="text-align: left;">
Without this, S6 will <br/>
<code style="font-size: 0.5em;">chown -R root:root /etc/{cont-init.d,cont-finish.d,fix-attrs.d,services.d}/</code>
<br/>
With this, S6 will copy those folders to <code>/var/run/s6/etc</code> and leave your mounted init scripts untouched
</p>
</section>
<section>
<h2><code>execline</code></h2>
<ul>
<li>An execline script is a single argv, made of a chain of programs designed to perform their action then <code>exec()</code> into the next one</li>
<li class="fragment"><code>execlineb</code>: launcher that parses text file, converts it to argv then executes into that argv</li>
<li class="fragment">simple, which in turn provides better portability and performance than <code>sh</code></li>
<li class="fragment">:( size limit — argv</li>
<li class="fragment">:( no signal handling</li>
</ul>
</section>
<section>
<h2>...and lots more</h2>
<p>
<code>S6_LOGGING</code><br/>
<code>S6_BEHAVIOUR_IF_STAGE2_FAILS</code><br/>
...
</p>
</section>
</section>
<!-- Slide: TQ -->
<section>
<h2>Thanks</h2>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
slideNumber: true,
fragmentInURL: true,
dependencies: [
// Speaker notes
{ src: 'plugin/notes/notes.js', async: true },
// Syntax highlight for <code> elements>
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
// Zoom in and out with Alt+click
{ src: 'plugin/zoom-js/zoom.js', async: true },
]
});
</script>
</body>
</html>