systemd on Linux 2: systemctl commands

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's talk about systemctl which is one of the two main commands you're going to use to interact with systemd the other being journal ctl to interact with logs in the systemd journal systemctl uh has a bunch of sub commands where the syntax is kind of like system ctl then the sub command you want and then like flags options the first one we're going to look at is the one that happens if you just run systemctl what that's actually doing is systemctl list units and you can narrow that with things like type equals service and that gives you a list you can page through with the spacebar and quit with the q key and that just shows you kind of all of your services and some information about them like are they loaded are they active are they running did they run and exit if you want a full listing this is only active and running or at least services that ran what you might want is list unit files and that will show you things that are all the unit files including disabled masked uh ones etc static ones this is a much more exhaustive list of all of the systemd units on your system let's go through all of the basic system ctl sub commands that deal with managing the state of units first there's status you'll be using this one all the time and this is just a way of getting the status of a service in this case the information it returns is really kind of a minimal set it gives us the service name the description that was given in the unit file the path to the unit file whether it's enabled or disabled and some information about if you just do a raw install through the package manager this is the vendor preset would be that it would be enabled by default whether it's running or not it's inactive let's enable nginx it's disabled right so let's see what happens it executes this command it creates a sim link from the target that wants it it's listed at the end of in the install section of the unit file it says multi-user target wants this so it's adding this to the place where that actually gets looked up as a sim link just a sim link to the unit file right if that's confusing here that's what this is install fine if you're going to enable this then it's wanted by multi-user target which just translates to we make a sim link to the multi-user target wants directory which gets looked at when you when the system approaches this target like everything's up multi-user login is enabled well one of the pre-the wants directory here contains all the prerequisites for that and here it just literally makes a sim link of the unit file cool so now it's enabled let's look at the status again you might be surprised that it is still inactive even though it's now enabled instead of disabled well that is because enabling and disabling something don't actually start or stop a service they only control what happens at boot so only at boot time does enable or disable matter if i rebooted this machine now then the service would be started before it reached the multi-user target so before it was finished booting uh looks like disable is not in my shell history we're going to say disable nginx again so it's going to remove that sim link it's just going to do the opposite so let's actually start it systemctl start nginx and now if we look at its status it is active and running and we have a bit more information here too so first off uh still loaded it's still disabled but now it's active and running it gives me the start time gives me the documentation uh that's actually the same as before and then it gives us the processes that are running the main page so this would be what's in the the pid file that it defines in its um in its unit file so in the unit file there's a path i think it was run nginx so you can see where that main pit is coming from that's the one that nginx lists as its main pid so that's the one that systemd picks up and that's because of the type of service that nginx is it's a forking uh process here's the number of tasks running for it the memory it's taking up the c group information i'm not going to get into that in this um video and then logs so it gives you it basically gives you a tail of the the logs it's it'll be like the last five or ten lines so it kind of gives you a nice snapshot of everything that's running or everything that's going on with the service when you look at a running service the next command is stop systemctl stop enginex and now if we look for status you can see that you still get that log data here but it's simply inactive now and you actually have some extra log messages of when we sent the stop signal to it now if you remember in the unit file there is actually a reload exact reload um command defined so if we started this and then we said system system ctl reload nginx that's what would get um executed but it's not running so nothing's gonna happen there is no restart defined so if you run systemctl restart what it'll do is it'll do an exact stop which if it's not running will have no effect and then it will do an exact start which will just be running this alright so a restart is simply a stop and a start so even though it wasn't running when we restart it it will run the stop command with no effect because it's not running and then we'll run the start command so it'll be just as if you had started it so those are the main kind of commands you need to know about enable and disable which only trigger at boot start and stop which trigger immediately and have no effect on what happens at boot restart and reload which kind of do configurable things but sane intuitive things by default status and then there's also kill system ctl kill engine x kills the pattern that you put here in this case just nginx the statuses that you might see are kind of varied you can see a list of them here they can be active like you saw when i turned on nginx uh or did i turn on nginx let's start nginx you can see that this is this went from inactive to active running um you might get a status like disabled enabled bad um if there's an actual like syntax problem usually on your unit file this is if you're if you're home cooking artisanally crafting with the finest ingredients your own unit files you're going to see a lot of bad statuses occasionally masked if you have masked a unit that is sort of it exists on disk but like systemd is going to just ignore it for whatever reason that's often a useful troubleshooting tool static is another status um you can see the status by the way with systemctl status long log lines if you want so if these log lines are too long to see then that dash l will give you the full log line you can scroll left and right um indirect is another status where it's not enabled or actually disabled but another unit file references it so it could be activated possibly uh linked is a sim linked one i've never used that uh it's in there i'm telling you because this is an educational video and that's kind of all you need to know about systemctl just to get started and do like the 90 of your work interacting with system d on a service management or really unit file management level
Info
Channel: tutoriaLinux
Views: 33,428
Rating: undefined out of 5
Keywords: computer, how-to, Linux, tutorial, system administration, sysadmin, command-line, CLI
Id: fzOceeJB5vw
Channel Id: undefined
Length: 9min 7sec (547 seconds)
Published: Fri Jul 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.