From Fedora Project Wiki

(→‎Services: i find this handy)
 
(21 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{autolang|base=yes}}
{{autolang|base=yes}}


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 generation information on systemd, refer to [[systemd]]  
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]].


Note that the 'service' and 'chkconfig' commands will continue to work as expected in the systemd world, this guide is how to use the native  
{{admon/tip | Note on 'service' and 'chkconfig' commands | 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 calls that are being made by those commands.  
systemctl replacements. }}


== Services ==
== Services ==


{|
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'
!SystemVinit Command!!Systemd Command!!Notes
 
{|border="1" cellspacing="0"
!Sysvinit Command!!Systemd Command!!Notes
|-
|-
| ls /etc/rc.d/init.d/ || ls /lib/systemd/system/*.service /etc/systemd/system/*.service || Used to list the services that can be started or stopped
| service frobozz start || systemctl start frobozz || Used to start a service (not reboot persistent)
|-
|-
| chkconfig frobozz || systemctl is-enabled frobozz.service; echo $? || Used to check whether a service is configured to start or not in the current environment.
| service frobozz stop || systemctl stop frobozz || Used to stop a service (not reboot persistent)
|-
|-
|- chkconfig --list || ls /etc/systemd/system/*.wants/ || Print a table of services that lists which runlevels each is configured on or off
| service frobozz restart || systemctl restart frobozz  || Used to stop and then start a service
| chkconfig frobozz --list || ls /etc/systemd/system/*.wants/frobozz.service || Used to list what levels this service is configured on or off
|-
| service frobozz reload || systemctl reload frobozz || When supported, reloads the config file without interrupting pending operations.
|-
| service frobozz condrestart || systemctl condrestart frobozz  || Restarts if the service is already running.
|-
|-
| chkconfig frobozz --add || systemctl enable frobozz.service || Set a service to run in the runlevels specified in the init script<ref group="nb"><code>Although chkconfig --add</code> and <code>systemctl enable</code> perform roughly the same action, <code>chkconfig --add</code> is recommended when you first install a service while <code>systemctl enable</code> is recommended when you first turn a service on. </ref>
| service frobozz status || systemctl status frobozz || Tells whether a service is currently running.
|-
|-
| chkconfig frobozz --level 12345 on || for target in rescue multi-user ; do ln -s /lib/systemd/system/frobozz.service /etc/systemd/system/$target.target.wants/ && systemctl daemon-reload || Turn the service on for the next reboot.  <ref group="nb" name="runlevel">In systemd, the numeric ''runlevels'' have been replaced by named ''targets''.  The <code>graphical</code> target is a strict superset of the <code>multi-user</code> target so you don't have to set it up separately.  The custom runlevels (2 and 4 in this example) are not defined well enough to have a real systemd equivalent; if you use them for custom runlevels, you should try a custom named ''target'' in systemd instead. See the [[#Runlevels/targets| Runlevels section]] for more details</ref>
| ls /etc/rc.d/init.d/ ||  systemctl (or) systemctl list-unit-files --type=service (or) <br />ls /lib/systemd/system/*.service /etc/systemd/system/*.service|| Used to list the services that can be started or stopped <br /> Used to list all the services and other units
|-
|-
| chkconfig frobozz --level 12345 off || for target in rescue multi-user ; do rm /etc/systemd/system/$target.target.wants/frobozz.service && systemctl daemon-reload || Turn the service off for the next reboot. <ref group="nb" name="runlevel" />
| chkconfig frobozz on || systemctl enable frobozz || Turn the service on, for start at next boot, or other trigger.
|-
|-
| service frobozz start || systemctl start frobozz.service (OR service frobozz start) || Used to start a service (not reboot persistent)
| chkconfig frobozz off || systemctl disable frobozz || Turn the service off for the next reboot, or any other trigger.
|-
|-
| service frobozz stop || systemctl stop frobozz.service (OR service frobozz stop) || Used to stop a service (not reboot persistent)
| chkconfig frobozz || systemctl is-enabled frobozz || Used to check whether a service is configured to start or not in the current environment.
|-
|-
| service frobozz restart || systemctl restart frobozz.service (OR service frobozz restart) || Used to stop and then start a service
| chkconfig --list || systemctl list-unit-files --type=service (or) ls /etc/systemd/system/*.wants/ || Print a table of services that lists which runlevels each is configured on or off
|-
|-
| service frobozz reload || systemctl reload frobozz.service (OR service frobozz reload) || When supported, reloads the config file without interrupting pending operations.
| chkconfig --list &#124; grep 5:on || systemctl list-dependencies graphical.target || Print a table of services that will be started when booting into graphical mode
|-
|-
| service frobozz condrestart || systemctl reload-or-restart frobozz.service (OR systemctl condrestart frobozz.service OR service frobozz condrestart) || When supported, restarts if the service is already running.
| chkconfig frobozz --list || ls /etc/systemd/system/*.wants/frobozz.service || Used to list what levels this service is configured on or off
|-
|-
| service frobozz status || systemctl status frobozz.service || Tells whether a service is currently running.
| chkconfig frobozz --add || systemctl daemon-reload || Used when you create a new service file or modify any configuration
|-
|-
|}
|}
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.


{{admon/warning|Additional commands|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.
{{admon/warning|Additional commands|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.
Line 42: Line 49:


Check the package-specific release notes for any services that may have done this.}}
Check the package-specific release notes for any services that may have done this.}}
=== Notes ===
<references group="nb" />


== Runlevels/targets ==
== Runlevels/targets ==


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 ''target''s that mimic the common SystemVinit runlevels so you can still switch ''target''s using the familiar <code>telinit RUNLEVEL</code> 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 <code>/etc/systemd/system/$YOURTARGET</code> that takes one of the existing runlevels as a base (you can look at <code>/lib/systemd/system/graphical.target</code> as an example), make a directory <code>/etc/systemd/system/$YOURTARGET.wants</code>, and then symlink the additional services that you want to enable into that directory.  (The service unit files that you symlink live in <code>/lib/systemd/system</code>).
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 ''target''s that mimic the common sysvinit runlevels so you can still switch ''target''s using the familiar <code>telinit RUNLEVEL</code> 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 <code>/etc/systemd/system/$YOURTARGET</code> that takes one of the existing runlevels as a base (you can look at <code>/lib/systemd/system/graphical.target</code> as an example), make a directory <code>/etc/systemd/system/$YOURTARGET.wants</code>, and then symlink the additional services that you want to enable into that directory.  (The service unit files that you symlink live in <code>/lib/systemd/system</code>).


{|
{|border="1" cellspacing="0"
!SystemVinit Runlevel!!Systemd Target!!Notes
!Sysvinit Runlevel!!Systemd Target!!Notes
|-
|-
| 0 || runlevel0.target, poweroff.target || Halt the system.
| 0 || runlevel0.target, poweroff.target || Halt the system.
Line 71: Line 75:
Changing runlevels:
Changing runlevels:


{|
{|border="1" cellspacing="0"
!SystemVinit Command!!Systemd Command!!Notes
!Sysvinit Command!!Systemd Command!!Notes
|-
|-
| telinit 3 || systemctl isolate multi-user.target (OR systemctl isolate runlevel3.target OR telinit 3) || Change to multi-user run level.
| telinit 3 || systemctl isolate multi-user.target (OR systemctl isolate runlevel3.target OR telinit 3) || Change to multi-user run level.
Line 78: Line 82:
| 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.
| 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.
|}
|}
Kernel Options:
The above systemd targets can be used when booting.  At the GRUB menu, edit the selection to add "systemd.unit=''target''" (without the double-quotation marks) as a kernel option where ''target'' is one of the above.  (For example, "rescue.target".)
Tip:  the ".target" extention is optional.  The "systemd.unit=rescue" kernel option works the same as "systemd.unit=rescue.target".

Latest revision as of 10:33, 11 January 2017

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.

Idea.png
Note on 'service' and 'chkconfig' commands
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.

Services

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'

Sysvinit Command Systemd Command Notes
service frobozz start systemctl start frobozz Used to start a service (not reboot persistent)
service frobozz stop systemctl stop frobozz Used to stop a service (not reboot persistent)
service frobozz restart systemctl restart frobozz Used to stop and then start a service
service frobozz reload systemctl reload frobozz When supported, reloads the config file without interrupting pending operations.
service frobozz condrestart systemctl condrestart frobozz Restarts if the service is already running.
service frobozz status systemctl status frobozz Tells whether a service is currently running.
ls /etc/rc.d/init.d/ systemctl (or) systemctl list-unit-files --type=service (or)
ls /lib/systemd/system/*.service /etc/systemd/system/*.service
Used to list the services that can be started or stopped
Used to list all the services and other units
chkconfig frobozz on systemctl enable frobozz Turn the service on, for start at next boot, or other trigger.
chkconfig frobozz off systemctl disable frobozz Turn the service off for the next reboot, or any other trigger.
chkconfig frobozz systemctl is-enabled frobozz Used to check whether a service is configured to start or not in the current environment.
chkconfig --list systemctl list-unit-files --type=service (or) ls /etc/systemd/system/*.wants/ Print a table of services that lists which runlevels each is configured on or off
chkconfig --list | grep 5:on systemctl list-dependencies graphical.target Print a table of services that will be started when booting into graphical mode
chkconfig frobozz --list ls /etc/systemd/system/*.wants/frobozz.service Used to list what levels this service is configured on or off
chkconfig frobozz --add systemctl daemon-reload Used when you create a new service file or modify any configuration

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.

Warning.png
Additional commands
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.

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.

Check the package-specific release notes for any services that may have done this.

Runlevels/targets

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).

Sysvinit Runlevel Systemd Target Notes
0 runlevel0.target, poweroff.target Halt the system.
1, s, single runlevel1.target, rescue.target Single user mode.
2, 4 runlevel2.target, runlevel4.target, multi-user.target User-defined/Site-specific runlevels. By default, identical to 3.
3 runlevel3.target, multi-user.target Multi-user, non-graphical. Users can usually login via multiple consoles or via the network.
5 runlevel5.target, graphical.target Multi-user, graphical. Usually has all the services of runlevel 3 plus a graphical login.
6 runlevel6.target, reboot.target Reboot
emergency emergency.target Emergency shell

Changing runlevels:

Sysvinit Command Systemd Command Notes
telinit 3 systemctl isolate multi-user.target (OR systemctl isolate runlevel3.target OR telinit 3) Change to multi-user run level.
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.

Kernel Options:

The above systemd targets can be used when booting. At the GRUB menu, edit the selection to add "systemd.unit=target" (without the double-quotation marks) as a kernel option where target is one of the above. (For example, "rescue.target".)

Tip: the ".target" extention is optional. The "systemd.unit=rescue" kernel option works the same as "systemd.unit=rescue.target".