SystemD - Environment Variable for a service

> Operating System - Kernel (Windows, Unix, Linux) > Linux / Unix > Linux - Boot (Init service system) > SystemD

1 - About

How to add environment to a service within SystemD

3 - List

3.1 - Bash Profile

Shell - (Startup|Login) script (.bash_profile, .profile, .login)

command.service
[Unit]
Description=Starts the process
After=network.target
 
[Service]
User=user
ExecStartPre=/bin/sleep 5
ExecStart=/bin/bash -c '. "$0" && exec "[email protected]"' /home/user/.bash_profile /tomcat/bin/service.sh startup
ExecStop=/tomcat/bin/service.sh shutdown
Type=forking
TimeoutSec=infinity
 
[Install]
WantedBy=multi-user.target
Advertising

3.2 - Environment property

[Service]
Environment="SECRET=pGNqdu23ffr9C2vijOmUDa2kPtUhArN"
Environment="ENV2=JP8YLOc00333887722Tq7L36obpjzxd"

3.3 - Environment File

whatever.service
[Service]
ExecStart=/usr/bin/whatever
EnvironmentFile=/path/to/env_service.conf

where :

/path/to/env_service.conf
IPV4_ANCHOR_0=X.X.X.X
PV4_PRIVATE_0=X.X.X.X
HOSTNAME=test.example.com
IPV4_PUBLIC_0=X.X.X.X
ENV1=X:X:X:X:X:X:X:X

4 - Documentation / Reference