Question
My C++ application runs as a systemd service. I need to configure it using environment variables, and be able to reload the value of the variables during runtime without restarting the application.
I created a .conf file and used the Environment directive in it, and I execute daemon-reload after changing the value in the .conf file. But the service does not notice the change.
I know about the systemctl reload command, but I don't know what to set in the ExecReload directive.
C++ application code
#include <unistd.h>
#include <fstream>
using namespace std;
int main(int argc, char** argv)
{
while (true)
{
char * cp = getenv("BAR");
string s = "";
if (cp)
s = (string) cp;
fstream fs;
fs.open("/tmp/foo", ios_base::app);
fs << s << endl;
fs.close();
sleep(1);
}
return 0;
}
Service description
Path: /etc/systemd/system/foo.service
[Unit]
Description=Testing configuration reloading
[Service]
ExecStart=/home/user/foo_application
Type=simple
[Install]
WantedBy=default.target
Service configuration file
Path: /etc/systemd/system/foo.service.d/foo.conf
[Service]
Environment="BAR=2"
My previous (re)search
https://serverfault.com/a/590732/379539
https://coreos.com/os/docs/latest/using-environment-variables-in-systemd-units.html
https://www.freedesktop.org/software/systemd/man/systemctl.html