Setting Environment Variables for a systemd Service: Difference between revisions
Jump to navigation
Jump to search
Line 8: | Line 8: | ||
=Create the Configuration Directory and the Configuration File= | =Create the Configuration Directory and the Configuration File= | ||
Create a directory < | Create a directory <code>/etc/systemd/system/myservice.service.d</code>. Inside that directory create a <code>.conf</code> file. Multiple files are allowed. These files contains configuration overrides for any part of the unit shipped by the distribution. | ||
A file that contains environment variables could be named < | A file that contains environment variables could be named <code>env.conf</code>. <code>myservice.conf</code> is also an acceptable name. | ||
{{Note|Note that if the configuration directory exists and is empty, the service will be disabled.}} | |||
=Configuration File Content= | =Configuration File Content= |
Revision as of 22:15, 19 August 2023
Internal
Overview
This document describes the procedure of configuring a systemd
service by injecting custom environment variables into its environment. The document assumes we're configuring a service named "myservice".
Create the Configuration Directory and the Configuration File
Create a directory /etc/systemd/system/myservice.service.d
. Inside that directory create a .conf
file. Multiple files are allowed. These files contains configuration overrides for any part of the unit shipped by the distribution.
A file that contains environment variables could be named env.conf
. myservice.conf
is also an acceptable name.
Note that if the configuration directory exists and is empty, the service will be disabled.
Configuration File Content
[Service] Environment="JAVA_HOME=/opt/java" Environment="JBOSS_HOME=/opt/jboss"