Q:

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

A:

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

So your MY_LIMIT won't get interpreted when set in MemoryLimit.
Also MemoryLimit is deprecated, use MemoryMax= instead. [source][2]
So what you should set is: MemoryMax=1024M

