Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch:...

29
Initskripte Linking zsh / mksh hal udev / mdev Abschluss Keep It Simple and Stupid Das KISS-Prinzip in der Praxis Daniel Friesel Maximilian Gaß Chaosdorf 30. April 2010 Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Transcript of Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch:...

Page 1: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Keep It Simple and StupidDas KISS-Prinzip in der Praxis

Daniel Friesel Maximilian Gaß

Chaosdorf

30. April 2010

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 2: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Was ist KISS?

KISS – Keep It Simple and Stupid

(auch: Keep It Simple, Stupid)

Es geht nicht primar um Bloat oder Performancevorteile

Quick C ist nicht Quick, SMTP ist nicht Simple, LDAPist nicht Lightweight, SQL ist nicht Structured, Windows2000 Professional ist nicht Professional. Seht ihr? Istdoch ganz einfach.

– Felix von Leitner, de.comp.security.misc

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 3: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Was ist KISS?

KISS – Keep It Simple and Stupid

(auch: Keep It Simple, Stupid)

Es geht nicht primar um Bloat oder Performancevorteile

Quick C ist nicht Quick, SMTP ist nicht Simple, LDAPist nicht Lightweight, SQL ist nicht Structured, Windows2000 Professional ist nicht Professional. Seht ihr? Istdoch ganz einfach.

– Felix von Leitner, de.comp.security.misc

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 4: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

DebianArch LinuxdaemontoolsupstartFazit

Initskripte

Was sind Initskripte?

Starten/Stoppen Services (Daemons)

Integraler Bestandteil jedes unixoiden Systems

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 5: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

DebianArch LinuxdaemontoolsupstartFazit

Debian I

1 #!/ b i n / sh23 ### BEGIN INIT INFO4 # P r o v i d e s : mpd5 # Requi red−S t a r t : $ l o c a l f s $ r e m o t e f s6 # Requi red−Stop : $ l o c a l f s $ r e m o t e f s7 # Should−S t a r t : a u t o f s $network a l s a−u t i l s p u l s e a u d i o8 # Should−Stop : a u t o f s $network a l s a−u t i l s p u l s e a u d i o9 # D e f a u l t−S t a r t : 2 3 4 5

10 # D e f a u l t−Stop : 0 1 611 # Short−D e s c r i p t i o n : Music P l a y e r Daemon12 # D e s c r i p t i o n : S t a r t t h e Music P l a y e r Daemon (MPD) s e r v i c e13 # f o r network a c c e s s to t h e l o c a l a u d i o queue .14 ### END INIT INFO1516 . / l i b / l s b / i n i t−f u n c t i o n s1718 PATH=/ s b i n : / b i n : / u s r / s b i n : / u s r / b i n19 NAME=mpd20 DESC=”Music P l a y e r Daemon”21 DAEMON=/u s r / b i n /mpd22 MPDCONF=/e t c /mpd . c o n f23 START MPD=t r u e2425 # E x i t i f t h e package i s not i n s t a l l e d

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 6: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

DebianArch LinuxdaemontoolsupstartFazit

Debian II

26 [ −x ”$DAEMON” ] | | e x i t 02728 # Read c o n f i g u r a t i o n v a r i a b l e f i l e i f i t i s p r e s e n t29 [ −r / e t c / d e f a u l t /$NAME ] && . / e t c / d e f a u l t /$NAME3031 i f [ −n ”$MPD DEBUG” ] ; then32 s e t −x33 MPD OPTS=−−v e r b o s e34 f i3536 DBFILE=$ ( sed −n ’ s / ˆ [ [ : s p a c e : ] ] ∗ d b f i l e [ [ : s p a c e : ] ]∗”\?\ ( [ˆ” ]∗\ )\”\?/\1/ p ’ $MPDCONF)37 PIDFILE=$ ( sed −n ’ s / ˆ [ [ : s p a c e : ] ] ∗ p i d f i l e [ [ : s p a c e : ] ]∗”\?\ ( [ˆ” ]∗\ )\”\?/\1/ p ’ $MPDCONF)3839 m p d s t a r t ( ) {40 i f [ ”$START MPD” != ” t r u e ” ] ; then41 l o g a c t i o n m s g ”Not s t a r t i n g MPD: d i s a b l e d by / e t c / d e f a u l t /$NAME” .42 e x i t 043 f i4445 log daemon msg ” S t a r t i n g $DESC” ”$NAME”4647 i f [ −z ” $PIDFILE ” −o −z ”$DBFILE” ] ; then48 l o g f a i l u r e m s g \49 ”$MPDCONF must have d b f i l e and p i d f i l e s e t ; cannot s t a r t daemon . ”50 e x i t 1

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 7: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

DebianArch LinuxdaemontoolsupstartFazit

Debian III

51 f i5253 PIDDIR=$ ( di rname ” $PIDFILE ”)54 i f [ ! −d ”$PIDDIR” ] ; then55 mkdir −m 0755 $PIDDIR56 chown mpd : a u d i o $PIDDIR57 f i5859 i f [ ”$FORCE CREATE DB” −o ! −f ”$DBFILE” ] ; then60 l o g w a r n i n g m s g ” c r e a t i n g $DBFILE . . . ”61 $DAEMON −−c r e a t e−db ”$MPDCONF” > / dev / n u l l 2>&162 f i6364 s t a r t−stop−daemon −−s t a r t −−q u i e t −−oknodo −−p i d f i l e ” $PIDFILE ” \65 −−e x e c ”$DAEMON” −− $MPD OPTS ”$MPDCONF”66 l o g e n d m s g $?67 }6869 mpd stop ( ) {70 i f [ ”$START MPD” != ” t r u e ” ] ; then71 l o g f a i l u r e m s g ”Not s t o p p i n g MPD: d i s a b l e d by / e t c / d e f a u l t /$NAME” .72 e x i t 073 f i74 i f [ −z ” $PIDFILE ” ] ; then75 l o g f a i l u r e m s g \

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 8: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

DebianArch LinuxdaemontoolsupstartFazit

Debian IV

76 ”$MPDCONF must have p i d f i l e s e t ; cannot s t o p daemon . ”77 e x i t 178 f i7980 log daemon msg ” S t o p p i n g $DESC” ”$NAME”81 s t a r t−stop−daemon −−s t o p −−q u i e t −−oknodo −−r e t r y 5 −−p i d f i l e ” $PIDFILE ” \82 −−e x e c $DAEMON83 l o g e n d m s g $?84 }8586 # note to s e l f : don ’ t c a l l t h e non−s t a n d a r d a r g s f o r t h i s i n87 # {post , p r e}{ i n s t , rm} s c r i p t s s i n c e u s e r s a r e not f o r c e d to upgrade88 # / e t c / i n i t . d/mpd when mpd i s updated89 c a s e ”$1” i n90 s t a r t )91 m p d s t a r t92 ; ;93 s t o p )94 mpd stop95 ; ;96 r e s t a r t | f o r c e−r e l o a d )97 mpd stop98 m p d s t a r t99 ; ;

100 f o r c e−s t a r t | s t a r t−c r e a t e−db )

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 9: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

DebianArch LinuxdaemontoolsupstartFazit

Debian V

101 FORCE CREATE DB=1102 m p d s t a r t103 ; ;104 f o r c e−r e s t a r t )105 FORCE CREATE DB=1106 mpd stop107 m p d s t a r t108 ; ;109 ∗)110 echo ” Usage : $0 { s t a r t | s t a r t−c r e a t e−db | s t o p | r e s t a r t }”111 e x i t 2112 ; ;113 e s a c

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 10: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

DebianArch LinuxdaemontoolsupstartFazit

Arch Linux I

1 #!/ b i n / bash2 . / e t c / r c . c o n f3 . / e t c / r c . d/ f u n c t i o n s4 c a s e ”$1” i n5 s t a r t )6 s t a t b u s y ” S t a r t i n g Music P l a y e r Daemon”7 / u s r / b i n /mpd / e t c /mpd . c o n f &> / dev / n u l l8 i f [ $? −gt 0 ] ; then9 s t a t f a i l

10 e l s e11 add daemon mpd12 s t a t d o n e13 f i14 ; ;15 s t o p )16 s t a t b u s y ” S t o p p i n g Music P l a y e r Daemon”17 / u s r / b i n /mpd −−k i l l / e t c /mpd . c o n f &> / dev / n u l l18 i f [ $? −gt 0 ] ; then19 s t a t f a i l20 e l s e21 rm daemon mpd22 s t a t d o n e23 f i24 ; ;25 c r e a t e−db )

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 11: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

DebianArch LinuxdaemontoolsupstartFazit

Arch Linux II

26 s t a t b u s y ” C r e a t i n g mpd ’ s d a t a b a s e . . . ”27 l o g p a t h =”/ v a r / l o g /mpd/mpd . db−c r e a t i o n ”28 / u s r / b i n /mpd −−c r e a t e−db / e t c /mpd . c o n f > $ l o g p a t h \29 && s t a t b u s y ” Output w r i t t e n to $ l o g p a t h ”30 s t a t d o n e31 ; ;32 r e s t a r t )33 $0 s t o p34 s l e e p 135 $0 s t a r t36 ; ;37 ∗)38 echo ” usage : $0 { s t a r t | s t o p | r e s t a r t | c r e a t e−db}”39 e s a c40 e x i t 0

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 12: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

DebianArch LinuxdaemontoolsupstartFazit

daemontools

1 #!/ b i n / sh2 e x e c mpd −−no−daemon −−s t d o u t . / mpd . c o n f

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 13: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

DebianArch LinuxdaemontoolsupstartFazit

upstart

1 s t a r t on r u n l e v e l [ 2 3 4 5 ]2 s t o p on r u n l e v e l [ ! 2 3 4 5 ]3 respawn4 e x e c mpd / e t c /mpd . c o n f5 e x p e c t f o r k

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 14: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

DebianArch LinuxdaemontoolsupstartFazit

Fazit

Gewaltige Unterschiede

Simplicity hat in diesem Bereich keine Nachteile

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 15: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Statisches LinkenDynamisches LinkenFazit

Was ist Linking?

Einbinden von Modulen in (C-)Programme

Statisches vs. Dynamisches Linken

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 16: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Statisches LinkenDynamisches LinkenFazit

Statisches Linken

Kein Linken beim Programmstart

Keine Probleme mit ABI-Changes

Weniger Abhangigkeiten auf Libraries

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 17: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Statisches LinkenDynamisches LinkenFazit

Dynamisches Linken

Ein zentraler Patch fixt alle Binaries

Geringerer RAM-Verbrauch und Plattenplatzbedarf

Standard, daher wenig fummelig beim Bauen

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 18: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Statisches LinkenDynamisches LinkenFazit

Fazit

Situationsabhangig, aber dynamisches Linken ist de-factoStandard

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 19: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Nachteile der zshVorteile der mksh/pdkshBequemlichkeit

Zsh vs. mksh

zsh: Z Shell, extrem konfigurierbar und featurereich

mksh / pdksh: Korn Shell-Varianten, konnen einiges, aberweniger

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 20: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Nachteile der zshVorteile der mksh/pdkshBequemlichkeit

Nachteile der zsh

Sehr groß (536KiB Binary, mksh/pdksh: 224/196 KiB)

Hoher RAM-Verbrauch (5-10M pro Instanz)

Sehr komplex

shell programming is like LSD, you often see advantagesthat are not there.

– Zaba

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 21: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Nachteile der zshVorteile der mksh/pdkshBequemlichkeit

Nachteile der zsh

Sehr groß (536KiB Binary, mksh/pdksh: 224/196 KiB)

Hoher RAM-Verbrauch (5-10M pro Instanz)

Sehr komplex

shell programming is like LSD, you often see advantagesthat are not there.

– Zaba

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 22: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Nachteile der zshVorteile der mksh/pdkshBequemlichkeit

Vorteile der mksh/pdksh

Niedriger RAM-Verbrauch (500-800K)

Schnelle Startup-Zeit

Verhaltnismaßig simpel

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 23: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Nachteile der zshVorteile der mksh/pdkshBequemlichkeit

Aber: Bequemlichkeit

zsh kann einfach mehr

→ Abwagen, was einem wichtiger ist

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 24: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

HAL

“Hardware Abstraction Layer”

Input-Hotplug, wobei X einzelne Gerate sehen kann

Hotplug selbst ging und geht auch ohne HAL

Klassisch: Flexibilitat fur wenige → mehr Komplexitat fur alle

Obskure XML-Configs

Inzwischen: libudev

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 25: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

udevmdev

udev vs. mdev

Device-Hotplugging (/dev)

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 26: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

udevmdev

udev

Daemon (Sicherheitsprobleme)

udevadm settle: Teilweise sehr langsam

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 27: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

udevmdev

mdev

Kein Daemon

kein Netlink-Socket, klassische Argumente / Environment

Hat trotzdem fast alle udev-Features

Schnell ( 0.1s fur alle Devicenodes)

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 28: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Fazit

Linux is becoming an idiot box; a nanny operatingsystem. The complexity and the idiot box ideals arekilling the power user, and the spare time developer.

– Tuomo Valkonen

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid

Page 29: Keep It Simple and Stupid Das KISS-Prinzip in der Praxis · KISS { Keep It Simple and Stupid (auch: Keep It Simple, Stupid) Es geht nicht prim ar um Bloat oder Performancevorteile

InitskripteLinking

zsh / mkshhal

udev / mdevAbschluss

Links

suckless.org

harmful.cat-v.org

Daniel Friesel, Maximilian Gaß Keep It Simple and Stupid