SystemD - Environment Variable for a service

About

How to add environment to a service within SystemD

List

Bash Profile

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

[Unit]
Description=Starts the process
After=network.target

[Service]
User=user
ExecStartPre=/bin/sleep 5
ExecStart=/bin/bash -c '. "$0" && exec "$@"' /home/user/.bash_profile /tomcat/bin/service.sh startup
ExecStop=/tomcat/bin/service.sh shutdown
Type=forking
TimeoutSec=infinity

[Install]
WantedBy=multi-user.target

Environment property

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

Environment File

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

where :

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

Documentation / Reference





Discover More
SystemD - Services

This page is service management with the systemd init process. .servicesystemd.service It is designed to replace and be backwards compatible with SysV init scripts. Traditional init scripts continue...



Share this page:
Follow us:
Task Runner