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

Systemctl Sub-Commands

Systemctl Sub-Commands

Managing systemd with systemctl

Systemctl is a command-line tool used to monitor and control systemd and units. It has several sub-commands used to show the statuses of unit files and active units or control and monitor specific units.

Commands for controlling a specific unit

There are sub-commands to control a specific unit (or unit file). If you are not logged in as the superuser, add the sudo prefix to the command.

systemctl start [unit name]

When you want to start a unit named unit_a.service, use this command.

Command Line - INPUT
sudo systemctl start unit_a

systemctl stop [unit name]

When you want to stop a running unit, use this command.

Command Line - INPUT
sudo systemctl stop unit_a

systemctl restart [unit name]

When you want to restart a running unit, use this command.

Command Line - INPUT
sudo systemctl restart unit_a

systemctl reload [unit name]

When you update a unit file and reload it, use this command.

Command Line - INPUT
sudo systemctl reload unit_a

systemctl enable [unit name]

When you want to start a unit (unit_a) automatically at boot, you need to enable it with this sub-command. When you run this command, a symbolic link of unit_a's unit file is created under a related directory of the unit that has a dependency with unit_a (typically, under a directory ending with .wants). This symbolic link is used to start unit_a.

Command Line - INPUT
sudo systemctl enable unit_a
Command Line - RESPONSE
Created symlink /etc/systemd/system/multi-user.target.wants/unit_a.service → /etc/systemd/system/unit_a.service.

With --now option, you can also start the unit when you run the command.

Command Line - INPUT
sudo systemctl enable --now unit_a

systemctl disable [unit name]

When you don't want to start the unit (unit_a) automatically at boot anymore, you can disable it with this sub-command. When you run this command, the symbolic link under the directory (ending with .wants) is removed.

Command Line - INPUT
sudo systemctl disable unit_a
Command Line - RESPONSE
Removed /etc/systemd/system/multi-user.target.wants/unit_a.service.

With --now option, you can also stop the unit when you run the command.

Command Line - INPUT
sudo systemctl disable --now unit_a

systemctl status [unit name]

When you want to check the status of a specific unit, such as ‘active(running)’ or ‘stopped’ and ‘enabled’ or ‘disabled’, you can use this sub-command. For this command, the sudo privilege is not necessary.

Command Line - INPUT
systemctl status unit_a
Command Line - RESPONSE
● unit_a.service - unit description
     Loaded: loaded (/etc/systemd/system/unit_a.service; enabled; vendor preset: >
     Active: active (running) since Sat 2023-01-14 02:45:18 UTC; 11s ago
   Main PID: 103219 (unit_a.)
      :

The status information is shown with a pager. To exit the pager mode, press the q key.

General control commands (not for a specific unit)

There are sub-commands that are not used for a specific unit, such as systemctl list-unit-files and systemctl list-unit, which are explained on the systemd topic page. There are also other sub-commands not used for a specific unit.

systemctl daemon-reload

When you edit a unit file already recognized by systemd, you need to reload it for systemd to recognize the changes. For example, if you edit service_a's unit file and check its status, you'll see a warning like the one below.

Command Line - INPUT
systemctl status service_a
Command Line - RESPONSE
Warning: The unit file, source configuration file or drop-ins of service_a.service changed on disk. Run 'systemctl daemon-reload' to reload units.

To make systemd recognize the change, run the command like shown below. Use sudo to avoid the authentication error if you are not logged in as the superuser.

Command Line - INPUT
sudo systemctl daemon-reload

systemctl list-dependencies

systemd manages multiple units in parallel. When the system starts, default.target is activated and dependent units are also activated. There is a tree of dependencies of the unit. By running this sub-command, you can see the dependencies in the tree structure.

Command Line - INPUT
systemctl list-dependencies
Command Line - RESPONSE
default.target
● ├─accounts-daemon.service
:
● └─multi-user.target
●   ├─apache2.service
●   ├─apport.service
●   ├─atd.service
:
●   ├─wpa_supplicant.service
●   ├─basic.target
●   │ ├─-.mount
:
●   │ ├─sockets.target
●   │ │ ├─acpid.socket
:
●   │ ├─sysinit.target
●   │ │ ├─apparmor.service
●   │ │ ├─blk-availability.service
:
●   │ └─timers.target
●   │   ├─apt-daily-upgrade.timer
:

systemctl get-default

The default target unit is used as a starting point for system boot. The default target is represented by the /etc/systemd/system/default.target file. This is a symbolic link to the original .target file in another location. To check the original target file, you can use this sub-command.

Command Line - INPUT
systemctl get-default
Command Line - RESPONSE
graphical.target

You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Docker Images and Registries (Docker Hub)

Docker Images and Registries (Docker Hub)

Viewing Text Content with less Pager

less (Display Content with Pager)

Chapter 4. Docker Networking and Storage

Chapter 4. Docker Networking and Storage

Setting Up a Virtual Environment for Django

Set Up Virtual Environment

Creating One-To-Many Relationships with ForeignKey

Django Models – ForeignKey (OneToMany Relationship)

Docker Images and Registries (Docker Hub)

Docker Images and Registries (Docker Hub)

Viewing Text Content with less Pager

less (Display Content with Pager)

Chapter 4. Docker Networking and Storage

Chapter 4. Docker Networking and Storage

Setting Up a Virtual Environment for Django

Set Up Virtual Environment

Creating One-To-Many Relationships with ForeignKey

Django Models – ForeignKey (OneToMany Relationship)

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