starting and stopping services |
sudo systemctl start application.service
|
sudo systemctl start application
|
systemctl looks for *.service already, not necessary to actually place in command. |
sudo systemctl stop application.service
|
restarting and reloading |
sudo systemctl restart application.service
|
fully restart srevice. |
sudo systemctl reload application.service
|
reload config files without restarting. |
sudo systemctl reload-or-restart application.service
|
if unsure that it can reload, this will try reload first then restart. |
Enabling and Disabling Services |
sudo systemctl enable application.service
|
creates a sym link from the system’s copy of the service file (usually in /lib/systemd/system
or /etc/systemd/system
) into the location on disk where systemd looks for autostart files. |
sudo systemctl disable application.service
|
removes sym link |
Checking the Status of Services |
systemctl status application.service
|
This will provide you with the service state, the cgroup hierarchy, and the first few log lines. |
systemctl is-active application.service
|
This will return the current unit state, which is usually active or inactive. exit code 0 if true |
systemctl is-enabled application.service
|
This will output whether the service is enabled or disabled. Exit code 0 if true. |
systemctl is-failed application.service
|
This will return active if it is running properly or failed if an error occurred. If the unit was intentionally stopped, it may return unknown or inactive. Exit code 0
if failure has occurred. |
Listing Current Units |
|
This will show you a list of all of the units that systemd currently has active on the system |
systemctl list-units --all
|
This will show any unit that systemd loaded or attempted to load, regardless of its current state on the system. |
systemctl list-units --all --state=inactive |
Another common filter is the --type= filter. We can tell systemctl to only display units of the type we are interested in. |
systemctl list-unit-files
|
Units are representations of resources that systemd knows about. Since systemd has not necessarily read all of the unit definitions in this view, it only presents information about the files themselves. |
Displaying a Unit File |
systemctl cat atd.service
|
The output is the unit file as known to the currently running systemd process. |
Displaying Dependencies |
systemctl list-dependencies sshd.service
|
This will display a hierarchy mapping the dependencies that must be dealt with in order to start the unit in question. |
Checking Unit Properties |
systemctl show sshd.service
|
To see the low-level properties of a unit, you can use the show command. |
systemctl show sshd.service -p Conflicts |
To display a single property, you can pass the -p flag with the property name. |
Masking and Unmasking Units |
mark a unit as completely unstartable, automatically or manually, by linking it to /dev/null. |
sudo systemctl mask nginx.service
|
This will prevent the Nginx service from being started, automatically or manually, for as long as it is masked. |
sudo systemctl unmask nginx.service
|
This will return the unit to its previous state, allowing it to be started or enabled. |
Editing Unit Files |
sudo systemctl edit nginx.service
|
This will be a blank file that can be used to override or add directives to the unit definition. A directory will be created within the /etc/systemd/system directory which contains the name of the unit with .d appended. For instance, for the nginx.service, a directory called nginx.service.d will be created. |
sudo systemctl edit --full nginx.service
|
This will load the current unit file into the editor, where it can be modified. |
sudo rm -r /etc/systemd/system/nginx.service.d
|
remove snippet created |
sudo rm /etc/systemd/system/nginx.service
|
To remove a full modified unit file, we would type: |
Adjusting the System State (Runlevel) with Targets |
|
find the default target for your system |
sudo systemctl set-default graphical.target
|
If you wish to set a different default target, you can use the set-default. For instance, if you have a graphical desktop installed and you wish for the system to boot into that by default, you can change your default target accordingly: |
Listing Available Targets |
systemctl list-unit-files --type=target |
You can get a list of the available targets on your system by typing |
systemctl list-units --type=target |
To see all of the active targets, type: |
Isolating Targets |
systemctl list-dependencies multi-user.target
|
sudo systemctl isolate multi-user.target
|
Using Shortcuts for Important Events |
|
put the system into rescue (single-user) mode, you can just use the rescue command |
|
To halt the system, you can use the halt command: |
|
To initiate a full shutdown, you can use the poweroff command: |
|
A restart can be started with the reboot command: |
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
More Cheat Sheets by jhaley32