Setting Environment Variables for a systemd Service: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 9: Line 9:
=Create the Configuration Directory and the Configuration File=
=Create the Configuration Directory and the Configuration File=


Create a directory <tt>/etc/systemd/system/myservice.service.d</tt>. Inside that directory create a <tt>.conf</tt>. Multiple files are allowed. These files contains configuration overrides for any part of the unit shipped by the distribution.
Create a directory <tt>/etc/systemd/system/myservice.service.d</tt>. Inside that directory create a <tt>.conf</tt> 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 <tt>env.conf</tt>. <tt>myservice.conf</tt> is also an acceptable name.
A file that contains environment variables could be named <tt>env.conf</tt>. <tt>myservice.conf</tt> is also an acceptable name.

Revision as of 18:08, 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 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.

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

[Service] Environment="SECRET=pGNqduRFkB4K9C2vijOmUDa2kPtUhArN" Environment="ANOTHER_SECRET=JP8YLOc2bsNlrGuD6LVTq7L36obpjzxd"