[systemd-devel] Query regarding NOTIFY_SOCKET

Alessandro Puccetti alessandro at kinvolk.io
Tue Nov 8 14:17:32 UTC 2016


I do not understand the relation between your question and service
dependencies (e.g. Requires= and After= directives).

Second is started when all the required services are ready, because of
"Requires=one.service" second will be started after one's status is READY.
Because one is Type=notify this state is not reached until one executes
sd_notify(...).


On Tue, Nov 8, 2016 at 2:59 PM, Raghavendra. H. R <raghuhr84 at gmail.com>
wrote:

> Just one last question.
> Does systemd notifies other services based on this notification ?
>

In this case are the services to notify systemd not vice-versa and
notifications are accepted  by systemd for a specific service the depending
on the value of Type= and NotifyAccess=.

>
> I have 2 service files, application in one service file sends notification
> using sd_notify does systemd starts another service file.
>
> one.service
> ========
> *[Unit]*
> *Description=Sd_notify example*
> *Before=second.service*
>
> *[Service]*
> *Type=notify*
> *ExecStart=/etc/Myapp*
>
As I said before you may need to add "NotifyAccess=all" here.

>
> *[Install]*
> *WantedBy=multi-user.target*
>
> second.service
> ==========
> *[Unit]*
> *Description=Second sd_notify example*
> *Requires=**one.service*
> *After=one.service*
>
> *[Service]*
> *ExecStart=/etc/SecondApp*
>
> *[Install]*
> *WantedBy=multi-user.target*
>
>
>
> *Regards,*
> *Raghavendra H R*
>
> --
> Regards,
>
> Raghavendra. H. R
> (Raghu)
>
> On Tue, Nov 8, 2016 at 7:14 PM, Alessandro Puccetti <alessandro at kinvolk.io
> > wrote:
>
>>
>>
>> On Tue, Nov 8, 2016 at 2:28 PM, Raghavendra. H. R <raghuhr84 at gmail.com>
>> wrote:
>>
>>> Hi Tomasz,
>>>
>>> Thanks for pointing out the mistake. I actually missed the line
>>> "Type=notify" in the mail.
>>> I found the journalctl logs and from that I can make out the real
>>> problem is not about NOTIFY_SOCKET. It is about child process in my
>>> application *Myapp.*
>>>
>>> Below given is my Service file.
>>>
>>> *[Unit]*
>>> *Description=Sd_notify example*
>>>
>>> *[Service]*
>>> *Type=notify*
>>> *ExecStart=/etc/Myapp*
>>>
>>> *[Install]*
>>> *WantedBy=multi-user.target*
>>>
>>> And in Myapp code my application is using fork() to create a child
>>> process. Because of which notification is not working correctly.
>>>
>>> This is error log
>>>
>>>
>>> *localhost systemd[1]: sd_example.service: Got notification message from
>>> PID 1270, but reception only permitted for main PID 1106*
>>>
>>> Is there any way from which we can force sd_notify to make use of Parent
>>> PID instead of child process. My sd_notify is after the fork() call, so I
>>> doubt sd_notify is called from child process.
>>>
>>> MyApp code snippet
>>>
>>>         *int count = 0;*
>>> *        cpid = fork();*
>>>
>>> *        if (cpid < 0)*
>>> *        {*
>>> *            printf("vfork failed.");*
>>> *        }*
>>>
>>> *        if (cpid == 0)*
>>> *        {*
>>> *            count++;*
>>> *            if(count == 1)*
>>> * {*
>>>
>> This notificaiton is done by the child process, but notificaitons are
>> accepted by default only form the main process. Read doc aobut
>> "NotifyAccess=". https://www.freedesktop.org/software/system
>> d/man/systemd.service.html#NotifyAccess=
>>
>>> * ret = sd_notify(0, "READY=1");*
>>> * printf("Return value = %d \n");*
>>> * }*
>>> * }*
>>>
>>>
>>> Regards,
>>> Raghavendra H R
>>>
>>> --
>>> Regards,
>>>
>>> Raghavendra. H. R
>>> (Raghu)
>>>
>>> On Tue, Nov 8, 2016 at 5:15 PM, Tomasz Torcz <tomek at pipebreaker.pl>
>>> wrote:
>>>
>>>> On Tue, Nov 08, 2016 at 05:01:59PM +0530, Raghavendra. H. R wrote:
>>>> > Hi All,
>>>> >
>>>> > I'm a newbie in Systemd init system and I'm exploring sd_notify which
>>>> is
>>>> > basically used for notification purpose in SystemD.
>>>>
>>>>   It is written “systemd” (all lowercase).
>>>>
>>>> > I have created one unit file which is of type "notify" and in my
>>>> > application I have written sd_notify(0, "READY=1"); from which
>>>> SystemD can
>>>> > be notified that my process in totally up and running.
>>>> >
>>>> > Below given is my Service file.
>>>> >
>>>> > *[Unit]*
>>>> > *Description=Sd_notify example*
>>>> >
>>>> > *[Service]*
>>>> > *ExecStart=/etc/Myapp*
>>>>
>>>>
>>>>   This is not 'unit of type notify'. This is unit of type 'simple'.
>>>> Please read "man systemd.service" and paragraph Type= and choose
>>>> correctly.
>>>>
>>>>
>>>> > Need help in understanding what value should be set in the environment
>>>> > varaible NOTIFY_SOCKET.
>>>> > But there's no much information/documentation available on
>>>> NOTIFY_SOCKET.
>>>>
>>>>   NOTIFY_SOCKET is filled-in by systemd and it is available when you
>>>> correctly defined unit type.  If you want to check it's value, you can
>>>> user getenv() inside you program and print the value.
>>>>   I think amount of documentation about NOTIFY_SOCKET is enough, if
>>>> you think there's something specific missing, let us know.
>>>>
>>>>
>>>> --
>>>> Tomasz Torcz               "Never underestimate the bandwidth of a
>>>> station
>>>> xmpp: zdzichubg at chrome.pl    wagon filled with backup tapes." -- Jim
>>>> Gray
>>>>
>>>> _______________________________________________
>>>> systemd-devel mailing list
>>>> systemd-devel at lists.freedesktop.org
>>>> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>>>>
>>>
>>>
>>> _______________________________________________
>>> systemd-devel mailing list
>>> systemd-devel at lists.freedesktop.org
>>> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>>>
>>>
>>
>>
>> --
>>
>> Alessandro Puccetti
>>
>
>


-- 

Alessandro Puccetti
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20161108/8a9dacce/attachment-0001.html>


More information about the systemd-devel mailing list