10 handy systemd commands: A reference (2024)

Posted: May 19, 2020 | | by Ken Hess (Sudoer alumni)

Image

10 handy systemd commands: A reference (1)

Poor systemd has had its share of detractors, but it seems to be here to stay for Linux admins so we might as well get used to it. This handy systemd command reference will help you keep your sanity when trying to perform normal administrative tasks. So, until we get something that's more usable, palatable, and desirable than systemd, please enjoy this list of ten handy commands for your convenience. These commands are in no particular order of importance or relevance.

List unit files

From the systemd man page: A unit file is a plain text ini-style file that encodes information about a service, a socket, a device, a mount point, an automount point, a swap file or partition, a start-up target, a watched file system path, a timer controlled and supervised by systemd, a resource management slice, or a group of externally created processes.

$ systemctl list-unit-filesUNIT FILE STATE proc-sys-fs-binfmt_misc.automount static dev-hugepages.mount static dev-mqueue.mount staticproc-sys-fs-binfmt_misc.mount static sys-fs-fuse-connections.mount static sys-kernel-config.mount static sys-kernel-debug.mount static tmp.mount disabledbrandbot.path disabledsystemd-ask-password-console.path static systemd-ask-password-plymouth.path static systemd-ask-password-wall.path static session-1.scope static arp-ethers.service disabledauditd.service enabledautovt@.service enabled<many more entries>

Of course, you can always pipe to grep to see just the enabled services.

$ systemctl list-unit-files |grep enabledauditd.service enabled autovt@.service enabled crond.service enabled dbus-org.fedoraproject.FirewallD1.service enabled dbus-org.freedesktop.nm-dispatcher.service enabled firewalld.service enabled getty@.service enabled irqbalance.service enabled kdump.service enabled lvm2-monitor.service enabled <many more entries>

These unit files, located under /lib/systemd/system, are roughly equivalent to the legacy init scripts that were located under /etc/rc.d/init.d. In fact, if you or your software installation create init scripts, a corresponding systemd unit file is mapped for you. A further explanation is given by /etc/rc.d/init.d/README:

You are looking for the traditional init scripts in /etc/rc.d/init.d,and they are gone?Here's an explanation on what's going on:You are running a systemd-based OS where traditional init scripts havebeen replaced by native systemd services files. Service files providevery similar functionality to init scripts. To make use of servicefiles simply invoke "systemctl", which will output a list of allcurrently running services (and other units). Use "systemctllist-unit-files" to get a listing of all known unit files, includingstopped, disabled and masked ones. Use "systemctl startfoobar.service" and "systemctl stop foobar.service" to start or stop aservice, respectively. For further details, please refer tosystemctl(1).Note that traditional init scripts continue to function on a systemdsystem. An init script /etc/rc.d/init.d/foobar is implicitly mappedinto a service unit foobar.service during system initialization.Thank you!Further reading: man:systemctl(1) man:systemd(1) http://0pointer.de/blog/projects/systemd-for-admins-3.html http://www.freedesktop.org/wiki/Software/systemd/Incompatibilities

As you can see, init.d has been removed in favor of systemd. It's here to stay until someone comes up with something better. (I'm hoping that someone is rapidly working on a replacement.)

List units

Listing active units displays a lot of useful information about your loaded and active services. The output is too detailed to demonstrate here, but try the following command on your system to see what I mean.

$ systemctl list-units

The status fields are great to see, but the description field is the most useful to me. It provides detailed information about your services.

Start a service

To get a service name, list your unit files and grep for the one you want. Then use the systemctl command to start your service. I'm using firewalld as the example.

$ sudo systemctl start firewalld

Surprisingly, or maybe not so surprisingly, there's no response from starting, stopping, or restarting a service. To check the status of a service, you must use the status command.

Checking a service status

To check a service's status, use the systemctl status service-name command.

$ sudo systemctl status sshd[sudo] password for khess: ● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2020-04-29 07:44:57 CDT; 2h 17min ago Docs: man:sshd(8) man:sshd_config(5) Main PID: 1055 (sshd) CGroup: /system.slice/sshd.service └─1055 /usr/sbin/sshd -DApr 29 07:44:57 centos7 systemd[1]: Starting OpenSSH server daemon...Apr 29 07:44:57 centos7 sshd[1055]: Server listening on 0.0.0.0 port 22.Apr 29 07:44:57 centos7 sshd[1055]: Server listening on :: port 22.Apr 29 07:44:57 centos7 systemd[1]: Started OpenSSH server daemon.Apr 29 07:51:35 centos7 sshd[1396]: Accepted password for khess from 192.168.1.85 port 56769 ssh2

I like systemd's status because of the detail given. For example, in the above listing, you see the full path to the unit file, the status, the start command, and the latest status changes.

[ Want to try out Red Hat Enterprise Linux? Download it now for free. ]

Stop a service

Stopping a running service is as easy as starting one.

$ sudo systemctl stop firewalld

Again, you see no response from issuing this command. Issue a service status to check your success or failure.

Restarting a service

If you want to stop and start a service without issuing two commands (sysadmins are a lazy lot, after all), issue a restart.

$ sudo systemctl restart firewalld

No system response is displayed.

System restart, halt, and shutdown

These three tasks are typical ones that sysadmins need to know and are now under the control of systemd.

Reboot

There are multiple ways to restart your systems, but the old standby, reboot, is actually a link to the systemctl command. I assume that since it works, it links the systemctl command with the reboot switch added as follows:

$ sudo systemctl reboot

The same link applies to the halt and to the shutdown commands.

Shutdown and halt

It doesn't matter how you used to do it with halt -p or shutdown now or whatever, the universal command is now:

$ sudo systemctl poweroff

This command powers down the system.

Set services to run at boot time

You're used to the chkconfig command to enable your services to run at boot time and under a particular runlevel. Well, those days too are gone, and they have been usurped by the ubiquitous systemctl command.

Enabling a service to run at boot time

To set any service to start at boot, issue the following command. I'm using firewalld as the example service.

$ sudo systemctl enable firewalld

Disabling a service from running at boot time

To prevent any service from starting at boot time, issue:

$ sudo systemctl disable firewalld

The firewalld service will not start at boot time.

Wrap up

This brief but handy systemd/systemctl reference guide should take some of the pain out of dealing with systemd. That's the theory, at least. And, as you'll often see in my articles or hear me say out loud, "Everything works on paper." Be sure to let me know on Twitter what you think of my articles and also to suggest new topics.

[ Free online course: Red Hat Enterprise Linux technical overview. ]

Topics: Linux

10 handy systemd commands: A reference (2024)
Top Articles
What Percentage of American Households Make Over $200k a Year?
What Is a Bitcoin ATM? | The Motley Fool
Fiskars X27 Kloofbijl - 92 cm | bol
Craigslist Campers Greenville Sc
Gore Videos Uncensored
Remnant Graveyard Elf
Unit 1 Lesson 5 Practice Problems Answer Key
Slmd Skincare Appointment
Oc Craiglsit
2015 Honda Fit EX-L for sale - Seattle, WA - craigslist
Praew Phat
Weather Rotterdam - Detailed bulletin - Free 15-day Marine forecasts - METEO CONSULT MARINE
Band Of Loyalty 5E
Selfservice Bright Lending
Veracross Login Bishop Lynch
Barber Gym Quantico Hours
Tu Pulga Online Utah
Dulce
Conscious Cloud Dispensary Photos
Galaxy Fold 4 im Test: Kauftipp trotz Nachfolger?
Parkeren Emmen | Reserveren vanaf €9,25 per dag | Q-Park
Sessional Dates U Of T
Beaufort 72 Hour
Skymovieshd.ib
Evil Dead Rise Showtimes Near Sierra Vista Cinemas 16
Unity Webgl Car Tag
Ullu Coupon Code
Dell 22 FHD-Computermonitor – E2222H | Dell Deutschland
Valley Craigslist
N.J. Hogenkamp Sons Funeral Home | Saint Henry, Ohio
Bursar.okstate.edu
Willys Pickup For Sale Craigslist
J&R Cycle Villa Park
Life Insurance Policies | New York Life
Mrstryst
Mega Millions Lottery - Winning Numbers & Results
Family Fare Ad Allendale Mi
Sams La Habra Gas Price
Latest Nigerian Music (Next 2020)
D-Day: Learn about the D-Day Invasion
Spectrum Outage in Genoa City, Wisconsin
Cpmc Mission Bernal Campus & Orthopedic Institute Photos
Joey Gentile Lpsg
Mybiglots Net Associates
Mynord
Access to Delta Websites for Retirees
Sacramentocraiglist
Aznchikz
Gear Bicycle Sales Butler Pa
Festival Gas Rewards Log In
Epower Raley's
Electronics coupons, offers & promotions | The Los Angeles Times
Latest Posts
Article information

Author: Margart Wisoky

Last Updated:

Views: 5451

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.