Jump to content

12 Systemctl commands list for System Admins


Sandeep B.

Recommended Posts

systemctl is a command-line tool used to manage and control the systemd system and service manager in various Linux distributions. It enables administrators to manage the OS and control the status of services. Further, systemctl is useful for troubleshooting and basic performance tuning.

Here are some Commands which need admin/root privilege

service_name is the name of the service you want to perform the action for.

Start a service:

To start a service, use the following command:

systemctl start service_name


Stop a service:

To stop a service, use the following command:

systemctl stop service_name


Restart a service:

To restart a service, use the following command:

systemctl restart service_name


Enable a service at boot:

To enable a service to start automatically at boot, use the following command:

systemctl enable service_name


Disable a service at boot:

To disable a service from starting automatically at boot, use the following command:

systemctl disable service_name


Check the status of a service:

To check the status of a service, use the following command:

systemctl status service_name


List all running services:

To list all running services, use the following command:

systemctl list-units --type=service --state=running


example :

[root@cwp ~]# systemctl list-units --type=service --state=running
UNIT                     LOAD   ACTIVE SUB     DESCRIPTION
amavisd.service          loaded active running Amavis mail content checker
atd.service              loaded active running Job spooling tools
cbpolicyd.service        loaded active running CWP Policyd for Postfix
clamd.service            loaded active running clamd scanner () daemon
console-getty.service    loaded active running Console Getty
crond.service            loaded active running Command Scheduler
cwp-phpfpm.service       loaded active running The PHP FastCGI Process Manager
cwpsrv-phpfpm.service    loaded active running The PHP FastCGI Process Manager
cwpsrv.service           loaded active running CentOS Web Panel service (daemon)
dbus.service             loaded active running D-Bus System Message Bus
dovecot.service          loaded active running Dovecot IMAP/POP3 email server
getty@tty2.service       loaded active running Getty on tty2
httpd.service            loaded active running Web server Apache
lfd.service              loaded active running ConfigServer Firewall & Security - lfd
mariadb.service          loaded active running MariaDB 10.11.2 database server
named.service            loaded active running Berkeley Internet Name Domain (DNS)
nginx.service            loaded active running nginx - high performance web server
opendkim.service         loaded active running DomainKeys Identified Mail (DKIM) Milter
php-fpm81.service        loaded active running The PHP FastCGI Process Manager
php-fpm82.service        loaded active running The PHP FastCGI Process Manager
postfix.service          loaded active running Postfix Mail Transport Agent
pure-ftpd.service        loaded active running Pure-FTPd FTP server
rsyslog.service          loaded active running System Logging Service
saslauthd.service        loaded active running SASL authentication daemon.
spamassassin.service     loaded active running Spamassassin daemon
sshd.service             loaded active running OpenSSH server daemon
systemd-journald.service loaded active running Journal Service
systemd-logind.service   loaded active running Login Service
systemd-udevd.service    loaded active running udev Kernel Device Manager
varnish.service          loaded active running Varnish Cache, a high-performance HTTP accelerator
xinetd.service           loaded active running Xinetd A Powerful Replacement For Inetd


Find a service name use grep :

systemctl list-units --type=service --state=running | grep keyword


example :

[root@server ~]# systemctl list-units --type=service --state=running | grep php
php-fpm81.service        loaded active running The PHP FastCGI Process Manager
php-fpm82.service        loaded active running The PHP FastCGI Process Manager


List all failed services:

To list all running services, use the following command:

systemctl list-units --type=service --state=failed


example :

[root@cwp ~]# systemctl list-units --type=service --state=failed
  UNIT                           LOAD   ACTIVE SUB    DESCRIPTION
* systemd-sysctl.service         loaded failed failed Apply Kernel Variables
* systemd-vconsole-setup.service loaded failed failed Setup Virtual Console
* vzquota.service                loaded failed failed LSB: Start vzquota at the end of boot


To Stop/masking a service strictly so no one or other programs can start it :

systemctl mask service_name


To unmasking a service and undo :

systemctl unmask service_name


Reload systemd configuration:

To reload the systemd configuration after changes is done or to just reload it, use the following command:

systemctl daemon-reload


View service logs:

To view the logs of a service, use the following command:

journalctl -u service_name


example :

[root@cwp ~]# journalctl -u httpd
-- Logs begin at Wed 2023-05-05 18:48:58 EDT, end at Sat 2023-05-06 15:20:01 EDT. --
Aug 04 04:25:14 cwp.onefinehost.com systemd[1]: Stopping Web server Apache...
Aug 04 04:25:14 cwp.onefinehost.com systemd[1]: Stopped Web server Apache.
Aug 04 04:25:14 cwp.onefinehost.com systemd[1]: Starting Web server Apache...
Aug 04 04:25:14 cwp.onefinehost.com systemd[1]: Started Web server Apache.
Aug 04 04:25:14 cwp.onefinehost.com systemd[1]: Reloading Web server Apache.
Aug 04 04:25:14 cwp.onefinehost.com systemd[1]: Reloaded Web server Apache.
Aug 04 04:25:15 cwp.onefinehost.com systemd[1]: Reloading Web server Apache.
Aug 04 04:25:15 cwp.onefinehost.com systemd[1]: Reloaded Web server Apache.
Aug 04 04:25:17 cwp.onefinehost.com systemd[1]: Stopping Web server Apache...

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...