I'm working on a systemd.service file which should eject your CD/DVD and stop to display a
message so the user can react and close his cd-tray.

This was my first draft:

[Unit]
Description=LiveMedia Eject Service

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/etc/manjaro/ejectcd

[Install]
WantedBy=multi-user.target

Lennart gave me than some tips to make my script better:

Hmm, service are not really supposed to be interactive in the systemd world, but you can still make this work, but should do that only for early boot and late shutdown services where you are sufficiently sure that nobody else will interfere with your console IO. Simply use StandardInput=tty-force in the [Service] section which
should do the trick.

Testing it a little more I came to this:

I added what you suggested like this:

[Unit]
Description=LiveMedia Eject Service

[Service]
StandardInput=tty-force
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/etc/manjaro/ejectcd

[Install]
WantedBy=multi-user.target

I can see the output now. I attached a screenshot of my virtualbox.
In my bash-script I added a "read" cmd so that script would wait for
user-interactivity.

Somehow systemd ends my service file so I never be able to react.
Also as you can see in my screenshot at least 15 services get
stopped after my service got killed.
Maybe I've to add it to another category and not to multi-user.target

Lennart answerd me later:

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

Now my script seems to be more properly written.
I see that message only some seconds but still have no option
to interact or make my virtualbox machine stop and wait for me hitting the "Enter"-key.

Does the community has a clue for me?

kind regards

Phil


#!/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
fi
[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

<<attachment: shutdown-systemd.png>>

_______________________________________________
systemd-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to