Projekt

Allgemein

Profil

Howto systemctl » Historie » Version 3

Jeremias Keihsler, 07.02.2020 13:54

1 1 Jeremias Keihsler
h1. SysVinit to Systemd Cheatsheet
2
3
this is taken from http://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet
4
5
This is a document to help system administrators who need to understand what commands in systemd replace their old workflow in sysvinit. If you want general information on systemd, refer to systemd.
6
7
Note on @service@ and @chkconfig@ commands
8
The @service@ and @chkconfig@ commands will mostly continue to work as expected in the systemd world, this guide is how to use the native systemctl replacements.
9
10
h2. Services
11
12
Note that all recent versions of systemctl assume the @.service@ if left off. So, @systemctl start frobozz.service@ is the same as @systemctl start frobozz@
13
14
|_. Sysvinit Command             |_. Systemd Command                                 |_. Notes                                                                                     |
15
| service frobozz start        | systemctl start frobozz.service                 | Used to start a service (not reboot persistent)                                           |
16
| service frobozz stop         | systemctl stop frobozz.service                  | Used to stop a service (not reboot persistent)                                            |
17
| service frobozz restart      | systemctl restart frobozz.service               | Used to stop and then start a service                                                     |
18
| service frobozz reload       | systemctl reload frobozz.service                | When supported, reloads the config file without interrupting pending operations.          |
19
| service frobozz condrestart  | systemctl condrestart frobozz.service           | Restarts if the service is already running.                                               |
20
| service frobozz status       | systemctl status frobozz.service                | Tells whether a service is currently running.                                             |
21
| ls /etc/rc.d/init.d/         | systemctl list-unit-files --type=service        | Used to list the services that can be started or stopped                                  |
22
| chkconfig frobozz on         | systemctl enable frobozz.service                | Turn the service on, for start at next boot, or other trigger.                            |
23
| chkconfig frobozz off        | systemctl disable frobozz.service               | Turn the service off for the next reboot, or any other trigger.                           |
24
| chkconfig frobozz            | systemctl is-enabled frobozz.service            | Used to check whether a service is configured to start or not in the current environment. |
25
| chkconfig --list             | systemctl list-unit-files --type=service        | Print a table of services that lists which runlevels each is configured on or off         |
26
| chkconfig frobozz --list     | ls /etc/systemd/system/*.wants /frobozz.service | Used to list what levels this service is configured on or off                             |
27
| chkconfig frobozz --add      | systemctl daemon-reload                         | Used when you create a new service file or modify any configuration                       |
28
29
Note that all @/sbin/service@ and @/sbin/chkconfig@ lines listed above continue to work on systemd, and will be translated to native equivalents as necessary. The only exception is @chkconfig --list@. 
30
31
h3. Additional commands
32
33
In SysVinit, services can define arbitrary commands. Examples would be @service iptables panic@, or @service httpd graceful@. Native systemd services do not have this ability.
34
35
Any service that defines an additional command in this way would need to define some other, service-specific, way to accomplish this task when writing a native systemd service definition.
36
Check the package-specific release notes for any services that may have done this.
37
38
h2. Runlevels/targets
39
40
Systemd has a concept of targets which serve a similar purpose as runlevels but act a little different. Each target is named instead of numbered and is intended to serve a specific purpose. Some targets are implemented by inheriting all of the services of another target and adding additional services to it. There are systemd targets that mimic the common sysvinit runlevels so you can still switch targets using the familiar telinit RUNLEVEL command. The runlevels that are assigned a specific purpose on vanilla Fedora installs; 0, 1, 3, 5, and 6; have a 1:1 mapping with a specific systemd target. Unfortunately, there's no good way to do the same for the user-defined runlevels like 2 and 4. If you make use of those it is suggested that you make a new named systemd target as /etc/systemd/system/$YOURTARGET that takes one of the existing runlevels as a base (you can look at /lib/systemd/system/graphical.target as an example), make a directory /etc/systemd/system/$YOURTARGET.wants, and then symlink the additional services that you want to enable into that directory. (The service unit files that you symlink live in /lib/systemd/system). 
41
42
|_. Sysvinit Runlevel |_. Systemd Target                     |_. Notes                                                                                        |
43
| 0                 | poweroff.target                    | Halt the system.                                                                             |
44
| 1, s, single      | rescue.target                      | Single user mode.                                                                            |
45
| 2, 4              | runlevel2.target, runlevel4.target | User-defined/Site-specific runlevels. By default, identical to 3.                            |
46
| 3                 | multi-user.target                  | Multi-user, non-graphical. Users can usually login via multiple consoles or via the network. |
47
| 5                 | graphical.target                   | Multi-user, graphical. Usually has all the services of runlevel 3 plus a graphical login.    |
48
| 6                 | reboot.target                      | Reboot                                                                                       |
49
| emergency         | emergency.target                   | Emergency shell                                                                              |
50
51
Changing runlevels:
52
|_. Sysvinit Command                                 |_. Systemd Command                                                                     |_. Notes                                          |
53
| @telinit 3@                                    | @systemctl isolate multi-user.target@                                             | Change to multi-user run level.                |
54 2 Jeremias Keihsler
| @sed s/^id:.*:initdefault:/id:3:initdefault:/@ | @ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target@ | Set to use multi-user runlevel on next reboot. |
55 1 Jeremias Keihsler
56 3 Jeremias Keihsler
get/set default runlevel:
57
@systemctl get-default@
58
@systemctl set-default multi-user.target@
59
60 1 Jeremias Keihsler
Kernel Options:
61
62
The above systemd targets can be used when booting. At the GRUB menu, edit the selection to add @systemd.unit=target@ as a kernel option where target is one of the above. (For example, @rescue.target@.)
63
64 2 Jeremias Keihsler
Tip: the @.target@ extention is optional. The @systemd.unit=rescue@ kernel option works the same as @systemd.unit=rescue.target@.