- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How To Use Systemctl On CentOS 7.x or RHEL Linux 7
In this article we will learn how to use ‘systemctl’ command, ‘systemctl’ is a new command which is available in the new version of Linux distributions which is used to control the system and services, we will explore some possible ways to use the ‘systemctl’ command in Linux.
Checking Services Status
We can verify the status of the services using this command. Below is the command to check the service.
# systemctl status httpd httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2016-06-02 06:48:58 EDT; 27s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 10011 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─10011 /usr/sbin/httpd -DFOREGROUND ├─10012 /usr/sbin/httpd -DFOREGROUND ├─10013 /usr/sbin/httpd -DFOREGROUND ├─10014 /usr/sbin/httpd -DFOREGROUND ├─10015 /usr/sbin/httpd -DFOREGROUND └─10016 /usr/sbin/httpd -DFOREGROUND Jun 02 06:48:57 centos-linux-1.shared systemd[1]: Starting The Apache HTTP Server... Jun 02 06:48:58 centos-linux-1.shared systemd[1]: Started The Apache HTTP Server.
To Show the Services
# systemctl show httpd Type=notify Restart=no NotifyAccess=main RestartUSec=100ms TimeoutStartUSec=1min 30s TimeoutStopUSec=1min 30s WatchdogUSec=0 WatchdogTimestamp=Thu 2016-06-02 06:48:58 EDT WatchdogTimestampMonotonic=2588490928 StartLimitInterval=10000000StartLimitBurst=5 StartLimitAction=none …. . . . . AssertResult=yes ConditionTimestamp=Thu 2016-06-02 06:48:57 EDT ConditionTimestampMonotonic=2587709137 AssertTimestamp=Thu 2016-06-02 06:48:57 ED AssertTimestampMonotonic=2587709138 Transient=no This will display all the status information about http (web servers services) Verifying the Services active or enabled Here we will verify that the servers are active and they are enabled at system startup To verify the services active or not we needed to run the below command # systemctl is-active httpd.service active
To enable the service to run at the system start-up or after the machine is Rebooted
# systemctl enable httpd Created symlink from /etc/systemd/system/multi-use.rtarget.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
To Check whether the services are enabled or not, run the below command
# systemctl is-enabled httpd enabled
To start the services manually or restart the services manually, we can use the below commands
# systemctl start httpd # systemctl restart httpd
To list out the dependencies we can use the below command
# systemctl list-dependencies httpd httpd.service ├─-.mount ├─system.slice └─basic.target ├─microcode.service ├─rhel-autorelabel-mark.service ├─rhel-autorelabel. service ├─rhel-configure.service ├─rhel-dmesg.service ├─rhel-loadmodules.service ├─paths.target ├─slices.target │ ├─-.slice │ └─system.slice… … . ..
To list all the jobs currently running in the background
# systemctl list-jobs No jobs running.
To list all the installed unit files
# systemctl list-unit files
To List all the installed Unit Files for a particular Service
# systemctl list-unit-files | grep httpd httpd.service enabled
To List all the Installed Sockets and these Types
# systemctl list-sockets --show-types LISTEN TYPE UNIT ACTIVATES /dev/log Datagram systemd-journald.socket systemd-j /run/dmeventd-client FIFO dm-event.socket dm-event. /run/dmeventd-server FIFO dm-event.socket dm-event. /run/lvm/lvmetad.socket Stream lvm2-lvmetad.socket lvm2-lvme /run/lvm/lvmpolld.socket Stream lvm2-lvmpolld.socket lvm2-lvmp /run/systemd/initctl/fifo FIFO systemd-initctl.socket systemd-i /run/systemd/journal/socket Datagram systemd-journald.socket systemd-j /run/systemd/journal/stdout Stream systemd-journald.socket systemd-j /run/systemd/shutdownd Datagram systemd-shutdownd.socket systemd-s /run/udev/control SequentialPacket systemd-udevd-control.socket systemd-u /var/run/dbus/system_bus_socket Stream dbus.socket dbus.serv kobject-uevent 1 Netlink systemd-udevd-kernel.socket systemd-u 12 sockets listed. Pass --all to see loaded but inactive sockets, too.
To Setup/list the Default Target (mean Run Level)
# systemctl set-default multi-user.target Removed symlink /etc/systemd/system/default.target. Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target. # systemctl get-default multi-user.target
Masking & Unmasking the Services
In some situations, especially in big companies – one of the administrators had stoped the servers and other will start the services, to avoid this type of situations we can mask and unmask the services, if some services are stoped without unmasking we cannot start the services again
# systemctl mask httpd Created symlink from /etc/systemd/system/httpd.service to /dev/null.
To see the Status of the Services after Masking
# httpd.service Loaded: masked (/dev/null) Active: active (running) since Thu 2016-06-02 07:03:27 EDT; 10min ago Main PID: 10128 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─10128 /usr/sbin/httpd -DFOREGROUND ├─10129 /usr/sbin/httpd -DFOREGROUND ├─10130 /usr/sbin/httpd -DFOREGROUND ├─10131 /usr/sbin/httpd -DFOREGROUND ├─10132 /usr/sbin/httpd -DFOREGROUND └─10133 /usr/sbin/httpd -DFOREGROUND Jun 02 07:03:27 centos-linux-1.shared systemd[1]: Starting The Apache HTTP Server... Jun 02 07:03:27 centos-linux-1.shared systemd[1]: Started The Apache HTTP Server. Jun 02 07:13:47 centos-linux-1.shared systemd[1]: httpd.service: Got notification m.... Jun 02 07:13:57 centos-linux-1.shared systemd[1]: httpd.service: Got notification m.... Jun 02 07:14:07 centos-linux-1.shared systemd[1]: httpd.service: Got notification m.... Jun 02 07:14:17 centos-linux-1.shared systemd[1]: httpd.service: Got notification m.... Hint: Some lines were ellipsized, use -l to show in full.
If we try to Start the Masked Services it will display Errors
# systemctl start httpd Failed to start httpd.service: Unit httpd.service is masked.
To unmask the services to Start, we need to run the below command
# systemctl unmask httpd Removed symlink /etc/systemd/system/httpd.service.
After unmasking of the service, we can start the services again back
# systemctl start httpd # systemctl status httpd httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2016-06-02 07:03:27 EDT; 18min ago Docs: man:httpd(8) man:apachectl(8) Main PID: 10128 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─10128 /usr/sbin/httpd -DFOREGROUND ├─10129 /usr/sbin/httpd -DFOREGROUND ├─10130 /usr/sbin/httpd -DFOREGROUND ├─10131 /usr/sbin/httpd -DFOREGROUND ├─10132 /usr/sbin/httpd -DFOREGROUND └─10133 /usr/sbin/httpd -DFOREGROUND
We can create a snapshot of the services on the Linux Machine
A snapshot refers to a saved status of the system manager. The Snapshot is useful only to save an restore the units running or stopped.
To take a snapshot of the service we can use
# systemctl snapshot httpd ht.tpdsnapshot
To see the status of the service Snapshot
# systemctl status httpd.snapshot httpd.snapshot Loaded: loaded Active: inactive (dead) Jun 02 07:26:31 centos-linux-1.shared systemd[1]: Created snapshot httpd.snapshot.
To delete the Snapshot and Check the status of the service snapshot
# systemctl delete httpd.snapshot # systemctl status httpd.snapshot httpd.snapshot Loaded: not-found (Reason: No such file or directory) Active: inactive (dead) Jun 02 07:26:31 centos-linux-1.shared systemd[1]: Created snapshot httpd.snapshot. Jun 02 07:29:05 centos-linux-1.shared systemd[1]: Removing snapshot httpd.snapshot.
After this article we can now able to control the services in the new or the latest version of Linux, where the ‘systemctl’ is the replacement of service command in the older versions of Linux. Hope this will help in doing your jobs.
- Related Articles
- How to setup hostname in centos 7 x or rhel 7 x linux versions
- How to Secure The SSHD Using Fail2Ban on RHEL 7.x/CentOS 7.x
- How To Fix and Protect The Linux Server Against the Dirty COW Vulnerability on CentOS 5/6/7 or RHEL 5/6/7
- How to install gnome desktop on centos rhel 7 using yum command
- Migrating PHP 5.x to PHP 7 on CentOS 7
- How to install and configure own wordpress instance on linux centos 7
- How to install and use docker and containers on centos 7
- How to install docker on centos 7
- How to install the latest version of Git on CentOS 7.x/6.x?
- How To Configure mod_rewrite for Apache on CentOS 7
- How to Install and Configure Ansible on CentOS 7
- How To Install and Configure MongoDB on CentOS 7
- How To Install Go (Golang) 1.7 on CentOS 7
- How To Use Let’s Encrypt SSL Certificate To Secure Nginx for free on CentOS 7
- How to install graylog 1 3graylog2 on centos 7rhel 7
