sami
sami

Reputation: 551

Systemd service configuration using environment variable

How do i set the MemoryLimit using environment variable I have tried set MemoryLimit field by using the variable MY_LIMIT like this, The Service configuration:

[Unit]
Description=Blabla

[Service]
Environment="MY_LIMIT=1024"
MemoryLimit=$MY_LIMIT
ExecStart=script.sh

But this doesnt seems to work As we see that

sudo systemctl show myservice

Show that the MemoryLimit is a assigned with this value instead

MemoryLimit=18446744073709551615

Upvotes: 1

Views: 2023

Answers (1)

Henrik Pingel
Henrik Pingel

Reputation: 3193

systemd has an Environment directive which sets environment variables for executed processes. source

So your MY_LIMIT won't get interpreted when set in MemoryLimit.

Also MemoryLimit is deprecated, use MemoryMax= instead. source

So what you should set is: MemoryMax=1024M

Upvotes: 2

Related Questions