Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
time command in Linux with examples
Next article icon

How to Manage System Services in Linux | systemctl Command

Last Updated : 04 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Linux operating systems are known for their robustness and versatility, and managing system services is a crucial aspect of maintaining a well-functioning system. With the advent of systemd, a system and service manager for Linux operating systems, the systemctl command has become an essential tool for managing services. In this article, we will explore the intricacies of systemctl and how it can be used to control and monitor system services.

Table of Content

  • What is Systemd?
  • What is the Linux Systemctl Command?
  • Syntax of `systemctl` command in Unix
  • How to Manage System Services in Linux
  • Options available in `systemctl` command in Unix

What is Systemd?

Systemd is like the traffic manager for your Linux system. It's a modern tool that organizes and supervises how different parts of your system start and run. Imagine it as a smarter, faster way to handle tasks compared to older methods. Instead of doing things one after the other, systemd can get multiple tasks going at the same time, making your computer start up quicker and respond faster. It uses something called "units" to keep everything in order – like services, sockets, and devices – helping your system run smoothly.

What is the Linux Systemctl Command?

Now, imagine you have a remote control for your Linux system – that's what `systemctl` is. It's like your boss for telling the system what to do. With this tool, you can start, stop, or restart services (think of them like programs running in the background). Want something to start automatically when your computer turns on? `systemctl` helps with that too. It's also good for checking how things are going – like looking at logs or figuring out what other things a service needs to work properly. So, if you're in charge of a Linux system, `systemctl` is your go-to tool for keeping things organized and running well.

Syntax of `systemctl` command in Unix

systemctl [command] [service]

[command] = The action we want to perform (start, stop, enable, disable, etc.)

[service] = The name of the service we want to perform the action on.

How to Manage System Services in Linux

1) Starting and Stopping Services

Starting Services

Syntax:

systemctl start [service]

Example:

If we want to start our SSH service.

systemctl start sshd

Stopping Services

Syntax:

systemctl stop [service]

Example:

If we want to stop our SSH service.

systemctl stop sshd

2) Enabling and Disabling Service

Enabling Services

Syntax:

systemctl enable [service]

Example:

If we want to enable our firewall service.

systemctl enable firewalld

Disabling Services

Syntax:

systemctl disable [service]

Example:

If we want to disable our firewall service.

systemctl disable firewalld

3) Viewing the Staus of Services

Viewing Status of Services

Syntax:

systemctl status [service]

Example:

If we want to see the status of our firewall service.

systemctl status firewalld

4) Restarting and Reloading Services

Restarting Services

Syntax:

systemctl restart [service]

Example:

If we want to restart our SSH service.

systemctl restart sshd

Reloading Services

Syntax:

systemctl reload [service]

Example:

If we want to reload our Apache service.

systemctl reload httpd

5) Masking and Unmasking Services

Masking Services

Syntax:

systemctl mask [service]

Example:

If we want to mask our MySQL service.

systemctl mask mysqld

Masking a service prevents it from being started or enabled, even if it is required by other services.

Unmasking Services

Syntax:

systemctl unmask [service]

Example:

If we want to unmask our MySQL service.

systemctl unmask mysqld

Unmasking a service allows it to be started or enabled again.

6) Changing the Default Target

Syntax:

systemctl set-default [target]

Example:

If we want to change the default target to graphical.target (which will start the graphical user interface).

systemctl set-default graphical.target

The default target determines which system services are started when the system boots up.

7) Listing Unit Files

Syntax:

systemctl list-unit-files

This command lists all the unit files available on the system, including both enabled and disabled unit files.
 

8) Masking and Unmasking Unit Files

Masking Unit Files

Syntax:

systemctl mask [unit-file]

Example:

If we want to mask the SSH unit file.

systemctl mask sshd.service

Masking a unit file prevents it from being started or enabled, even if it is required by other services.

Unmasking Unit Files

Syntax:

systemctl unmask [unit-file]

Example:

If we want to unmask the SSH unit file.

systemctl unmask sshd.service

Unmasking a unit file allows it to be started or enabled again.

Options available in `systemctl` command in Unix

Options                                                     DescriptionSyntax
--versionThis option displays the version number of the systemctl command.
systemctl --version
--helpThis option displays the help manual for systemctl, including a list of available options and commands
systemctl --help
--typeThe argument in this case should be comma-separated list of unit types such as service and socket.
systemctl --type=service
--allThis option lists all available units, including those that are inactive.
systemctl --all
--failedThis option lists all units that have failed.
 
systemctl --failed
--usertalk to service manager of calling user, instead of system.
systemctl --user
--forceThis option forces the service to start or stop, even if it has dependencies that are not yet started or stopped.
systemctl stop --force httpd.service

--no-block

This option starts or stops the service without blocking the shell, allowing the user to continue to use the shell while the service is starting or stopping.
systemctl start --no-block httpd.service
--state

This option is used to filter the output based on the specified unit state. You can specify one or more-unit states separated by commas, such as active, inactive, failed, and activating.

 For example: to list all the failed units.

systemctl list-units --state=failed
-r, --recursive

This option is used to show units of local containers as well.

 For example: to list all units including those in local containers.

systemctl list-units --recursive
--show-types

This option is used to show the types of sockets along with showing sockets. 

For example: to show the types of all sockets.

systemctl list-sockets --show-types
--job-mode=

This option controls how to deal with already queued jobs in case of queuing a new job. There are three available modes:

replace: replace already queued jobs with the new one.
fail: cancel the new job and return failure if there are already queued jobs.
isolate: queue the new job and isolate it from the other jobs.

For example: to use the replace mode.

systemctl isolate graphical.target --job-mode=replace
-i, --ignore-inhibitors

This option is used to ignore inhibitor locks when requesting a system shutdown or sleep state. 

For example: to ignore inhibitor locks when requesting a system shutdown.

systemctl poweroff --ignore-inhibitors
-q, --quiet

This option is used to suppress the printing of results of various commands and the hints about the truncated lines. 

For example: to reload the systemctl daemon without showing any output.

systemctl daemon-reload --quiet
--no-wall

This option is used to not send a wall message before power-off, halt, or reboot. 

For example: to halt the system without sending a wall message.

systemctl halt --no-wall

Conclusion

In this article we will understand the use of `systemctl` command in Linux and How to manage system services in linux. By mastering systemctl, you gain full control over your system's services, ensuring optimal performance and stability. Whether you're a seasoned Linux admin or just starting, this powerful command is a valuable tool in your arsenal. So, dive in, explore its capabilities, and take command of your Linux system!

Remember, this is just a starting point. The world of systemctl is vast and offers many more possibilities. Explore the man page (man systemctl) and online resources for deeper dives and advanced usage. Feel free to ask any questions you may have, and happy systemd adventures!
 


Next Article
time command in Linux with examples

M

msdeep14
Improve
Article Tags :
  • Linux-Unix
  • linux-command
  • Linux-misc-commands

Similar Reads

  • source Command in Linux with Examples
    If you're new to the world of Linux, you might have heard about commands that do various tasks, but some like the 'source' command might seem a bit confusing at first. Don't worry; let's break it down step by step. What is the Source Command?The source command in Linux is like a magic wand that lets
    7 min read
  • How to sort lines in text files in Linux | sort Command
    SORT command is used to sort a file, arranging the records in a particular order. By default, the sort command sorts file assuming the contents are ASCII. Using options in the sort command can also be used to sort numerically.  SORT command sorts the contents of a text file, line by line.sort is a s
    7 min read
  • Split Command in Linux with Examples
    Split command in Linux is used to split large files into smaller files . It splits the files into 1000 lines per file(by default) and even allows users to change the number of lines as per requirement. The names of the files are PREFIXaa, PREFIXab, PREFIXac, and so on. By default the PREFIX of files
    6 min read
  • How to use SSH to connect to a remote server in Linux | ssh Command
    Secure Shell, commonly known as SSH, is like a super-secure way to talk to faraway computers, called servers. It's like a secret tunnel on the internet that keeps your conversations safe and private. Imagine you're sending a letter, and instead of sending it openly, you put it in a magic envelope th
    8 min read
  • Strace command in Linux with Examples
    'strace' is a powerful tool for monitoring and diagnosing processes in Linux. It is primarily used for debugging programs, troubleshooting issues, intercepting and recording system calls, and tracing running processes. It provides valuable insights into how a program interacts with the system, espec
    4 min read
  • stty command in Linux with Examples
    stty command in Linux is used to change and print terminal line settings. This command shows or changes terminal characteristics. Syntaxstty [-F DEVICE | --file=DEVICE] [SETTING]...stty [-F DEVICE | --file=DEVICE] [-a|--all]stty [-F DEVICE | --file=DEVICE] [-g|--save]where, -F DEVICE or --file=DEVIC
    2 min read
  • sudo Command in Linux with Examples
    sudo (Super User DO) command in Linux is generally used as a prefix for some commands that only superusers are allowed to run. If you prefix any command with "sudo", it will run that command with elevated privileges or in other words allow a user with proper permissions to execute a command as anoth
    8 min read
  • sum command in Linux with Examples
    The sum command in Linux is used to calculate the checksum and block count of files. This command helps in verifying file integrity by comparing the calculated checksum with an expected value. The sum command can operate on one or more files, and when no file is specified, it reads from standard inp
    3 min read
  • sync command in Linux with Examples
    sync command in Linux is used to synchronize cached writes to persistent storage. If one or more files are specified, sync only them, or their containing file systems. Syntax: sync [OPTION] [FILE]... Note: Nothing is being shown in the screenshots just because sync command makes the cache in the bac
    1 min read
  • How to Manage System Services in Linux | systemctl Command
    Linux operating systems are known for their robustness and versatility, and managing system services is a crucial aspect of maintaining a well-functioning system. With the advent of systemd, a system and service manager for Linux operating systems, the systemctl command has become an essential tool
    8 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences