Is it possible to get the exit code of a previous run of systemd's process on re-run?
That is, suppose I have the following C++ code:
int main(int argc, char **argv)
{
if (argc > 2)
{
std::string opt = argv[1];
std::string val = argv[2];
if (arg == "--exit-code" && val == "42")
{
std::cout << "Previous exit code is: " << val << std::endl;
return 0;
}
}
std::cout << "This is the first run" << std::endl;
return 42;
}
And systemd's configuration:
[Unit]
Description=Fails first then succeeds
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
ExecStart=./a.out
Restart=on-failure # --exit-code <-- how to pass the previous exit code here?
[Install]
WantedBy=multi-user.target
How does one get the exit code of the previous run and pass it to subsequent attempts of the same process?