---
slug: Managing Systemd Services and Units with Systemctl A Guide
title: Managing Systemd Services and Units with Systemctl A Guide
authors: [slorber, yangshun]
tags: [hola, docusaurus]
---

<!-- truncate -->
import CodeBlock from '@site/src/components/CodeBloack';


<div className="head">Introduction</div>


<div className="text">Systemd is an important part of many Linux computers. It acts like an organizer that helps your computer work smoothly. Understanding systemd might seem a bit challenging at first, but it's a powerful tool that simplifies managing your computer. Learning about systemd and its tools will give you more control and flexibility over your computer. It's like having a reliable assistant that makes your computer tasks easier. So, let's explore systemd together and see how it can become your computer's helpful companion!</div><br/>

<div className="text">In this guide, we'll explore a command called 'systemctl,' a powerful tool for managing how your computer starts and runs programs. We'll cover how to control programs, check their status, make changes and work with special files that control how everything functions.</div><br/>

<div className="text">Just so you know, not all computers use the same tools. If you come across a message like 'bash: systemctl is not installed,' it means your computer has a different setup. No worries, though – you can still learn a lot from this guide!</div><br/>


<div className="head">Managing Services with Systemctl</div>

<div className="text">The init system is like the manager of your computer. Its main job is to get things ready after you turn on your computer, which we call 'userland' components. It also looks after special helpers called services and daemons while your computer is already up and running. Now, let's jump into some simple ways to take care of these services – it's like learning how to manage different tasks on your computer!</div><br/>


<div className="text">In systemd, everything we want to control is called a 'unit.' Units are like different parts of your computer that systemd knows how to handle. Each unit is put into a group based on what it does, and we describe them using files called unit files. You can tell what type of unit it is by looking at the end of its file name.</div><br/>

<div className="text">When you're managing services, you'll mainly deal with something called 'service units.' These units have files with names ending in .service. But here's something cool: most of the time, you can just leave off the .service part when you're giving commands to systemd. It's clever enough to figure out that you're probably talking about a service!</div><br/>


<div className="text" style={{ fontSize:'28px' }}>Getting Services Going and Turning Them Off</div>

<div className="text">To get a systemd service up and running, you use the start command. If you're not the main user of the computer, you'll need to add sudo before the command, because starting a service can change how the computer works:</div>


<CodeBlock code={`sudo systemctl start application.service`} /><br/>

<div className="text">As we mentioned earlier, when you're dealing with services in systemd, you usually don't need to worry about typing the ".service" part. So, you can just type the command like this:</div>

<CodeBlock code={`sudo systemctl start application`} /><br/>

<div className="text">While you can use the simplified command we mentioned earlier for most things, for better clarity in our instructions, we'll include the ".service" part in the following commands.</div><br/>

<div className="text">To turn off a service that's currently running, use the stop command instead:</div>

<div className="text">sudo systemctl stop application.service</div>

<div className="text" style={{ fontSize:'28px' }}>Refreshing and Rebooting Services</div>

<div className="text">To give a running service a fresh start, you can use the restart command:</div>

<CodeBlock code={`sudo systemctl restart application.service`} /><br/>

<div className="text">If the program you're using can update its settings without needing to restart, you can use the reload command to make that happen:</div>

<CodeBlock code={`sudo systemctl reload application.service`} /><br/>

<div className="text">If you're not sure whether the service can update its settings without restarting, you can use the reload-or-restart command. This smart command will try to update the settings in place if possible. If not, it will simply restart the service with the new settings.</div>

<CodeBlock code={`sudo systemctl reload-or-restart application.service`} /><br/>

<div className="text" style={{ fontSize:'28px' }}>Turning Services On and Off</div>

<div className="text">The commands we talked about earlier are handy for turning services on or off while you're using your computer. But if you want a service to start automatically every time you turn on your computer, you need to tell systemd to do that.</div><br/>

<div className="text">To make a service start automatically when you boot up your computer, use the enable command:</div>

<CodeBlock code={`sudo systemctl enable application.service`} /><br/>

<div className="text">When you use the enable command, it basically creates a special link. This link points from where your computer usually keeps track of services (like in /lib/systemd/system or /etc/systemd/system) to the place where systemd checks for things to start automatically (usually /etc/systemd/system/some_target.target.wants).</div><br/>

<div className="text">Now, if you change your mind and don't want a service to start automatically anymore, you can type:</div>

<CodeBlock code={`sudo systemctl disable application.service`} /><br/>

<div className="text">This will simply undo the special link that makes the service start automatically.</div><br/>

<div className="text">Remember, when you enable a service, it doesn't start running right away. If you want it to start now and also whenever you turn on your computer, you'll need to use both the start and enable commands.</div><br/>


<div className="text" style={{ fontSize:'28px' }}>Checking How Services Are Doing</div>

<div className="text">To see how a service is doing on your computer, you can use the status command:</div>


<CodeBlock code={`systemctl status application.service`} /><br/>

<div className="text">This will give you information about the service, like whether it's running or not, where it's organized in the system, and some early details from its logs.</div><br/>

<div className="text">For example, if you check the status of an Nginx server, you might see something like this:</div>

<CodeBlock code={`Output
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2015-01-27 19:41:23 EST; 22h ago
 Main PID: 495 (nginx)
   CGroup: /system.slice/nginx.service
           ├─495 nginx: master process /usr/bin/nginx -g pid /run/nginx.pid; error_log stderr;
           └─496 nginx: worker process
Jan 27 19:41:23 desktop systemd[1]: Starting A high performance web server and a reverse proxy server...
Jan 27 19:41:23 desktop systemd[1]: Started A high performance web server and a reverse proxy server.
`} /><br/>

<div className="text">This gives you a helpful summary of how the application is doing, letting you know if there are any issues or if anything needs your attention.</div><br/>

<div className="text">If you want to check if a unit (like a service) is currently doing its job (running), you can use the is-active command:</div>