[systemd-devel] Hand when using systemctl in unit files

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Thu Jul 28 01:38:44 PDT 2011


On 07/28/2011 08:37 AM, Warpme wrote:
> On 7/27/11 11:19 PM, Kok, Auke-jan H wrote:
>> 2011/7/27 Warpme<warpme at o2.pl>:
>>> Hi,
>>> I really like systemd concept.
>>> I want to use systemctl to control other unit from given unit.
>>> I'm on systemd-29
>>>
>>> Example:
>>>
>>> unit1:
>>> ExecStartPre=systemctl restart service2.service
>>>
>>> Issuing "systemctl restart unit1.service" gives hang on this command
>>> (I have
>>> to terminate manually systemctl)
>>> While I don't know is this by design behavior or not - I think it
>>> would be
>>> nice to have possibility to control units from other units
>> Can you explain why you need this? This sounds like you have a broken
>> design to begin with, and you're masking it with something that is
>> even more broken. Please try to use more arguments than "nice to have"
>> but give a real example.
>>
>> Auke
>>
> Hi,
> Thx for replay.
> Indeed probably my approach is suboptimal but currently I can't find
> better solution.
Hi,
to give a more concrete example: proc2=tracd using proc1=postgresql as a
backend requires a restart after the database daemon is restarted,
because it doesn't reopen the connection. A really ugly and painful
example seen in the wild.

A proper fix would be to make proc2 fail after a few attempts without
successful communication. Then proc2 could be reconfigured to
Restart=always and changed from Wants=proc1 to Requires=proc1.
I think that this would be more robust than delayed restarting that you
describe.

> Usecase if following:
> 
> My server has some services which are servers for other services.
> e.g. proc1 is required to operate for proc2. Abort of proc1 requires
> ordered restart of proc2 with given delay.
> 
> Currently my implementation is quite dumb:
> -I'm terminating proc2 via proc1's ExecStartPost killall proc2
> -proc2 have ExecStartPre with sleep <delay>
> Issue with such approach is that I have always <delay> when proc2 starts.

You can use more than one ExecStartPost. E.g.
  ExecStartPost=sleep 10
  ExecStartPost=systemctl try-restart proc2
This way you remove the unnecessary delay when starting proc2.

Zbyszek


More information about the systemd-devel mailing list