[systemd-devel] [solved] howto handle one time shutdown programs

Andrei Borzenkov arvidjaar at gmail.com
Wed Jul 1 05:15:26 PDT 2015


On Wed, Jul 1, 2015 at 2:30 PM, Andreas Buschmann <buschman at tech.net.de> wrote:
> Hello Andrei,
>
> On Tue 30-Jun-2015 15:45 CEST Andrei Borzenkov writes:
>
>> On Tue, Jun 30, 2015 at 2:35 PM, Andreas Buschmann <buschman at tech.net.de> wrote:
>>> Hello Johannes,
>>>
>>> On Thu 25-Jun-2015 20:09 CEST Johannes Ernst writes:
>>>
>>>>> On Jun 25, 2015, at 7:57, Andreas Buschmann <buschman at tech.net.de> wrote:
>>>>>
>>>>> I am writing a systemd .service file to handle NVDIMMs.
>>>>>
>>>>> - start
>>>>> - stop
>>>>> - reload
>>>>> all work
>>>>>
>>>>> The problem child is "restart".
>>>>> Restart is internally implemented as stop followed by start.
>>>>>
>>>>> The problem is, that stop calls a program which does something to the
>>>>> NVDIMM hardware.
>>>>> After that no further access to the NVDIMMs is possible before the next
>>>>> reboot of the server.
>>>>>
>>>>> How should I handle that sort of logic with systemd?
>>>>
>>>> How is that different from the user executing:
>>>>
>>>> systemctl start your.service
>>>> systemctl stop your.service
>>>> systemctl start your.service
>>>>
>>>> without reboot?
>>>
>>> It is not different, but that sequence can not work with my
>>> implementation of the service.
>>>
>>> systemctl stop your.service
>>> can only be called once.
>>>
>>> My stop script shuts down the hardware.
>>> Think like parking a hard disk.
>>>
>>>
>>> I am not sure on how to do that the systemd way.
>>>
>>> I have no problem with spliting the service up into
>>> myservice1 and myservice2, but than myservice2 has to be called exactly
>>> once before a shutdown or a reboot completes.
>>>
>>
>> You could place separate shutdown hook in
>> /usr/lib/systemd/system-shutdown/. Note that all executables there are
>> run concurrently in case it matters.
>
> It works.
> But only if everything you need is in the root filesystem.
>
> It would be helpful if the man page for
>   man systemd-shutdown
> would be extended by:
>
> -------------------------------------------------------------------------------
> The executables in /usr/lib/systemd/system-shutdown only have access to
> the root filesystem (/).
> All other filesystems are not mounted any more.
> The remaining mounts are:
> /proc
> /sys
> /dev
>
> For debugging these scripts redirect your output to /dev/ttyS0 or
> /dev/ttyS1 and log that output over a serial console switch.
> -------------------------------------------------------------------------------
>

Well, a paragraph before contains: "Before shutting down, this binary
will try to unmount all remaining file systems, disable all remaining
swap devices, detach all remaining storage devices and kill all
remaining processes.". But if you think it is not clear enough, submit
pull request (or at least patch here :) )


More information about the systemd-devel mailing list