mirror of
https://pagure.io/fedora-docs/quick-docs.git
synced 2024-11-25 05:37:32 +00:00
34fc23c4f1
Following the upstream documentation for systemd network target: https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/ It is not supposed to be used as an active unit and it cannot be started directly. Quote from the website: Note that network.target is a passive unit: you cannot start it directly and it is not pulled in by any services that want to make use of the network. Instead, it is pulled in by the network management service itself. Services using the network should hence simply place an After=network.target dependency in their unit files, and avoid any Wants=network.target or even Requires=network.target. This patch changes the documentation to follow the upstream recommendation.
99 lines
3.5 KiB
Text
99 lines
3.5 KiB
Text
[#converting-sysvinit-services]
|
|
= Converting SysVinit services to systemd
|
|
|
|
Older versions of Fedora use SysVinit scripts to manage services. This section provides some guidelines on how to convert a SysVinit script to a _systemd_ equivalent.
|
|
|
|
[discrete]
|
|
== Prerequisites
|
|
|
|
* You are logged in as a user with administrator-level permissions.
|
|
|
|
* You have a custom SysVinit script to convert to a _systemd_ configuration.
|
|
|
|
[discrete]
|
|
== Procedure
|
|
|
|
. Identify the runlevels in your SysVinit script. This is usually defined with `chkconfig` directive in the commented section at the beginning of the script. For example, the following indicates the service is using runlevels 3, 4, and 5:
|
|
+
|
|
----
|
|
# chkconfig: 235 20 80
|
|
----
|
|
+
|
|
systemd uses targets instead of runlevels. Use the table in <<#converting-sysvinit-services>> to map the runlevels to targets. In this example, runlevels 2, 3, and 5 are all multi-user runlevels, so the _systemd_ service can use the following:
|
|
+
|
|
----
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
----
|
|
+
|
|
If you enable the custom _systemd_ service to start at boot (`systemctl enable foo.service`), _systemd_ loads the service when loading the `multi-user.target` at boot time.
|
|
|
|
. Identify the dependent services and targets. For example, if the custom service requires network connectivity, specify the `network.target` as a dependency:
|
|
+
|
|
----
|
|
[Unit]
|
|
Description=My custom service
|
|
After=network.target
|
|
----
|
|
|
|
. Identify the command used to start the service in the SysVinit script and convert this to the _systemd_ equivalent. For example, the script might contain a `start` function in the following format:
|
|
+
|
|
[source,bash]
|
|
----
|
|
start() {
|
|
echo "Starting My Custom Service..."
|
|
/usr/bin/myservice -D
|
|
}
|
|
----
|
|
+
|
|
In this example, the `/usr/bin/myservice` command is the custom service command set to daemonize with the `-D` option. Set the `ExecStart` parameter to use this command:
|
|
+
|
|
----
|
|
[Service]
|
|
ExecStart=/usr/bin/myservice -D
|
|
----
|
|
|
|
. Check the SysVinit script to see if the service uses a special command to restart the service. For example, the script might contain a `reboot` function that reloads the service:
|
|
+
|
|
[source,bash]
|
|
----
|
|
reboot() {
|
|
echo "Reloading My Custom Service..."
|
|
/usr/bin/myservice reload
|
|
}
|
|
----
|
|
+
|
|
In this example, the `/usr/bin/myservice` command is the custom service command and reloads the service using the `reload` subcommand. Set the `ExecReload` parameter to use this command:
|
|
+
|
|
----
|
|
[Service]
|
|
ExecReload=/usr/bin/myservice reload
|
|
----
|
|
+
|
|
Alternatively, you can omit `ExecReload` and use the default behavior, which kills the service and starts it again.
|
|
|
|
. Check the SysVinit script to see if the service uses a special command to stop the service. For example, the script might contain a `stop` function that reloads the service:
|
|
+
|
|
[source,bash]
|
|
----
|
|
reboot() {
|
|
echo "Stopping My Custom Service..."
|
|
/usr/bin/myservice shutdown
|
|
}
|
|
----
|
|
+
|
|
In this example, the `/usr/bin/myservice` command is the custom service command and stop the service gracefully using the `shutdown` subcommand. Set the `ExecStop` parameter to use this command:
|
|
+
|
|
----
|
|
[Service]
|
|
ExecStop=/usr/bin/myservice shutdown
|
|
----
|
|
+
|
|
Alternatively, you can omit `ExecStop` and use the default behavior, which kills the service.
|
|
|
|
. Review the SysVinit script and identify any additional parameters or functions. Use _systemd_ parameters to replicate any identified SysVinit functions that might be relevant to your service.
|
|
|
|
[discrete]
|
|
== Related Information
|
|
|
|
* See link:#common-service-parameters[Common service parameters] for more information about the parameters used in this procedure.
|