Systemctl command is a utility in Linux to manage & control systemd.
systemd is like a service manager in Linux.
Let's list some of the frequently used systeamctl commands.
How to get list services on your system.
[satish@host]$ sudo service --status-all
### How to list all active units
[satish@host]$ sudo systemctl list-units --all
######
yum install cronie -y && systemctl start crond.service && systemctl status crond.serviceHow to Restart systemd.
[satish@host]$ sudo systemctl daemon-reload
### if you don't want to use systemctl daemon-reload command after making some change in service use the following command to edit the service.
[pankaj@host]$ sudo systemctl edit myservices.service --fullEnable mariadb service on reboot.
[satish@host]$ sudo systemctl enable mariadbDisable mariadb service on reboot.
[satish@host]$ sudo systemctl disable mariadbDisable & Stop mariadb service.
[satish@host]$ sudo systemctl disable mariadb --nowMask mariadb service.
Before masking the service it is always recommend to stop and disable service
[satish@host]$ sudo systemctl mask mariadbUnMask mariadb service.
[satish@host]$ sudo systemctl unmask mariadbView all the active systemd jobs.
[satish@host]$ sudo systemctl list-jobsView the list of services that failed to run.
[satish@host]$ sudo systemctl --failedRemove failed status service from systemctl list:
[satihs@host]$ sudo systemctl reset-failed
[satish@host]$ sudo rm -rf /etc/systemd/system/service_name
[satish@host]$ sudo rm -rf /etc/systemd/system/service_symlinkView Log Messages
journalctl command in Linux:
To see all the log messages at once:
[satish@host]$ sudo journalctl To see the log message of particular service
[satish@host]$ sudo journalctl -u service_nameTo see the log message as they come in live mode basically:
[satish@host]$ sudo journalctl -fTo highlight the error in log message:
[satish@host]$ sudo journalctl -p errorTo make the journalctl log message persistence:
[satish@host]$ sudo mkdir -p /var/log/journalsometime tail command can be useful in the case if journalctl command is not available:
[satish@host]$ tail -f /var/log/messages
[satish@host]$ tail -f /var/log/secure
-f --> followSystemctl command to start multiple services:
[satish@host]$ sudo systemctl start(rpcbind,nfs-server,rpc-statd,nfs-idmapd)Iptables:
$ sudo su -
$ yum install iptables-services -y
$ systemctl enable iptables
$ iptables -A INPUT -p tcp --destination-port 5004 -s 172.16.238.14 -j ACCEPT
$ iptables -A INPUT -p tcp --destination-port 5004 -j DROP
$ service iptables save
$ systemctl restart iptablesI will keep adding more command to this post!!
Thanks for reading.



0 Comments