Rakesh Jain Profile picture
Nov 30, 2021 44 tweets 11 min read Read on X
What is systemd and why should Linux users care about it?

Everything about "systemd" !!

A Mega Thread 👇 https://everyday.codes/
What is systemd ?

systemd is the glue that holds Linux systems together. systemd is a collection of building blocks, which handle services, processes, logging, network connectivity and even authentication. PC: https://images.techhive.com/ & ZDNet
systemd handles the boot process for Linux systems. As an init implementation, it has a PID of 1 like other init systems, such as System V, Upstart.

It was designed as a replacement for SystemV and LSB-style startup scrips, which were prevalent since 1980s.
Components-

systemd- The system and service manager
systemctl- A command line tool to interact with systemd
journald- A unified logging framework
logind- A daemon that handles user logins & seats
resolved, timesyncd, & networkd, which r responsible for nw connection, dns resolv
What’s init?

An init program is usually the first to start and the last to stop. It initializes & terminates programs and services crucial to d operation of Linux systems.

It’s also a daemon process that runs during the entire lifetime of all programs in the system.
System V init-

This is the traditional init system (also pronounced as “sys five”). It consists of several scripts that start various services expected to run on a runlevel. In System V, the state of a Linux machine at any particular stage points to a runlevel. PC: https://bytexd.com/
SysV Limitations -
It has a lot of deficiencies that make startup time slower. Since shell scripts execute line-by-line, system execution isn’t parallelized.

If there is an error with a script’s execution, it would have to time-out before d next script in line gets executed.
Upstart-

Ubuntu’s implementation of d init system. It solves d problems associated with SysV. Rather than execute scripts during a runlevel, upstart manages d system state by reacting to events. An event occurs when a hot-plug device is connected/removed from the machine. PC: https://mlb4r4okoseb.i.optimole.com/
Why systemd?

It is capable of starting svcs in parallel, which speeds up d boot process. It is also capable of handling hot-plug devices such as starting up svcs on demand at d occurrence of an event (like upstart)

It makes svc mgmt easier by placing their processes in a cgroup
Here, spawned processes are made members of their parent cgroup (named after d service). These processes are not capable of leaving their cgroup until their parent terminates them. This prevents d creation of zombie processes. PC: https://www.scylladb.com/
What are systemd units?

systemd provides a dependency system bn various entities called “units”. Units encapsulate various objects that are relevant for system boot-up & maintenance.

A unit type is a type of task that’s relevant to the management of a Linux system.
Unit files are found in three different places:

/etc/systemd/system: Local configuration

/run/systemd/system: Runtime configuration

/lib/systemd/system: Distribution-wide configs

/usr/lib/systemd/system/: Contains default systemd unit configs as per contained in the rpm
There are 11 types of units in systemd. I will mention d most common ones.

1. Service units: This unit defines how to manage service daemons controlled by systemd. Unit files of this service end with .service.
2. Socket units: This contains info abt local inter-process communication or nw sockets in a Linux system.

3. Target units: This is used to provide sync amongst unit files during boot-up. It can also be used as a medium to extend scope by specifying their targets to othr targets
4. Device units: This unit describes devices that need exposure to systemd by udev and sysfs filesystem.

5. Mount units: This defines a mount point for attaching filesystems controlled by systemd.

6. Automount units: This provides automount capabilities.
7. Timer units: This unit (like cron) defines a timer controlled by systemd. It schedules d activation of other units.

8. Swap units: This describes a memory swap partition.

9. Path units: This can define a path dat activates other sevices wen files within d path r modified.
10. Slice units: Now this is a special unit. It’s used in conjunction with cgroups to group processes, daemons, services into one hierarchical tree for the management of resources.

11. Scope units: This manages externally created processes. See man 5 systemd.scope.
All unit files begin with a section marked [Unit] which contains basic information and dependencies, for example:

[Unit]
Description=D-Bus System Message Bus
Documentation=man:dbus-daemon(1)
Requires=dbus.socket
Diff between unit dependencies Requires, Wants and Conflicts -

Requires: A list of units that this unit depends on, which is started wen this unit is started

Wants: A weaker form of Requires: d units listed r started but d current unit is not stopped if any of them fail
Conflicts: A negative dependency: the units listed are stopped when this one is started and, conversely, if one of them is started, this one is stopped
The keywords Before & After determine d order in which they r started. The order of stopping is just d reverse of d start order:

Before: This unit should be started before the units listed

After: This unit should be started after the units listed
In d following example, d After directive makes sure that d web server is started after d nw:

[Unit]
Description=Lighttpd Web Server
After=network.target

In d absence of Before/After directives, d units will be started or stopped in parallel wid no particular ordering.
What is a Service in systemd?

It is a daemon that can be started & stopped, equivalent to a SysV service. for eg, ssh.service.

A service unit has a [Service] section that describes how it should be run.
These are the cmds to run when starting the service & restarting it.
Let’s talk a bit about the directives of the Service section:

Type: This defines services by their process and daemonizing behavior.

ExecStart: This directive set the path and arguments of the executable command for the unit.
ExecStartPre: This specifies an additional cmd that executes before ExecStart.

ExecStartPost: This configures d path to cmds that will be executed after ExecStart.

ExecReload: This defines a cmd to reload d svc file.

Restart: systemd restarts d svc when this point is reached.
Targets -

A target is another type of unit which groups svcs (or other types of unit). Its a type of unit that only hs dependencies. Targets hv names ending in .target, for eg, multi-user.target.

A target is a desired state, which performs d same role as SysV runlevels. PC: https://www.linuxnix.com/
Basic Unit Management -

Start the service:

systemctl start nginx.service
Check the status of the Service -

systemctl status nginx.service
Stop the Service -

systemctl stop nginx.service
Restart the service -

systemctl restart nginx.service
To attempt to reload the service without interrupting normal functionality -

systemctl reload nginx.service
Enabling or Disabling Units -

By default, most systemd unit files are not started automatically at boot. To configure this functionality, you need to “enable” to unit.

To enable a service to start automatically at boot, type:

systemctl enable nginx.service
To disable the service at boot time -

systemctl disable nginx.service
Getting an Overview of the System State -

To get all of the unit files that systemd has listed as “active”

# systemctl list-units
To list all of the units that systemd has loaded or attempted to load into memory, including those that are not currently active, add the --all switch:

systemctl list-units --all
To list all of the units installed on the system, including those that systemd has not tried to load into memory, type:

systemctl list-unit-files
Using Targets (Runlevels)

To see all of the targets available on your system, type:

systemctl list-unit-files --type=target
To view the default target that systemd tries to reach at boot (which in turn starts all of the unit files that make up the dependency tree of that target), type:

systemctl get-default
Change the default target that will be used at boot by using the set-default option:

systemctl set-default multi-user.target
To see what units are tied to a target, you can type:

systemctl list-dependencies multi-user.target
Stopping or Rebooting the Server -

For some of the major states that a system can transition to, shortcuts are available. For instance, to power off your server, you can type:

systemctl poweroff
If you wish to reboot the system instead, that can be accomplished by typing:

systemctl reboot
You can boot into rescue mode by typing:

systemctl rescue
Retweet the thread if you liked it.

Follow me for more such content.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Rakesh Jain

Rakesh Jain Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @devops_tech

Apr 29
🔍 AIOps vs. DevOps
Can AIOps Replace the Whole DevOps? 🔄

A thread🧵👇 Image
1/ 💡 Culture Matters:

DevOps isn't just about tools; it's about teamwork and making things better together. AIOps helps with some tasks, but it can't fix team dynamics.

Example: In DevOps, developers and IT folks work closely to solve problems faster.
2/ 💻 From Idea to Reality:

DevOps handles everything from planning to getting the software out there. AIOps helps with some steps, but it doesn't cover everything DevOps does.

Example: In DevOps, everyone works together to build and release software smoothly.
Read 9 tweets
Apr 24
🚨Interview Guide!

AWS☁️Networking Interview Questions & Answers👇

#AWS #Cloud #networking #interview #Guide
1/15 Q: What is the difference b/n an Internet Gateway (IGW) & a NAT Gateway in AWS networking?

A: An IGW allows communication b/n instances in a VPC & the internet, while a NAT Gateway enables outbound internet traffic from private subnets without exposing their IP addresses.
2/15 Q: Explain the concept of VPC peering in AWS.

A: VPC peering allows connecting two VPCs privately to share resources, like EC2 instances, without traversing the internet. It enables communication using private IP addresses across peered VPCs. #AWSNetworkingInterview
Read 25 tweets
Apr 22
🚨Kubernetes Interview Guide!

A thread with 15 interview questions & answers for new/intermediate administrators ⚓️👇
1/15: Question: What is a Kubernetes Pod, and why is it used?

Answer: A Pod is the smallest deployable unit in Kubernetes, representing one or more containers that share resources. It's used to deploy, manage, and scale containers.
2/15: Question: How does Kubernetes manage container networking?

Answer: Kubernetes uses the Container Network Interface (CNI) to manage container networking. CNI plugins allow for different network configurations and overlays, enabling communication between pods across nodes.
Read 19 tweets
Apr 20
🚨Linux Interview Guide!🚨

A thread with 15 advanced questions &answers 🐧👇 Image
1️⃣ Q: How do you optimize disk I/O performance in Linux?

A: Utilize techniques like RAID striping, I/O schedulers (e.g., deadline, noop), and file system optimizations (e.g., tuning journaling options).
2️⃣ Q: Explain the concept of kernel namespaces in Linux.

A: Kernel namespaces isolate and virtualize system resources, enabling processes to have their own view of the system, improving security and resource management.
Read 18 tweets
Apr 18
🚨🚨Interview Guide!

15 Docker scenario-based interview questions and answers 👇🛳️
Q1: U r tasked with deploying a multi-container app on Docker. How would u orchestrate these containers effectively?

A: Utilize Docker Compose, defining services, networks, & volumes in a YAML file. It simplifies multi-container deployments, ensuring consistency & scalability.
Q2: ur team wants to ensure seamless updates without downtime. How would u achieve zero-downtime deployments with Docker?

A: Implement rolling updates with Docker Swarm/ Kubernetes. By gradually updating containers while keeping the app available, u ensure uninterrupted service.
Read 18 tweets
Apr 16
🚨🚨 Interview Tip!

What happens at the backend when you launch a Pod in Kubernetes!

A Thread 👇 Image
🐳 Step 1: YAML Configuration

To kick things off, you create a YAML file defining your Pod's configuration. This includes details like container images, ports, volumes, etc. #Kubernetes #YAML
🔍 Step 2: API Request

Once you've got your YAML ready, you send an API request to the Kubernetes cluster. This request includes your Pod configuration. #K8s #API
Read 21 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(