I am trying out systemd script along in Docker environment.
Consider this:
command mentioned in ExecStartPre updating environment file and ExecStart actually making use of environment variable mentioned in env. file.? (all in the same systemd file).
like this:
[Unit]
Description=test service
Before=memcached.service
[Service]
Type=oneshot
EnvironmentFile=-/etc/sysconfig/testfile
ExecStartPre=/usr/local/bin/update_sysconfig_testfile.sh
ExecStart=/usr/bin/testmebinary $VOLUMES
[Install]
WantedBy=multi-user.target
Here, $VOLUMES is defined inside testfile and it is updated by update_sysconfig_testfile.sh script.
Will systemd aware about the change made by ExecStartPre (or) it just loads whatever value in testfile?
If there is any better approach, please share.
ExecStartPre= , ExecStartPost= Additional commands that are executed before or after the command in ExecStart= , respectively. Syntax is the same as for ExecStart= , except that multiple command lines are allowed and the commands are executed one after the other, serially.
Systemd Files and Paths Unit files are stored in the /usr/lib/systemd directory and its subdirectories, while the /etc/systemd/ directory and its subdirectories contain symbolic links to the unit files necessary to the local configuration of the host. We recommend putting your scripts in /etc/systemd/system .
The ExecStop setting is optional and is used to communicate with the service for a clean termination. The process specified by ExecStop will run in case the service crashes.
As an alternate approach, consider a script like with_testfile_vars
doing the following:
#!/bin/sh
export foo=bar # export the same calculated values you would otherwise write to the file
export baz=qux
exec "$@" # then invoke your "real" program
...with a service file using that wrapper:
[Unit]
Description=test service
Before=memcached.service
[Service]
Type=oneshot
ExecStart=/usr/local/with_testfile_vars /usr/bin/testmebinary $VOLUMES
[Install]
WantedBy=multi-user.target
No EnvironmentFile
needed at all, no ordering dependencies around how exactly it's interpreted, no concerns about how systemd's parsing differs from a shell's, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With