[systemd-devel] question about system reboot and shutdown

Jérémy Rosen jeremy.rosen at smile.fr
Wed Aug 9 07:47:54 UTC 2017


Hi
> I have no problem with changing some code in microupsd so it behave in certain
> way. It is handling SIGTERM and other signals if needed.
> The problem for me is that SIGTERM is send to process during system reboot and
> system halt - so I need to differentiate between the two.
SIGTERM is sent, by default, to all processes early during shutdown.

You need to disable DefaultDependencies for your process to not recieve
the default SIGTERM and then trigger it yourself with the WandedBy that
was already described...


Your daemon is a late-shutdown daemon, not a normal daemon. I think
that deactivating default dependencies in this case makes sense.

I strongly advice carefully reading the section on default dependencies in
systemd.service, though... You will deactivate all default dependencies and
you probably don't want that. You'll need to manually reactivate the other
default dependencies

BR
Jérémy
> If you can suggest me  a way, maybe with some example I will change my code.
>
> Best Regards
> Marek
>
>> Normally services are given a certain amount of time to stop after SIGTERM
>> (or whatever KillSignal was set, or whatever ExecStop command was
>> specified). Even if microupsd doesn't handle SIGTERM nicely (which I'd call
>> a bug), it's possible to add some... arbitrary delays.
>>
>> Units are stopped due to having automatic Conflicts=shutdown.target, if I
>> remember correctly. I'm not sure if disabling that default dependency is a
>> good approach though...
>>
>> This time I can't think of a good combination that'd solve both problems
>> without introducing some ugly race conditions...
>>
>> On Tue, Aug 8, 2017, 21:46 Marek Floriańczyk <marek.florianczyk at gmail.com>
>>
>> wrote:
>>> Dnia wtorek, 8 sierpnia 2017 21:04:18 CEST Andrei Borzenkov pisze:
>>>> 08.08.2017 17:03, Marek Floriańczyk пишет:
>>>>> What would be the proper way to distinguish between system is going
>>> down
>>>
>>>>> for reboot and for shutdown ?
>>>> Straightforward way is to make your service WantedBy poweroff.target and
>>>> halt.target. You can then have second service WantedBy reboot.target and
>>>> kexec.target. They may even call the same binary (script) but with
>>>> different arguments.
>>> Thanks for answer,
>>>
>>> So, my binary "microupsd" is started  by /etc/init.d/microups at the boot
>>> time
>>> to monitor power input, battery status etc.
>>> During system halt I need to send SIGUSR1 to this "microupsd" process at
>>> which
>>> it will send command to microups device, moreover  I would like to give it
>>> some time (like 1-2 seconds) to accomplish the transmission.
>>> I don't need to send anything in case of reboot.
>>>
>>> Should I prepare some script that sends SIGUSR1 to "microupsd" process and
>>> then sleeps for 2 seconds and set it as WantedBy poweroff.target and
>>> halt.target ?
>>>
>>> How can I be sure that this script will be called before "microupsd" is
>>> actually killed during system shutdown ?
>>>
>>> Best Regards
>>> Marek
>>>
>>> _______________________________________________
>>> 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

-- 
Logo <http://www.smile.fr/>

20 rue des Jardins
92600 Asnières-sur-Seine
www.smile.fr <http://www.smile.fr/> 	
*Jérémy ROSEN*
Architecte technique
Email : jeremy.rosen at smile.fr <mailto:jeremy.rosen at smile.fr>
Tel : +33141402967

Facebook <https://www.facebook.com/smileopensource> Google%2B 
<http://fr.slideshare.net/SmileOpenSource/presentations> LinkedIn 
<https://www.linkedin.com/company/smile> Twitter 
<https://twitter.com/GroupeSmile>


bandeaux_mail 
<http://www.smile.fr/Offres-services/Offres/Ingenierie?utm_source=signature&utm_medium=email&utm_campaign=signature>

eco Pour la planète, n'imprimez ce mail que si c'est nécessaire
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20170809/c0725662/attachment.html>


More information about the systemd-devel mailing list