Hello,

Most projects handle this using a CLI argument, like --foreground or
--no-daemonize or something like that. Then in the systemd unit file, you'd
pass that CLI argument on the ExecStart line.

Best,
Adrian

On Mon, Jun 30, 2025, 06:26 Stef Bon <stef...@gmail.com> wrote:

> Hi,
>
> it's important for a program to detect it has been started by systemd.
> For example it does not have to fork since it has already been forked.
>
> I've written a test script, which calls env, and there are a few
> unique environment variables which are an indication it has been
> started by systemd: SYSTEMD_EXEC_PID and INVOCATION_ID.
>
> Is it a good way to test these environment vars (to detect started by
> systemd) or is there a better way?
>
> S. Bon
>

Reply via email to