SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
From /etc/init to systemd
A journey through the years of

UNIX

and

Linux

service management
Lubomir Rintel <lkundrak@v3.sk>
BTC: 15wvWxN5QMpreKR37pYb7VBu8xLu4TiNR2
Sixth Edition UNIX (1976)
●

/etc/init

(219 lines)

●

●

gettys from /etc/ttys

●

●

Single user shell
utmp & wtmp

/etc/rc

(2 lines)

rm -f /etc/mtab
/etc/update
UNIX System III (1980)
●

/etc/init
●

(486 lines)

/etc/inittab "states" controlling gettys on

terminals
●

/etc/rc

(67 lines)

●

State aware, single user mode

●

acct

●

errdemon

●

cron

●

"edit to add umounts"
2.9 BSD UNIX (1983)
●

/sbin/init

(593 lines)

●

●

●

Single user shell
gettys from /etc/ttys

/etc/rc

(53 lines)

●

fsck, quotacheck

●

mount -a, from /etc/fstab

●

savecore, ex/vi recovery

●

clear /tmp, locks in /usr/spool

●

update, cron, acct

●

hostname
UNIX System V Release 4 (1983)
●

/etc/init
●

●

/etc/inittab with runlevels, respawns

/etc/rc?
●

Modular init system, /etc/rc.d

●

Per-daemon init scripts (8-56 lines, avg. 26)
–
–

●

●

start & stop arguments
pid from ps, stop = kill -TERM

Enablement/disablement by linking into level
dir
Ordered by numbers
#ident

"@(#)/etc/init.d/cron.sl 1.1 4.0 10/15/90 8479 AT&T-SF"

#
cron control
pid=`/usr/bin/ps -e | /usr/bin/grep cron |
/usr/bin/sed -e 's/^ *//' -e 's/ .*//'`
case $1 in
'start')
if [ "${pid}" = "" ]
then
/usr/bin/rm -f /etc/cron.d/FIFO
if [ -x /usr/bin/cron ]
then
/usr/bin/cron
elif [ -x /usr/sbin/cron ]
then
/usr/sbin/cron
fi
fi
;;
'stop')
if [ "${pid}" != "" ]
then
/usr/bin/kill ${pid}
fi
;;
*)
echo "usage: /etc/init.d/cron {start|stop}"
;;
esac
2.11 BSD UNIX (1986)
●

/sbin/init

(782 lines)

●

●

●

Single user
gettys from /etc/gettytab

/etc/rc

(165 lines)

●
●
●

Everything 2.9BSD had
Network, inetd, routed, named, lpd, rwhod

/etc/rc.local
●

Editable for starting local daemons
Red Hat Enterprise Linux 5 (2007)
●

SVR4-like init
●

●

Some BSD elements: /etc/rc, /etc/rc.local

Init scripts LSB compliant
●

61-584 lines, avg. 128

●

start, stop, status, restart, condrestart

●

Pidfiles in /var/run

●

Subsystem locks in /var/lock/subsys

●

/etc/rc.d/functions library

●

/etc/sysconfig init script configuration
#!/bin/bash
#
# sendmail
This shell script takes care of starting and stopping
#
sendmail.
#
# chkconfig: 2345 80 30
# description: Sendmail is a Mail Transport Agent, which is the program 
#
that moves mail from one machine to another.
# processname: sendmail
# config: /etc/mail/sendmail.cf
# pidfile: /var/run/sendmail.pid

if [ -x /usr/bin/make -a -f /etc/mail/Makefile ]; then
make all -C /etc/mail -s > /dev/null
else
for i in virtusertable access domaintable mailertable ; do
if [ -f /etc/mail/$i ] ; then
makemap hash /etc/mail/$i < /etc/mail/$i
fi
done
fi
daemon /usr/sbin/sendmail $([ "x$DAEMON" = xyes ] && echo -bd) 
$([ -n "$QUEUE" ] && echo -q$QUEUE)
RETVAL=$?
killproc sendmail -HUP
RETVAL=$?
echo
if [ $RETVAL -eq 0 -a -f /var/run/sm-client.pid ]; then
echo -n $"reloading sm-client: "
killproc sm-client -HUP
RETVAL=$?
echo
fi
return $RETVAL

# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
# Source sendmail configureation.
if [ -f /etc/sysconfig/sendmail ] ; then
. /etc/sysconfig/sendmail
else
DAEMON=no
QUEUE=1h
fi
[ -z "$SMQUEUE" ] && SMQUEUE="$QUEUE"
[ -z "$SMQUEUE" ] && SMQUEUE=1h

}
stop() {
# Stop daemons.
if test -f /var/run/sm-client.pid ; then
echo -n $"Shutting down sm-client: "
killproc sm-client
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/run/sm-client.pid
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sm-client
fi
echo -n $"Shutting down $prog: "
killproc sendmail
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sendmail
return $RETVAL

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
[ -f /usr/sbin/sendmail ] || exit 0
RETVAL=0
prog="sendmail"
start() {
# Start daemons.
echo -n $"Starting $prog: "
if test -x /usr/bin/make -a -f /etc/mail/Makefile ; then
make all -C /etc/mail -s > /dev/null
else
for i in virtusertable access domaintable mailertable ; do
if [ -f /etc/mail/$i ] ; then
makemap hash /etc/mail/$i < /etc/mail/$i
fi
done
fi
/usr/bin/newaliases > /dev/null 2>&1
daemon /usr/sbin/sendmail $([ "x$DAEMON" = xyes ] && echo -bd) 
$([ -n "$QUEUE" ] && echo -q$QUEUE) $SENDMAIL_OPTARG
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/sendmail
if ! test -f /var/run/sm-client.pid ; then
echo -n $"Starting sm-client: "
touch /var/run/sm-client.pid
chown smmsp:smmsp /var/run/sm-client.pid
if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
/sbin/restorecon /var/run/sm-client.pid
fi
daemon --check sm-client /usr/sbin/sendmail -L sm-msp-queue -Ac 
-q$SMQUEUE $SENDMAIL_OPTARG
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/sm-client
fi
return $RETVAL
reload() {
# Stop daemons.}
echo -n $"reloading $prog: "
/usr/bin/newaliases > /dev/null 2>&1

}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
RETVAL=$?
;;
restart)
stop
start
RETVAL=$?
;;
condrestart)
if [ -f /var/lock/subsys/sendmail ]; then
stop
start
RETVAL=$?
fi
;;
status)
status sendmail
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac
exit $RETVAL
··

ddish):
hket (Yi
far∙pot∙s
pronoun
 a result
ruined as
letely 
erfection
1. comp
inor imp
o f ix a m
ttempts t
of a
Issues
●

inittab
●

service control inflexible

Not actually used very much

●

No way to monitor services

●

Error output is lost

●

Inflexible startup ordering

●

Single-threaded startup
●

●

●

Slow
Malfunctional startup script can lock up boot

Limited to single instance of a service
Issues (cont.)
●

No way to track processes belonging to a service
●

●

No way to reliably terminate a service

●

No way to tell whether the service is operational

●

●

They double-fork to daemonize

Resource hogging

Inconsistent
●

Who drops privileges?

●

Who writes PID files?

●

Who chroots?
SVR4 & LSB init scripts
●

Unbelievably shitty
●

Unreliably work around issues mentioned

●

Very long and ugly

●

Lots of code duplication

●

●

Races, improper
subsystem locks
Insecure PID
determination
How did UNIX address this
●

Sun Solaris 10: SMF
●

●

Multiple service instances

Apple Darwin: launchd
●

●

On demand startup of network daemons (inetd)

●

●

System and User sessions
Job scheduler

Common:
●

●

Dependency management, service ordering

●

●

Parallel startup
Monitoring/restarts of services

Various others: upstart, daemontools, Monit, ...
Linux: systemd
●

Heavily inspired by concepts from launchd

●

Already used in most modern Linux distributions

●

Solves all of the mentioned issues!

●

Leverages Linux inovations -- a lot more powerful
●

Control groups, Namespaces

●

Seccomp, Capabilities, SELinux

●

Auditing

●

Automounter

●

DBus API

●

Structured kernel messaging
systemd Unit types
Unit type

Description/equivalent

service

A daemon (SVR4 init script)

socket

A network or UNIX socket (inetd)

device

UDev device instance

mount

Mount point (fstab)

target

Runlevel

swap

Swap space (fstab)

automount

Autofs

path

Inotify watch

timer

Crond

snapshot

Dynamically created target
httpd.service
├─system.slice
└─basic.target
├─fedora-loadmodules.service
├─paths.target
├─sockets.target
│ ├─cups.socket
│ ├─rpcbind.socket
│ ├─systemd-initctl.socket
│ └─systemd-udevd-kernel.socket
├─sysinit.target
│ ├─kmod-static-nodes.service
│ ├─systemd-udev-trigger.service
│ ├─local-fs.target
│ │ ├─-.mount
│ │ ├─fedora-import-state.service
│ │ ├─home.mount
│ │ ├─systemd-fsck-root.service
│ │ └─tmp.mount
│ └─swap.target
│
└─dev-disk-byx2dlabel-yolo.swap
└─timers.target
└─systemd-tmpfiles-clean.timer
systemd Units
●

Defined from unit files
●
●

●

/lib/systemd
/etc/systemd

Generated automatically
●
●

●

Compatibility or dynamic changes
device unit appears as device appears in
udev
mount units generated from /etc/fstab
Service units
●

Service runs in its own control group

●

Isolated from the rest of system to some extent

●

A process can't escape

●

Freezer control group assures reliable shutdown

●

Service should not double-fork (launchd)

●

systemd-journald takes care of logging

●

Can depend on socket units for activation (inetd)

●

DBus activation also possible
User sessions
●

Manages processes for a user session (e.g. tty
or GNOME desktop)

●

Session runs in separate control group

●

systemd-logind replaces ConsoleKit

●

Multiseat

●

Reliable log-off
Essential tools
systemctl --all
systemctl stop sshd.service
systemctl status sshd
systemctl disable sshd
systemd-cgtop
systemd-cgls
journalctl -f
systemd-analyze blame
systemd-analyze critical-chain
What else
●

Takes care of system-wide events
●
●

Laptop lid close

●

●

Pinging watchdog
Shutdown, kexec

Documentation
●

●

Well written manual pages for everything

Lightweight virtualization (LXC)
●

clone()s all namespaces
Thanks for listening!
Found this useful? My Bitcoin address:
15wvWxN5QMpreKR37pYb7VBu8xLu4TiNR2

Mais conteúdo relacionado

Mais procurados

Mais procurados (19)

Useful linux-commands
Useful linux-commandsUseful linux-commands
Useful linux-commands
 
Zram
ZramZram
Zram
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
Augeas
AugeasAugeas
Augeas
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Vi Editor
Vi EditorVi Editor
Vi Editor
 
Shell & Shell Script
Shell & Shell Script Shell & Shell Script
Shell & Shell Script
 
NUMOSS 4th Week - Commandline Tutorial
NUMOSS 4th Week - Commandline TutorialNUMOSS 4th Week - Commandline Tutorial
NUMOSS 4th Week - Commandline Tutorial
 
Linux Command Line
Linux Command LineLinux Command Line
Linux Command Line
 
4412 SDRAM
4412 SDRAM4412 SDRAM
4412 SDRAM
 
100+ run commands for windows
100+ run commands for windows 100+ run commands for windows
100+ run commands for windows
 
List Command at Run
List Command at RunList Command at Run
List Command at Run
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scripting
 
50 Most Frequently Used UNIX Linux Commands -hmftj
50 Most Frequently Used UNIX  Linux Commands -hmftj50 Most Frequently Used UNIX  Linux Commands -hmftj
50 Most Frequently Used UNIX Linux Commands -hmftj
 
Linux fundamental - Chap 11 boot
Linux fundamental - Chap 11 bootLinux fundamental - Chap 11 boot
Linux fundamental - Chap 11 boot
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scriptingEasiest way to start with Shell scripting
Easiest way to start with Shell scripting
 
Terminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partITerminal basic-commands(Unix) -partI
Terminal basic-commands(Unix) -partI
 
Linux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersLinux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for Beginners
 

Semelhante a A journey through the years of UNIX and Linux service management

Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commandsMichael J Geiser
 
От sysV к systemd
От sysV к systemdОт sysV к systemd
От sysV к systemdDenis Kovalev
 
Andresen 8 21 02
Andresen 8 21 02Andresen 8 21 02
Andresen 8 21 02FNian
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetOmar Reygaert
 
How to go the extra mile on monitoring
How to go the extra mile on monitoringHow to go the extra mile on monitoring
How to go the extra mile on monitoringTiago Simões
 
Beyond Golden Containers: Complementing Docker with Puppet
Beyond Golden Containers: Complementing Docker with PuppetBeyond Golden Containers: Complementing Docker with Puppet
Beyond Golden Containers: Complementing Docker with Puppetlutter
 
Globus toolkit4installationguide
Globus toolkit4installationguideGlobus toolkit4installationguide
Globus toolkit4installationguideAdarsh Patil
 
Docker 基本概念與指令操作
Docker  基本概念與指令操作Docker  基本概念與指令操作
Docker 基本概念與指令操作NUTC, imac
 
Managing your Minions with Func
Managing your Minions with FuncManaging your Minions with Func
Managing your Minions with Funcdanhanks
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis OverviewLeo Lorieri
 
OpenStack Swift - MSST 2011 Tutorial Day
OpenStack Swift - MSST 2011 Tutorial DayOpenStack Swift - MSST 2011 Tutorial Day
OpenStack Swift - MSST 2011 Tutorial DayJoshua McKenty
 
Containers with systemd-nspawn
Containers with systemd-nspawnContainers with systemd-nspawn
Containers with systemd-nspawnGábor Nyers
 
Advanced Level Training on Koha / TLS (ToT)
Advanced Level Training on Koha / TLS (ToT)Advanced Level Training on Koha / TLS (ToT)
Advanced Level Training on Koha / TLS (ToT)Ata Rehman
 
MINCS - containers in the shell script (Eng. ver.)
MINCS - containers in the shell script (Eng. ver.)MINCS - containers in the shell script (Eng. ver.)
MINCS - containers in the shell script (Eng. ver.)Masami Hiramatsu
 

Semelhante a A journey through the years of UNIX and Linux service management (20)

Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commands
 
От sysV к systemd
От sysV к systemdОт sysV к systemd
От sysV к systemd
 
Andresen 8 21 02
Andresen 8 21 02Andresen 8 21 02
Andresen 8 21 02
 
Virtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + PuppetVirtualization and automation of library software/machines + Puppet
Virtualization and automation of library software/machines + Puppet
 
Dev ops
Dev opsDev ops
Dev ops
 
How to go the extra mile on monitoring
How to go the extra mile on monitoringHow to go the extra mile on monitoring
How to go the extra mile on monitoring
 
Beyond Golden Containers: Complementing Docker with Puppet
Beyond Golden Containers: Complementing Docker with PuppetBeyond Golden Containers: Complementing Docker with Puppet
Beyond Golden Containers: Complementing Docker with Puppet
 
Unix 3 en
Unix 3 enUnix 3 en
Unix 3 en
 
EC2
EC2EC2
EC2
 
Mac OSX Terminal 101
Mac OSX Terminal 101Mac OSX Terminal 101
Mac OSX Terminal 101
 
Linux Run Level
Linux Run LevelLinux Run Level
Linux Run Level
 
Globus toolkit4installationguide
Globus toolkit4installationguideGlobus toolkit4installationguide
Globus toolkit4installationguide
 
Docker 基本概念與指令操作
Docker  基本概念與指令操作Docker  基本概念與指令操作
Docker 基本概念與指令操作
 
Managing your Minions with Func
Managing your Minions with FuncManaging your Minions with Func
Managing your Minions with Func
 
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
 
OpenStack Swift - MSST 2011 Tutorial Day
OpenStack Swift - MSST 2011 Tutorial DayOpenStack Swift - MSST 2011 Tutorial Day
OpenStack Swift - MSST 2011 Tutorial Day
 
FreeBSD: Dev to Prod
FreeBSD: Dev to ProdFreeBSD: Dev to Prod
FreeBSD: Dev to Prod
 
Containers with systemd-nspawn
Containers with systemd-nspawnContainers with systemd-nspawn
Containers with systemd-nspawn
 
Advanced Level Training on Koha / TLS (ToT)
Advanced Level Training on Koha / TLS (ToT)Advanced Level Training on Koha / TLS (ToT)
Advanced Level Training on Koha / TLS (ToT)
 
MINCS - containers in the shell script (Eng. ver.)
MINCS - containers in the shell script (Eng. ver.)MINCS - containers in the shell script (Eng. ver.)
MINCS - containers in the shell script (Eng. ver.)
 

Mais de Lubomir Rintel

Namespaces for Kazimir
Namespaces for KazimirNamespaces for Kazimir
Namespaces for KazimirLubomir Rintel
 
Linux Kernel Debugging Essentials workshop
Linux Kernel Debugging Essentials workshopLinux Kernel Debugging Essentials workshop
Linux Kernel Debugging Essentials workshopLubomir Rintel
 
LinuxAlt 2013: Writing a driver for unknown USB device
LinuxAlt 2013: Writing a driver for unknown USB deviceLinuxAlt 2013: Writing a driver for unknown USB device
LinuxAlt 2013: Writing a driver for unknown USB deviceLubomir Rintel
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingLubomir Rintel
 
Reverse Engineering: Writing a Linux driver for an unknown device
Reverse Engineering: Writing a Linux driver for an unknown deviceReverse Engineering: Writing a Linux driver for an unknown device
Reverse Engineering: Writing a Linux driver for an unknown deviceLubomir Rintel
 
Brno meetr: Packaging Ruby Gems into RPM
Brno meetr: Packaging Ruby Gems into RPMBrno meetr: Packaging Ruby Gems into RPM
Brno meetr: Packaging Ruby Gems into RPMLubomir Rintel
 

Mais de Lubomir Rintel (8)

Namespaces for Kazimir
Namespaces for KazimirNamespaces for Kazimir
Namespaces for Kazimir
 
Linux Kernel Debugging Essentials workshop
Linux Kernel Debugging Essentials workshopLinux Kernel Debugging Essentials workshop
Linux Kernel Debugging Essentials workshop
 
Namespaces in Linux
Namespaces in LinuxNamespaces in Linux
Namespaces in Linux
 
LinuxAlt 2013: Writing a driver for unknown USB device
LinuxAlt 2013: Writing a driver for unknown USB deviceLinuxAlt 2013: Writing a driver for unknown USB device
LinuxAlt 2013: Writing a driver for unknown USB device
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profiling
 
Reverse Engineering: Writing a Linux driver for an unknown device
Reverse Engineering: Writing a Linux driver for an unknown deviceReverse Engineering: Writing a Linux driver for an unknown device
Reverse Engineering: Writing a Linux driver for an unknown device
 
SELinux basics
SELinux basicsSELinux basics
SELinux basics
 
Brno meetr: Packaging Ruby Gems into RPM
Brno meetr: Packaging Ruby Gems into RPMBrno meetr: Packaging Ruby Gems into RPM
Brno meetr: Packaging Ruby Gems into RPM
 

Último

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Último (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

A journey through the years of UNIX and Linux service management

  • 1. From /etc/init to systemd A journey through the years of UNIX and Linux service management Lubomir Rintel <lkundrak@v3.sk> BTC: 15wvWxN5QMpreKR37pYb7VBu8xLu4TiNR2
  • 2. Sixth Edition UNIX (1976) ● /etc/init (219 lines) ● ● gettys from /etc/ttys ● ● Single user shell utmp & wtmp /etc/rc (2 lines) rm -f /etc/mtab /etc/update
  • 3. UNIX System III (1980) ● /etc/init ● (486 lines) /etc/inittab "states" controlling gettys on terminals ● /etc/rc (67 lines) ● State aware, single user mode ● acct ● errdemon ● cron ● "edit to add umounts"
  • 4. 2.9 BSD UNIX (1983) ● /sbin/init (593 lines) ● ● ● Single user shell gettys from /etc/ttys /etc/rc (53 lines) ● fsck, quotacheck ● mount -a, from /etc/fstab ● savecore, ex/vi recovery ● clear /tmp, locks in /usr/spool ● update, cron, acct ● hostname
  • 5. UNIX System V Release 4 (1983) ● /etc/init ● ● /etc/inittab with runlevels, respawns /etc/rc? ● Modular init system, /etc/rc.d ● Per-daemon init scripts (8-56 lines, avg. 26) – – ● ● start & stop arguments pid from ps, stop = kill -TERM Enablement/disablement by linking into level dir Ordered by numbers
  • 6. #ident "@(#)/etc/init.d/cron.sl 1.1 4.0 10/15/90 8479 AT&T-SF" # cron control pid=`/usr/bin/ps -e | /usr/bin/grep cron | /usr/bin/sed -e 's/^ *//' -e 's/ .*//'` case $1 in 'start') if [ "${pid}" = "" ] then /usr/bin/rm -f /etc/cron.d/FIFO if [ -x /usr/bin/cron ] then /usr/bin/cron elif [ -x /usr/sbin/cron ] then /usr/sbin/cron fi fi ;; 'stop') if [ "${pid}" != "" ] then /usr/bin/kill ${pid} fi ;; *) echo "usage: /etc/init.d/cron {start|stop}" ;; esac
  • 7. 2.11 BSD UNIX (1986) ● /sbin/init (782 lines) ● ● ● Single user gettys from /etc/gettytab /etc/rc (165 lines) ● ● ● Everything 2.9BSD had Network, inetd, routed, named, lpd, rwhod /etc/rc.local ● Editable for starting local daemons
  • 8. Red Hat Enterprise Linux 5 (2007) ● SVR4-like init ● ● Some BSD elements: /etc/rc, /etc/rc.local Init scripts LSB compliant ● 61-584 lines, avg. 128 ● start, stop, status, restart, condrestart ● Pidfiles in /var/run ● Subsystem locks in /var/lock/subsys ● /etc/rc.d/functions library ● /etc/sysconfig init script configuration
  • 9. #!/bin/bash # # sendmail This shell script takes care of starting and stopping # sendmail. # # chkconfig: 2345 80 30 # description: Sendmail is a Mail Transport Agent, which is the program # that moves mail from one machine to another. # processname: sendmail # config: /etc/mail/sendmail.cf # pidfile: /var/run/sendmail.pid if [ -x /usr/bin/make -a -f /etc/mail/Makefile ]; then make all -C /etc/mail -s > /dev/null else for i in virtusertable access domaintable mailertable ; do if [ -f /etc/mail/$i ] ; then makemap hash /etc/mail/$i < /etc/mail/$i fi done fi daemon /usr/sbin/sendmail $([ "x$DAEMON" = xyes ] && echo -bd) $([ -n "$QUEUE" ] && echo -q$QUEUE) RETVAL=$? killproc sendmail -HUP RETVAL=$? echo if [ $RETVAL -eq 0 -a -f /var/run/sm-client.pid ]; then echo -n $"reloading sm-client: " killproc sm-client -HUP RETVAL=$? echo fi return $RETVAL # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. [ -f /etc/sysconfig/network ] && . /etc/sysconfig/network # Source sendmail configureation. if [ -f /etc/sysconfig/sendmail ] ; then . /etc/sysconfig/sendmail else DAEMON=no QUEUE=1h fi [ -z "$SMQUEUE" ] && SMQUEUE="$QUEUE" [ -z "$SMQUEUE" ] && SMQUEUE=1h } stop() { # Stop daemons. if test -f /var/run/sm-client.pid ; then echo -n $"Shutting down sm-client: " killproc sm-client RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/run/sm-client.pid [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sm-client fi echo -n $"Shutting down $prog: " killproc sendmail RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sendmail return $RETVAL # Check that networking is up. [ "${NETWORKING}" = "no" ] && exit 0 [ -f /usr/sbin/sendmail ] || exit 0 RETVAL=0 prog="sendmail" start() { # Start daemons. echo -n $"Starting $prog: " if test -x /usr/bin/make -a -f /etc/mail/Makefile ; then make all -C /etc/mail -s > /dev/null else for i in virtusertable access domaintable mailertable ; do if [ -f /etc/mail/$i ] ; then makemap hash /etc/mail/$i < /etc/mail/$i fi done fi /usr/bin/newaliases > /dev/null 2>&1 daemon /usr/sbin/sendmail $([ "x$DAEMON" = xyes ] && echo -bd) $([ -n "$QUEUE" ] && echo -q$QUEUE) $SENDMAIL_OPTARG RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sendmail if ! test -f /var/run/sm-client.pid ; then echo -n $"Starting sm-client: " touch /var/run/sm-client.pid chown smmsp:smmsp /var/run/sm-client.pid if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then /sbin/restorecon /var/run/sm-client.pid fi daemon --check sm-client /usr/sbin/sendmail -L sm-msp-queue -Ac -q$SMQUEUE $SENDMAIL_OPTARG RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sm-client fi return $RETVAL reload() { # Stop daemons.} echo -n $"reloading $prog: " /usr/bin/newaliases > /dev/null 2>&1 } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload RETVAL=$? ;; restart) stop start RETVAL=$? ;; condrestart) if [ -f /var/lock/subsys/sendmail ]; then stop start RETVAL=$? fi ;; status) status sendmail RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart|condrestart|status}" exit 1 esac exit $RETVAL
  • 11. Issues ● inittab ● service control inflexible Not actually used very much ● No way to monitor services ● Error output is lost ● Inflexible startup ordering ● Single-threaded startup ● ● ● Slow Malfunctional startup script can lock up boot Limited to single instance of a service
  • 12. Issues (cont.) ● No way to track processes belonging to a service ● ● No way to reliably terminate a service ● No way to tell whether the service is operational ● ● They double-fork to daemonize Resource hogging Inconsistent ● Who drops privileges? ● Who writes PID files? ● Who chroots?
  • 13. SVR4 & LSB init scripts ● Unbelievably shitty ● Unreliably work around issues mentioned ● Very long and ugly ● Lots of code duplication ● ● Races, improper subsystem locks Insecure PID determination
  • 14. How did UNIX address this ● Sun Solaris 10: SMF ● ● Multiple service instances Apple Darwin: launchd ● ● On demand startup of network daemons (inetd) ● ● System and User sessions Job scheduler Common: ● ● Dependency management, service ordering ● ● Parallel startup Monitoring/restarts of services Various others: upstart, daemontools, Monit, ...
  • 15. Linux: systemd ● Heavily inspired by concepts from launchd ● Already used in most modern Linux distributions ● Solves all of the mentioned issues! ● Leverages Linux inovations -- a lot more powerful ● Control groups, Namespaces ● Seccomp, Capabilities, SELinux ● Auditing ● Automounter ● DBus API ● Structured kernel messaging
  • 16. systemd Unit types Unit type Description/equivalent service A daemon (SVR4 init script) socket A network or UNIX socket (inetd) device UDev device instance mount Mount point (fstab) target Runlevel swap Swap space (fstab) automount Autofs path Inotify watch timer Crond snapshot Dynamically created target
  • 17. httpd.service ├─system.slice └─basic.target ├─fedora-loadmodules.service ├─paths.target ├─sockets.target │ ├─cups.socket │ ├─rpcbind.socket │ ├─systemd-initctl.socket │ └─systemd-udevd-kernel.socket ├─sysinit.target │ ├─kmod-static-nodes.service │ ├─systemd-udev-trigger.service │ ├─local-fs.target │ │ ├─-.mount │ │ ├─fedora-import-state.service │ │ ├─home.mount │ │ ├─systemd-fsck-root.service │ │ └─tmp.mount │ └─swap.target │ └─dev-disk-byx2dlabel-yolo.swap └─timers.target └─systemd-tmpfiles-clean.timer
  • 18. systemd Units ● Defined from unit files ● ● ● /lib/systemd /etc/systemd Generated automatically ● ● ● Compatibility or dynamic changes device unit appears as device appears in udev mount units generated from /etc/fstab
  • 19. Service units ● Service runs in its own control group ● Isolated from the rest of system to some extent ● A process can't escape ● Freezer control group assures reliable shutdown ● Service should not double-fork (launchd) ● systemd-journald takes care of logging ● Can depend on socket units for activation (inetd) ● DBus activation also possible
  • 20. User sessions ● Manages processes for a user session (e.g. tty or GNOME desktop) ● Session runs in separate control group ● systemd-logind replaces ConsoleKit ● Multiseat ● Reliable log-off
  • 21. Essential tools systemctl --all systemctl stop sshd.service systemctl status sshd systemctl disable sshd systemd-cgtop systemd-cgls journalctl -f systemd-analyze blame systemd-analyze critical-chain
  • 22. What else ● Takes care of system-wide events ● ● Laptop lid close ● ● Pinging watchdog Shutdown, kexec Documentation ● ● Well written manual pages for everything Lightweight virtualization (LXC) ● clone()s all namespaces
  • 23. Thanks for listening! Found this useful? My Bitcoin address: 15wvWxN5QMpreKR37pYb7VBu8xLu4TiNR2