I would like to migrate some OpenRC init script to systemd but I think that it is general problem of environment variables handling in systemd.
Original OpenRC files
There is a file e.g.
/etc/conf.d/fooservice with contents
# value of FOO variable # you can override default value by uncomenting this line # FOO=value1 # value of BAR variable BAR=value2
In original startup script
/etc/init.d/fooservice, there was
So the result was
Migrated systemd files
Now I have systemd service file
/usr/lib/systemd/system/fooservice.service, that contains
[Service] EnvironmentFile=/etc/conf.d/fooservice ExecStart=/usr/bin/fooservice $FOO $BAR
But there is a problem that
$FOO is not initialized to
Is there a way to tell systemd to use default value if there is no value in environment file? Is there a way to use intermediate environment file with default values or multiple chained Environment files?
This is not good way.
/etc/conf.d/fooservice file can be incompatible because it is "shell script" and systemd expects "environment file". In basic value assignment, it seems similar, but it is not the same thing.
Prefered solution for this by Gentoo is to put everything into service file and configuration file of the service and not to use additional
WORKING BUT NOT PREFERED SOLUTION:
Use this only as fast hack to run OpenRC service as systemd one.
/usr/lib/systemd/system/fooservice.service now contains
[Service] Environment="FOO=default_foo_value" Environment="BAR=default_bar_value" EnvironmentFile=/etc/conf.d/fooservice ExecStart=/usr/bin/fooservice $FOO $BAR