quick-docs/modules/ROOT/pages/_partials/proc_modifying-existing-systemd-services.adoc

54 lines
1.7 KiB
Text
Raw Normal View History

[#modifying-existing-systemd-services]
2018-02-26 16:43:59 +00:00
= Modifying existing systemd services
2020-08-05 16:44:28 +00:00
This example shows how to modify an existing service. Service modification are stored within `/etc/systemd/system`, in a single file or in a subdirectory named after the service. For example, this procedure modifies the `httpd` service.
2020-07-26 18:35:01 +00:00
[discrete]
2020-08-05 14:22:16 +00:00
== Prerequisites
* You are logged in as a user with administrator-level permissions.
* You have a configured `httpd` server running through _systemd_.
2020-07-26 18:35:01 +00:00
[discrete]
2020-08-05 14:22:16 +00:00
== Procedure
2020-08-05 16:44:28 +00:00
. _Systemd_ services can be modified using the `systemctl edit` command.
+
----
2020-08-05 16:44:28 +00:00
# systemctl edit httpd.service
----
+
2020-08-05 16:44:28 +00:00
This creates an override file `/etc/systemd/system/httpd.service.d/override.conf` and opens it in your text editor. Anything you put into this file will be *added* to the existing service file.
. Add your custom configuration. For example:
+
----
[Service]
Restart=always
RestartSec=30
----
2020-08-05 16:44:28 +00:00
+
To replace an option that can be set multiple times, it must cleared first, otherwise the override file will add the option a second time.
+
----
[Service]
ExecStart=
ExecStart=<new command>
----
2020-08-05 16:44:28 +00:00
. Save the file. _Systemd_ automatically loads the new service configuration.
. Restart the `httpd` service:
+
----
2018-01-21 17:04:05 +00:00
# systemctl restart httpd
----
2020-08-05 16:44:28 +00:00
To completely replace (instead of just add to/modify) an existing service file, use `systemctl edit --full`, e.g. `systemctl edit --full httpd.service`. This will create `/etc/systemctl/system/httpd.service`, which will be used instead of the existing service file.
2020-07-26 18:35:01 +00:00
[discrete]
2020-08-05 14:22:16 +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.