your computer; your init; your choice - troubleshooters.com · init jumpering philosophy one way or...

26
Your Computer; Your Init; Your Choice By Steve Litt Copyright © 2015 by Steve Litt Creative Commons Attribution-NoDerivatives 4.0 International License http://creativecommons.org/licenses/by-nd/4.0/legalcode Available online at http://www.troubleshooters.com/linux/presentations/golug_inits/golug_inits.pdf NO WARRANTY, use at your own risk. Your Computer; Your Init; Your Choice Slide 1 of 26 Steve Litt Version 20150108_1348

Upload: truongkhuong

Post on 09-Aug-2019

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Your Computer; Your Init;

Your Choice

By Steve Litt

Copyright © 2015 by Steve LittCreative Commons Attribution-NoDerivatives 4.0 International License

http://creativecommons.org/licenses/by-nd/4.0/legalcode

Available online at http://www.troubleshooters.com/linux/presentations/golug_inits/golug_inits.pdf

NO WARRANTY, use at your own risk.

Your Computer; Your Init; Your ChoiceSlide 1 of 26 Steve Litt

Version 20150108_1348

Page 2: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

System Overview

● Kernel runs one program, init.● Everything else run directly or indirectly by init.

Your Computer; Your Init; Your ChoiceSlide 2 of 26 Steve Litt

Page 3: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Many Different Init Systems● Epoch● OpenRC● RichFelker● s6● sysvinit● uselessd

● nosh● perp● runit● systemd● Upstart

● Many more● There's an init for every situation● You can make your own

Your Computer; Your Init; Your ChoiceSlide 3 of 26 Steve Litt

Page 4: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Full vs Partial

● Kernel->full-init at PID1->daemons– Systemd, sysvinit, runit, Epoch, Upstart, etc.

● Kernel->PID1->partial-init->daemons– OpenRC, daemontools, damontools-encore, etc.

Your Computer; Your Init; Your ChoiceSlide 4 of 26 Steve Litt

Page 5: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Many Features

● Socket Activation

● Event controlled

● Daemontools-like

● Simplicity

● Descriptive config

● Script config

● Parallel starting

● Sequential starting

● Numeric ordering

● Dependency ordering

● Work with sysvinit scripts

● OS toolkit

● Forget features● Look for benefits that fit your priorities and

situation

Your Computer; Your Init; Your ChoiceSlide 5 of 26 Steve Litt

Page 6: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Many Routes to Benefits

● Within and outside of init● With or without sockets● With or without packaging● Cutting edge or oldschool

Your Computer; Your Init; Your ChoiceSlide 6 of 26 Steve Litt

Page 7: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Bogus Characterizations● ___ is a toy.

– What does that even mean?

● ___ is not ready for prime time.– What does that even mean?

● ___ has an April Fools Joke architecture.– What does that even mean?

● ___ lacks features A, B and C.– Different inits deliver benefits using different

features.

– Some benefits aren't important in your use case.Your Computer; Your Init; Your ChoiceSlide 7 of 26 Steve Litt

Page 8: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

YOU Choose Your Init

● It's YOUR computer.● Keep the default if you like it● Replace or jumper the default if you don't.

– Performance

– Technology

– Politics

● You owe nobody an explanation

Your Computer; Your Init; Your ChoiceSlide 8 of 26 Steve Litt

Page 9: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Typical Init Architecture

● Stage 1: Bring up computer– No daemons

– Don't block!

● Stage 2: Manage daemons and ttys– Reap zombies

– Listen for Ctrl+Alt+Del

● Stage 3: Shut down / computer– Don't block!

Your Computer; Your Init; Your ChoiceSlide 9 of 26 Steve Litt

Page 10: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Daemontools Style Inits● Good stuff!● Daemon runs in foreground● Can log stdout and stderr, with timestamps● Most can parallel start services● Very simple run scripts● Examples

– runit

– nosh– s6

– perpYour Computer; Your Init; Your ChoiceSlide 10 of 26 Steve Litt

Page 11: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Ways to Switch Inits● Replacement

– Usually done by packaging● When such packaging exists, at will of packagers

– Removes old init

● Jumper– Usually done by compile and copy

● On almost any distro

– Old init remains functional if called

– Additional init can be a huge advantage

Your Computer; Your Init; Your ChoiceSlide 11 of 26 Steve Litt

Page 12: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Init Jumpering Philosophy

● One way or another, I'll find a way.– This almost always pans out.

● Shellscripts are your friend.– Test at command prompt.

– When tested, call from init.

● YOU are CUSTOM building this.● Simple systems are easier to construct.● It's amazing how simple you can make it when

you eliminate the edge case CYA fluff.

Your Computer; Your Init; Your ChoiceSlide 12 of 26 Steve Litt

Page 13: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Epoch Init System● http://universe2.us/epoch.html

– Contents links on the bottom

● http://universe2.us/collector– Scripts and other stuff.

● Easiest to jumper● Best docs● Does respawning:

– Optionally, per service

● No stage separation

Your Computer; Your Init; Your ChoiceSlide 13 of 26 Steve Litt

Page 14: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Epoch, More Properties

● Single File conf● Sequential load● Numeric order

Your Computer; Your Init; Your ChoiceSlide 14 of 26 Steve Litt

Page 15: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Epoch Installation● Be root● cd /root● Make sure gcc is installed● Download latest release tarball

– From bottom of http://universe2/us/epoch.html● tar xzvf epoch_version_no.tgz● cd epoch-version_no● ./buildepoch.sh● cp -p built/sbin/epoch /usr/bin/epoch

– Or /sbin if it's not a symlink● cp -p built/sbin/epoch /e

Your Computer; Your Init; Your ChoiceSlide 15 of 26 Steve Litt

Page 16: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Epoch Installation Observations

● Builds under /root● No args needed for buildepoch● Copy to install● Adding init=/e inits via Epoch

– After you make epoch.conf

Your Computer; Your Init; Your ChoiceSlide 16 of 26 Steve Litt

Page 17: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Hello World epoch.confBootBannerText=Sorry, Lennart!BootBannerColor=CYAN

Hostname=FILE /etc/hostnameDefaultRunlevel=bootEnableLogging=trueDisableCAD=trueBlankLogOnBoot=trueMountVirtual=procfs sysfs devpts+ devshm+

DefinePriority=Early_Getty_Start 40

ObjectID=getty2 ObjectDescription=Early getty on /dev/tty2 ObjectStartCommand=agetty tty2 & ObjectStopCommand=NONE ObjectStartPriority=Early_Getty_Start ObjectStopPriority=0 ObjectEnabled=true ObjectOptions=SERVICE AUTORESTART ObjectRunlevels=boot

Your Computer; Your Init; Your ChoiceSlide 17 of 26 Steve Litt

Page 18: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Hello World Observations

● Always use DefinePriority ● tty2 can repeatedly log in and out● Change command if computer lacks agetty

● No network, sound, or X capabilities● Reboot with epoch reboot

● Poweroff with epoch poweroff

Your Computer; Your Init; Your ChoiceSlide 18 of 26 Steve Litt

Page 19: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Full Epoch: Start/Stop ordering

Your Computer; Your Init; Your ChoiceSlide 19 of 26

DefinePriority=Udev_Start 20DefinePriority=Rwfs_Start 30DefinePriority=Sysclock_Start 35DefinePriority=Early_Getty_Start 40DefinePriority=Mountall_Start 45DefinePriority=Network_Start 50DefinePriority=Wpa_Sup_Start 53DefinePriority=Dh_Cli_Start 56DefinePriority=Dev_Mixer_Start 60DefinePriority=Typical_Daemon_Start 80DefinePriority=Typical_Getty_Start 70DefinePriority=Display_Manager_Start 120

DefinePriority=Typical_Daemon_Stop 10DefinePriority=Dh_Cli_Stop 20DefinePriority=Wpa_Sup_Stop 21DefinePriority=Display_Manager_Stop 40DefinePriority=Sysclock_Stop 80DefinePriority=Killall5_Soft_Stop 90DefinePriority=Killall5_Stop 91DefinePriority=Rwfs_Stop 100DefinePriority=Mountall_Stop 101

● Hey, where's NetworkManager?● Where's dbus?● That's why it starts wpa_supplicant and dhcpcd.

Steve Litt

Page 20: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Starting udevObjectID=udevd ObjectDescription=Starting udev ObjectStartCommand=/root/udev_start.sh ObjectStopCommand=NONE ObjectStartPriority=Udev_Start ObjectStopPriority=0 ObjectEnabled=true ObjectOptions=RAWDESCRIPTION ObjectRunlevels=boot

#!/bin/sh/usr/lib/systemd/systemd-udevd --daemon/usr/bin/udevadm trigger --action=add --type=subsystems/usr/bin/udevadm trigger --action=add --type=devices/usr/bin/udevadm settle

● Can swap systemd-udevd for vdevd later on.● Udev necessary for network devices

DefinePriority=Udev_Start 20

Your Computer; Your Init; Your ChoiceSlide 20 of 26 Steve Litt

Page 21: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Starting Wifi Network Device

● Requires run udev or install drivers first● Distro independent

hostname -F /etc/hostnameip link set dev lo upip link set dev wlo1 downip link set dev wlo1 up

ObjectID=network ObjectDescription=Setting up net devices and the network ObjectStartCommand=/root/upnet.sh ObjectStopCommand=NONE ObjectStartPriority=Network_Start ObjectStopPriority=0 ObjectEnabled=true ObjectOptions=RAWDESCRIPTION ObjectRunlevels=boot

Your Computer; Your Init; Your ChoiceSlide 21 of 26 Steve Litt

Page 22: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Starting wpa_supplicant

● Links up wifi (wlo1) with ssid in config file● Dbus-free substitute for NetworkManager● Does not obtain an IP address● Runs as a respawning daemon

ObjectID=wpa_supplicant ObjectDescription=wpa_supplicant ObjectStartCommand=/usr/bin/wpa_supplicant -B -iwlo1 -c /etc/wpa_supplicant/wpa_supplicant.conf

ObjectStopCommand=killall wpa_supplicant ObjectStartPriority=Wpa_Sup_Start ObjectStopPriority=Wpa_Sup_Stop ObjectOptions=SERVICE AUTORESTART ObjectEnabled=true ObjectRunlevels=boot

Your Computer; Your Init; Your ChoiceSlide 22 of 26 Steve Litt

Page 23: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Starting dhcpcd

● Wifi device must have been started first● Runs as a respawning daemon

ObjectID=dhclient ObjectDescription=dhclient ObjectStartCommand=/usr/bin/dhclient wlo1 ObjectStopCommand=PIDFILE /run/dhclient.pid ObjectStartPriority=Dh_Cli_Start ObjectStopPriority=Dh_Cli_Stop ObjectOptions=SERVICE AUTORESTART ObjectEnabled=true ObjectRunlevels=boot

Your Computer; Your Init; Your ChoiceSlide 23 of 26 Steve Litt

Page 24: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Starting sshd

● Same as others● Runs as respawning daemon● Wifi must be configged and have IP address

ObjectID=sshd ObjectDescription=Manage sshd daemon ObjectStartCommand=/usr/sbin/sshd ObjectStopCommand=PIDFILE /run/sshd.pid ObjectStartPriority=Typical_Daemon_Start ObjectStopPriority=Typical_Daemon_Stop ObjectEnabled=true ObjectRunlevels=boot ObjectOptions=SERVICE AUTORESTART

Your Computer; Your Init; Your ChoiceSlide 24 of 26 Steve Litt

Page 25: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Troubleshooting Epoch● Docs at http://universe2.us/epoch.html● /var/log/system.log provides boot log.● Get things running on the command line first.● epoch status [objectid]● epoch getpid objectid● epoch configreload● ObjectOptions=STOPFAILCRITICAL● ObjectOptions=STARTFAILCRITICAL

Your Computer; Your Init; Your ChoiceSlide 25 of 26 Steve Litt

Page 26: Your Computer; Your Init; Your Choice - troubleshooters.com · Init Jumpering Philosophy One way or another, I'll find a way. – This almost always pans out. Shellscripts are your

Summary● Many init programs● Your choice

– Keep or switch: Your choice

– Choose for your use case

– You owe nobody any explanations

● Replace or jumper● Daemontools-style have many advantages● Epoch is easiest to jumper

– Great as main or emergency B init

Your Computer; Your Init; Your ChoiceSlide 26 of 26 Steve Litt