[systemd-devel] [script] Eject CD before shutdown

Philip Müller philm at manjaro.org
Thu Sep 13 15:14:03 PDT 2012


So, seems to work. I attached my current scripts and two picutes with 
error messages.
Also I added now *read -t 30* and fixed hanging by pressing the 
Enter-key. Is there any way
to hide those error messages (seems the system still tries to read from 
CD after it got ejected),
so my message gets displayed clean? Maybe there is a way to get it cleaner.

Mixed feelings about this one ...

Phil

Am 13.09.2012 20:01, schrieb Philip Müller:
> Sorry, that was my fault. As suggested it works.
> Thx again for your help.
>
> Phil
>
> Am 13.09.2012 18:19, schrieb Lennart Poettering:
>> On Thu, 13.09.12 18:04, Philip Müller (philm at manjaro.org) wrote:
>>
>> [...]
>>
>>> All operations are timed out in systemd by default. You can turn this
>>> off by pasing TimeoutSec=0.
>>>
>>> However, I'd probably recommend you to define your service a bit
>>> differently. Add this to [Unit]:
>>>
>>>          DefaultDependencies=no
>>>          After=shutdown.target
>>>          Before=final.target
>>>
>>> And just use ExecStart= to spawn your code, drop the ExecStop=.
>>>
>>> And then pull that in from final.target.
>>>
>>> In case you wonder: the charts at the end of this man page might
>>> explain better where a service like that is positioned:
>>>
>>> http://www.freedesktop.org/software/systemd/man/bootup.html
>> [...]
>>
>>> [Unit]
>>> Description=LiveMedia Eject Service
>>> Before=unmount.target
>>> After=shutdown.target
>>> DefaultDependencies=no
>>>
>>> [Service]
>>> Type=oneshot
>>> ExecStart=/etc/manjaro/ejectcd
>>> StandardInput=tty-force
>>> RemainAfterExit=yes
>>>
>>> [Install]
>>> WantedBy=shutdown.target
>> Use "Before=final.target" as I suggested, not "Before=unmount.target"
>> (there is no unmount.target anyway, only umount.target).
>>
>> Lennart
>>
>
>
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20120914/dee31082/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shutdown-eject-systemd.png
Type: image/png
Size: 13393 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20120914/dee31082/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shutdown-eject-systemd-error.png
Type: image/png
Size: 18910 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20120914/dee31082/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shutdown-eject-systemd-error2.png
Type: image/png
Size: 23725 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20120914/dee31082/attachment-0005.png>
-------------- next part --------------
[Unit]
Description=LiveMedia Eject Service
Before=final.target
After=shutdown.target
DefaultDependencies=no

[Service]
Type=oneshot
ExecStart=/etc/manjaro/ejectcd
StandardInput=tty-force
StandardOutput=inherit
StandardError=inherit

[Install]
WantedBy=shutdown.target

-------------- next part --------------
#!/bin/sh

if [ -n "$(blkid -L %MISO_LABEL% |grep -Eo 'sr|cd')" ]; then
    eject -m /dev/disk/by-label/%MISO_LABEL%

    echo -e "\033[31m"
    echo -en "Remove the boot medium, close the tray (if any), "
    echo -en "then press ENTER."
    echo -e "\033[0m"

    read -t 30
fi


More information about the systemd-devel mailing list