Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Linux IntroductionChapter 8. Process Management

Systemd

Systemd

Introduction to systemd

What is systemd?

systemd is a daemon (or a service) that manages other daemons for Linux OS. When Linux OS starts or reboots, systemd also starts and continues running to centrally control other daemons until the OS shuts down. You can see how systemd is positioned in Linux OS by running the pstree command. The pstree command shows current processes running on the OS in a hierarchical structure.

Command Line - INPUT
pstree
Command Line - RESPONSE
systemd─┬─accounts-daemon───2*[{accounts-daemon}]
        ├─acpid
        ├─2*[agetty]
        ├─amazon-ssm-agen─┬─ssm-agent-worke───8*[{ssm-agent-worke}]
        │                 └─7*[{amazon-ssm-agen}]
        ├─atd
        ├─cron
        ├─dbus-daemon
        ├─5*[grep]
        ├─multipathd───6*[{multipathd}]
        ├─networkd-dispat
        ├─polkitd───2*[{polkitd}]
        ├─rsyslogd───3*[{rsyslogd}]
        ├─snapd───8*[{snapd}]
        ├─sshd─┬─3*[sshd───sshd───bash]
        │      ├─4*[sshd───sshd───sftp-server]
        │      └─sshd───sshd───bash───pstree
        ├─systemd───(sd-pam)
        ├─systemd-journal
        ├─systemd-logind
        ├─systemd-network
        ├─systemd-resolve
        ├─systemd-timesyn───{systemd-timesyn}
        ├─systemd-udevd
        ├─unattended-upgr───{unattended-upgr}
        └─uuidd hierarchically.

Units

systemd manages and controls other processes through units. There are several types of units. Below are some examples.

  • .service: starts, stops, restarts, or reloads a service daemon
  • .socket: activates a service when the service receives incoming traffic on a listening socket
  • .path: activates and deactivates a service if a specified file or directory is accessed
  • .target: is a group of units
  • .timer: activates and deactivates a service with a timer

Unit files

When systemd starts, it triggers multiple units by loading unit files. Unit files are configuration files that contain directives for units. For example, when and how the unit will start, dependency on other units, which command will be triggered, etc.

Locations of unit files

There are two major file locations for unit files. The unit files saved under these directories will be loaded by systemd, and systemd will follow the directives written in the unit files.

  • /usr/lib/systemd/system: default location for unit files. Original copies of unit files should be stored in this directory.
  • /etc/systemd/system: custom unit file location. If you have modified unit files, store them in this directory.

When systemd loads unit files, the unit files in the /etc/systemd/system directory are prioritized. For example, if there are files with the same names in both directories, systemd prioritizes the unit file stored in the /etc/systemd/system directory.

systemctl

Systemctl is a command-line tool used to monitor and control systemd. It has sub-commands used to start, stop, restart, reload, enable, and disable units. systemctl is also used to show the statuses of units and unit files available in the system.

List unit files with ‘systemctl list-unit-files’

To view the list of unit files available in the system, run the following command. You can see the files under /usr/lib/systemd/system or /etc/systemd/system but running this command makes viewing the list easier.

List unit files with the systemctl list-unit-files command

If you want to show services only, add the -t service option shown below. The -t option can select only a specified type of unit.

Command Line - INPUT
systemctl list-unit-files -t service

You can see the list of service unit files like the one below.

Command Line - RESPONSE
UNIT FILE                            STATE           VENDOR PRESET
accounts-daemon.service              enabled         enabled      
acpid.service                        disabled        enabled      
apparmor.service                     enabled         enabled      
apport-autoreport.service            static          enabled      
apport-forward@.service              static          enabled      
apport.service                       generated       enabled      
apt-daily-upgrade.service            static          enabled      
apt-daily.service                    static          enabled
    :                                   :               :

To exit the view mode, press the q key.

List units with ‘systemctl list-units’

To view the list of active units in the system, run the following command.

List units with the systemctl list-units command

If you want to show services only, add the -t service option shown below. The -t option can select only a specified type of unit.

Command Line - INPUT
systemctl list-units -t service

You can see the list of active service units like the one below.

Command Line - RESPONSE
 UNIT                         LOAD   ACTIVE SUB     DESCRIPTION       >
  accounts-daemon.service     loaded active running Accounts Service  >
  acpid.service               loaded active running ACPI event daemon >
  apparmor.service            loaded active exited  Load AppArmor prof>
  apport.service              loaded active exited  LSB: automatic cra>
  atd.service                 loaded active running Deferred execution>
  blk-availability.service    loaded active exited  Availability of bl>
          :                      :      :      :         :

To exit the view mode, press the q key.


You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Understanding Version Control

What Is Version Control?

Configuring STATIC_URL and STATICFILES_DIRS in Django

STATIC_URL and STATICFILES_DIRS

Adding Extra Context in Django Views

Customize Views (3) – Add Extra Context

Exploring UFW (Uncomplicated Firewall)

UFW (Uncomplicated Firewall)

Managing Standard Input and Output with Redirection

Standard Input Output and Redirection

Understanding Version Control

What Is Version Control?

Configuring STATIC_URL and STATICFILES_DIRS in Django

STATIC_URL and STATICFILES_DIRS

Adding Extra Context in Django Views

Customize Views (3) – Add Extra Context

Exploring UFW (Uncomplicated Firewall)

UFW (Uncomplicated Firewall)

Managing Standard Input and Output with Redirection

Standard Input Output and Redirection

Tags:

Service

Daemon Process

Unit File

Unit

systemctl

systemd

Linux Introduction
Course Content

Chapter 1. Linux Basics

What Is OS?

CUI and GUI

Linux Distributions

Package Manager

Kernel and Shell

Current Working Directory

Linux Directory Structure

Absolute Path and Relative Path (Linux OS)

Linux Command Syntax

Special Characters and Escape Character

Chapter 2. Linux Key Commands

Setting Up Linux Environment on AWS

pwd (Print Working Directory)

cd (Change Directory)

ls (List Contents of Directory)

mkdir (Make Directory)

rmdir (Remove Directory)

touch (Create File)

rm (Remove File)

mv (Move File and Directory)

cp (Copy File and Directory)

cat (Display File Content)

sort (Sort File Contents)

grep (Global Regular Expression Print)

Regular Expression

find (Find File and Directory)

Wildcard

ln (Create Link to File and Directory)

Chapter 3. Vim Editor

What Is Vim and How to Launch It?

Normal, Insert and Visual Mode

Normal Mode (1) – Move Cursor

Normal Mode (2) – Delete

Normal Mode (3) – Copy and Paste

Normal Mode (4) – Undo and Redo

Normal Mode (5) – Search Phrase

Normal Mode (6) – Replace Phrase

Normal Mode (7) – Save and Exit

Insert Mode

Visual Mode

Chapter 4. User, Group and Permission

What Are User, Group And Permission in Linux?

Permission (Access Mode) by Owner Status

Superuser (Root User) vs. Normal User

sudo (Run Command with Superuser Privileges)

su (Switch User)

useradd (Add User)

passwd (Set Password)

userdel (Delete User)

Group – Primary Group and Secondary Group

groupadd (Add Group)

usermod (Modify User Account Information)

gpasswd (Add and Delete Users to Group)

groupdel (Delete Group)

chown (Change Owner of File and Directory)

chgrp (Change Group of File and Directory)

chmod (Change Access Mode)

chmod Command with Numbers

w and who (Check Current User Login Status)

id and groups (Check User ID and Group)

getent (Display User and Group Data)

Chapter 5. Redirection, Pipe and Shell Script

Standard Input Output and Redirection

Pipe (Combine Commands)

less (Display Content with Pager)

tr (Replace Characters)

cut (Extract Data Sections)

uniq (Extract Unique Data Lines)

Shell Script

echo (Echo input)

read (Read and Store Input)

Shell Variable and Environmental Variable

source (Execute Shell Script and Refresh Environmental Variables)

Chapter 6. Linux Commands for Command Management

history (Check Command History)

alias (Create Command Shortcuts)

man (Display Manual)

type, which and whereis (Display Command Information)

Package Manager Command

tree (Display Directory Tree)

Chapter 7. SSH Remote Connection

SSH (Secure Shell)

Locate .ssh Directory

SSH Remote Login (1) – Use Key Pair Generated by Server

SSH Remote Login (2) – Use Key Pair Generated by Client

SSH Config File

SSH Remote Login with Visual Studio Code

SCP (Secure Copy Protocol)

SCP with SSH Config File

SFTP (Secure File Transfer Protocol)

Other File Transfer Commands

Chapter 8. Linux Process Management

Process and Job

Foreground and Background Jobs

jobs and ps (Display Jobs and Processes)

Signals

Create, Stop and Terminate Jobs

Daemon Processes

What Is Service on Linux?

Systemd

Unit File

Systemctl Sub-Commands

Create Custom Unit and Start at Boot

Firewall

UFW (Uncomplicated Firewall)

Web Server

Launch Apache Web Server

Chapter 1. Linux Basics

What Is OS?

CUI and GUI

Linux Distributions

Package Manager

Kernel and Shell

Current Working Directory

Linux Directory Structure

Absolute Path and Relative Path (Linux OS)

Linux Command Syntax

Special Characters and Escape Character

Chapter 2. Linux Key Commands

Setting Up Linux Environment on AWS

pwd (Print Working Directory)

cd (Change Directory)

ls (List Contents of Directory)

mkdir (Make Directory)

rmdir (Remove Directory)

touch (Create File)

rm (Remove File)

mv (Move File and Directory)

cp (Copy File and Directory)

cat (Display File Content)

sort (Sort File Contents)

grep (Global Regular Expression Print)

Regular Expression

find (Find File and Directory)

Wildcard

ln (Create Link to File and Directory)

Chapter 3. Vim Editor

What Is Vim and How to Launch It?

Normal, Insert and Visual Mode

Normal Mode (1) – Move Cursor

Normal Mode (2) – Delete

Normal Mode (3) – Copy and Paste

Normal Mode (4) – Undo and Redo

Normal Mode (5) – Search Phrase

Normal Mode (6) – Replace Phrase

Normal Mode (7) – Save and Exit

Insert Mode

Visual Mode

Chapter 4. User, Group and Permission

What Are User, Group And Permission in Linux?

Permission (Access Mode) by Owner Status

Superuser (Root User) vs. Normal User

sudo (Run Command with Superuser Privileges)

su (Switch User)

useradd (Add User)

passwd (Set Password)

userdel (Delete User)

Group – Primary Group and Secondary Group

groupadd (Add Group)

usermod (Modify User Account Information)

gpasswd (Add and Delete Users to Group)

groupdel (Delete Group)

chown (Change Owner of File and Directory)

chgrp (Change Group of File and Directory)

chmod (Change Access Mode)

chmod Command with Numbers

w and who (Check Current User Login Status)

id and groups (Check User ID and Group)

getent (Display User and Group Data)

Chapter 5. Redirection, Pipe and Shell Script

Standard Input Output and Redirection

Pipe (Combine Commands)

less (Display Content with Pager)

tr (Replace Characters)

cut (Extract Data Sections)

uniq (Extract Unique Data Lines)

Shell Script

echo (Echo input)

read (Read and Store Input)

Shell Variable and Environmental Variable

source (Execute Shell Script and Refresh Environmental Variables)

Chapter 6. Linux Commands for Command Management

history (Check Command History)

alias (Create Command Shortcuts)

man (Display Manual)

type, which and whereis (Display Command Information)

Package Manager Command

tree (Display Directory Tree)

Chapter 7. SSH Remote Connection

SSH (Secure Shell)

Locate .ssh Directory

SSH Remote Login (1) – Use Key Pair Generated by Server

SSH Remote Login (2) – Use Key Pair Generated by Client

SSH Config File

SSH Remote Login with Visual Studio Code

SCP (Secure Copy Protocol)

SCP with SSH Config File

SFTP (Secure File Transfer Protocol)

Other File Transfer Commands

Chapter 8. Linux Process Management

Process and Job

Foreground and Background Jobs

jobs and ps (Display Jobs and Processes)

Signals

Create, Stop and Terminate Jobs

Daemon Processes

What Is Service on Linux?

Systemd

Unit File

Systemctl Sub-Commands

Create Custom Unit and Start at Boot

Firewall

UFW (Uncomplicated Firewall)

Web Server

Launch Apache Web Server