<div dir="auto"><div>No, it really shouldn't detect "started by systemd" at all. These are several independent things and you shouldn't mix them all together.</div><div dir="auto"><br></div><div dir="auto">Regarding startup, systemd services have several distinct Type= settings with different expectations and the program has no way to reliably detect which one is configured. And other init systems exist which also support handling non-forking services. For example, OpenRC can just as well start services that don't fork/demonize, and it even supports the systemd-style "Type=notify" nowadays.</div><div dir="auto"><br></div><div dir="auto">So you shouldn't have a "systemd" mode, but rather have a "--(no-)daemon" or "--(no-)fork" or "--foreground" option that describes the behavior expected.</div><div dir="auto"><br></div><div dir="auto">If Type=notify is offered, this can be detected from the specific $NOTIFY_SOCKET, again separately from which init system is offering it.</div><div dir="auto"><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Mon, Jun 30, 2025, 13:26 Stef Bon <<a href="mailto:stefbon@gmail.com" target="_blank" rel="noreferrer">stefbon@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
it's important for a program to detect it has been started by systemd.<br>
For example it does not have to fork since it has already been forked.<br>
<br>
I've written a test script, which calls env, and there are a few<br>
unique environment variables which are an indication it has been<br>
started by systemd: SYSTEMD_EXEC_PID and INVOCATION_ID.<br>
<br>
Is it a good way to test these environment vars (to detect started by<br>
systemd) or is there a better way?<br>
<br>
S. Bon<br>
</blockquote></div></div></div>