[systemd-devel] Help with making socket activation work.

Stef Bon stefbon at gmail.com
Fri Jun 27 14:50:19 UTC 2025


Op vr 27 jun 2025 om 15:23 schreef Andrei Borzenkov <arvidjaar at gmail.com>:

>

>
> How do you expect this environment variable to change? It was set when
> systemd invoked your program. How systemd is supposed to change the
> value of this variable inside already started process? How systemd is
> supposed to predict the value of PID before starting your command?

Well, what I expected is that the service manager was notified that
the pid of the mainprocess has changed. See in systemd.service:

Type = forking .....This is the behavior of traditional UNIX services.
If this setting is used, it is recommended to also use the PIDFile=
option, so that systemd can reliably identify the main process of the
service. The manager will proceed with starting follow-up units after
the parent process exits.

So I used a pidfile, but that did not lead to sd_listen_fds to providing the fd.

In the same manpage I read that Type = notify may offer the
functionality 'm looking for.

See in man sd_notify:

"Notify service manager about start-up completion and other service
status changes"

and

MAINPID=…

Change the main process ID (PID) of the service. This is especially
useful in the case where the real main process is not directly forked
off by the service manager. Example: "MAINPID=4711".

Ok. The environment variable won't change when calling sd_notify.
I understand that. But how can I make socket activation  work after
the main process osns system has forked? Is it required to fork
anyway....

S. Bon


More information about the systemd-devel mailing list