| |
Command Syntax |
|
| The systemctl command typically follow this syntax: |
| |
█ systemctl <command> <unit> |
|
| It starts with the main call and is followed by these optional parts: |
| |
- <command> the action to take.
- <unit> the service (or resource) to apply that action to.
|
|
| So in short, you simply tell systemctl what action to take on what service. |
| |
Usage Examples |
|
| |
Start / Stop a Service |
|
| Start a service to make it available to users: |
| |
█ systemctl start <service>
|
|
| After installing a new service, like PlexMedia Server for instance, You'll want to launch the service. |
| The service will run in background and other users can connect to it. |
| |
█ sudo systemctl start plexmediaserver
|
|
| Stop a service to make it unavailable to users: |
| |
█ systemctl stop <service>
|
|
| Stopping a service takes it down, which is useful when you need to peform maintenance or if you want to stop others from being able to connect to it. |
| |
Autostart a Service on Boot |
|
| But what happens to a service when you shutdown or reboot? |
| When the system reboots, your service will be down. |
| If you want the service to always start, such as a web server that you want to be available 24/7, the solution is to make it load automatically every time the system boots. |
| |
Enable a service to automatically start on boot: |
|
| |
█ systemctl enable <service>
|
|
| |
Disable a service to remove it from the autostart list: |
|
| |
█ systemctl disable <service> |
|
| |
Trobleshoot a service |
|
| Sometimes, I can't connect to one of my servers, like VNC remote access, and I don't know why. |
| These commands will help you find out what's going on so you can get things running again. |
| |
Check the status of a service |
|
| |
█ systemctl status <service>
|
|
| The output will report the service status i.e. Loaded or not and active or inactive. |
| The soulution maybe to start the service and enable it. |
| |
Restart a service to stop and start it again: |
|
| |
█ systemctl restart <service>
|
|
| What if you need to change the configuration for a service, but you don't want to bring it down because it will distrupt your users' activity? For instance, maybe you have a Postfix email server, and are testing a lot of settings over and over. |
| In this case, you can use the reload command instead. |
| |
█ systemctl reload <service>
|
|
| |
Kill a service to terminate it forcefully: |
|
| |
█ systemctl kill <service>
|
|
| |
List All Services |
|
| if you want to manage or troubleshoot a service but don't know what name it goes by on your system, the systemctl command can be used to figure it out. |
| If you enter systemctl command with no parameters,you'll get a long lisst of everything initialized on your system, like kernel modules and virtual RAM disks. This can be 200 lines (or more), and in my experience,that's often information overload. |
| Let's say you're only interested in what services are on the system. You can filter systemctl's output to narrow down what you see. |
| |
List services only: |
|
| |
█ systemctl list-units --type=service
|
|
| This command filters the output to show services only and is more readable. |
| But maybe you want to narrow that list down even more. ProbabIy you're only interested in learning about services that are active, use these next command. |
| |
List running services to see which ones have been started: |
|
| |
█ systemctl list-units --type=service --state=running
|
|
| |
|
|
| |
|
|
| |
|
|