[systemd-devel] query on systemd services ordering for daemonize process

Mantas Mikulėnas grawity at gmail.com
Fri Aug 3 18:09:38 UTC 2018


On Fri, Aug 3, 2018 at 8:57 PM Rajesh Kumar <myemail.rajeshkumar at gmail.com>
wrote:

> Hi All,
>
>
>
> We are facing issue in on system services.
>
>
>
> Problem statement:
>
> We have two process P1 and P2, both are getting daemonize using fork()
> command and parent exits immediately after fork().
>
> We want process P2 to start once P1 is initialized successfully (means P2
> should start when P1 is listening on particular socket and in ready state
> to handle request)
>
>
>
> [...]
>
>
>
> Our processes P1 and P2 which are started through service file are also
> getting demonized using fork(). And, we have used sd_notify() mechanisum to
> notify systemd once process initialization completes.
>

With Type=forking, the service is considered "ready" when the parent exits.
So if you use Type=forking, make sure the parent *doesn't* exit until the
child has fully initialized. (For example, use a pipe or an eventfd between
child and parent.)

But with Type=notify, there is no reason to perform daemonization at all.
(Could almost say that daemonization isn't even *supported* for this
type...) If you use Type=notify, just do everything directly in the parent.

-- 
Mantas Mikulėnas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20180803/d269e828/attachment-0001.html>


More information about the systemd-devel mailing list