quick-docs/modules/ROOT/partialsdelete/2delete-proc_converting-sysvinit-services.adoc

100 lines
3.5 KiB
Text
Raw Normal View History

[#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.
2020-07-26 18:35:01 +00:00
[discrete]
2020-08-05 13:14:35 +00:00
== Prerequisites
* You are logged in as a user with administrator-level permissions.
* You have a custom SysVinit script to convert to a _systemd_ configuration.
2020-07-26 18:35:01 +00:00
[discrete]
2020-08-05 13:14:35 +00:00
== 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:
+
2018-01-21 17:04:05 +00:00
[source,bash]
----
start() {
2018-01-21 17:04:05 +00:00
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:
+
2018-01-21 17:04:05 +00:00
[source,bash]
----
reboot() {
2018-01-21 17:04:05 +00:00
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:
+
2018-01-21 17:04:05 +00:00
[source,bash]
----
reboot() {
2018-01-21 17:04:05 +00:00
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.
2020-07-26 18:35:01 +00:00
[discrete]
2020-08-05 13:14:35 +00:00
== Related Information
2018-01-21 17:04:05 +00:00
* See link:#common-service-parameters[Common service parameters] for more information about the parameters used in this procedure.