Setting Environment Variables for a systemd Service: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * systemd")
 
No edit summary
Line 2: Line 2:


* [[systemd#Configuration|systemd]]
* [[systemd#Configuration|systemd]]
=Overview=
This document describes the procedure of configuring a <tt>systemd</tt> service by injecting custom environment variables into its environment. The document assumes we're configuring a service named "myservice".
=Create the Configuration Directory=
Create a directory /etc/systemd/system/myservice.service.d, and inside that directory create a file whose name ends in .conf, and in this file you can add to or override any part of the unit shipped by the distribution.
For instance, in a file /etc/systemd/system/myservice.service.d/myenv.conf:
[Service]
Environment="SECRET=pGNqduRFkB4K9C2vijOmUDa2kPtUhArN"
Environment="ANOTHER_SECRET=JP8YLOc2bsNlrGuD6LVTq7L36obpjzxd"
Also note that if the directory exists and is empty, your service will be disabled! If you don't intend to put something in the directory, ensure that it does not exist.

Revision as of 17:51, 16 February 2016

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

Create a directory /etc/systemd/system/myservice.service.d, and inside that directory create a file whose name ends in .conf, and in this file you can add to or override any part of the unit shipped by the distribution.

For instance, in a file /etc/systemd/system/myservice.service.d/myenv.conf:

[Service] Environment="SECRET=pGNqduRFkB4K9C2vijOmUDa2kPtUhArN" Environment="ANOTHER_SECRET=JP8YLOc2bsNlrGuD6LVTq7L36obpjzxd" Also note that if the directory exists and is empty, your service will be disabled! If you don't intend to put something in the directory, ensure that it does not exist.