Hello,
I have a question regarding a creation of systemd service unit.
I’m getting desperate with this project and hope that there is someone here who can help me a bit.
I actually want to run a script for an Xfce project when I click on the shutdown button before the system is no longer able to do so. This is a small 3 second sound file.
All solutions I found on the internet don’t work unfortunately.
Here is my unit and the commands I used to activate it.
Hello, thank you for your participation.
I forgot that I have installed the SOX package which runs this play command. But I also tried canberra-gtk-play and even played with vlc. It all leads to the same result.
Another unit is the one that was marked as working in the XFCE forum but has not been allowed for a long time because the Boolean value “True” does not work anymore. Link: https://forum.xfce.org/viewtopic.php?pid=64370#p64370
Another method to execute a script before shutdown is described here and I tried that too.
Script created and made executable with the content:
sh -c "play -q /home/jag/Downloads/Smooth/stereo/desktop-logout.oga"
I have no success with this either.
Now I have a suspicion where I hope that someone can confirm it; Can it be that Pipewire only works in Runlevel5 and no longer in Runlevel4?
Unfortunately no success. But it must be possible. I tinker there now already 2 days at it. It must be possible to execute a script (e.g. backup) or unit before the system shuts down.
Which would suggest that it may be easier to have the service run on startup and remain on exit till shutdown. So the unit would look something like this:
So far I was already true myself! Nevertheless, I have again worked through the instructions from your link.
Unfortunately, this does not work. But the service file seems to be correct.
First of all I would like to thank you again for interest!
In /usr/schare/Sounds/… there are already files.
Basically the unit and the script works.
With both I do not get an error code.
Script with Geany tested and Unit with command(s).
jag@fedora:~$ /usr/bin/aplay /usr/share/sounds/purple/logout.wav
Wiedergabe: WAVE '/usr/share/sounds/purple/logout.wav' : Signed 16 bit Little Endian, Rate: 22050 Hz, stereo
jag@fedora:~$
jag@fedora:~$ sudo service sound-shutdown.service start
[sudo] Passwort für jag:
Redirecting to /bin/systemctl start sound-shutdown.service
jag@fedora:~$
The problem must be with Pipewire because I also see with aplay in the task manager that Pipewire is started briefly. But there is still nothing to hear.
Apparently Pipewire hinders the process of the script.
The installation of moc as a further sound server has unfortunately also failed. I have no more nerves to deal with it!
I am running out of ideas.
How can I get back to ALSA? Is there an official manual? Maybe the crackling and popping and the interruptions when starting the browser will stop?
Yes, sure I can live with it but even if an idiot system like Windows can do that, then questions arise.
I just wanted to activate the system sounds and came up with the idea of maybe creating a current article instead of the user having to search for everything from outdated and perhaps no longer applicable information.
Everything works except for the sound at shutdown.
I have a sound at logon and logoff, in the system and at reboot but not at shutdown and that annoys me. Despite intensive efforts I have not found a solution for Fedora and OpenSuse. So the error is not specific to Fedora!
Back to the topic.
What is the fault now SystemD or Pipewire?
How, where and with what info should we create a bug report?
[/home/gregory]$ systemctl --user status pipewire.service
● pipewire.service - PipeWire Multimedia Service
Loaded: loaded (/usr/lib/systemd/user/pipewire.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2022-10-30 14:20:31 CDT; 7h ago
TriggeredBy: ● pipewire.socket
Main PID: 1866 (pipewire)
Tasks: 2 (limit: 18459)
Memory: 7.8M
CPU: 2min 19.705s
CGroup: /user.slice/user-1000.slice/user@1000.service/session.slice/pipewire.service
└─ 1866 /usr/bin/pipewire
Oct 30 14:20:31 hal9000 systemd[1624]: Started PipeWire Multimedia Service.
So if you need a sound to play before the Pipewire service stops, you probably need to
Make your sound-shutdown.service a user service by placing it under ~/.config/systemd/user and running systemctl --user enable --now sound-shutdown.service.
Place an ordering requirement of After=pipewire.service on the sound-shutdown.service so that it is started after Pipewire starts and stopped before Pipewire stops (yes, the ordering requirements have the reverse meaning on shutdown).
I don’t know for sure, but the above would be my guess. Good luck!
P.S. It also looks like user services are normally “WantedBy” default.target.
Thanks for your tip! With this I have already come one step further.
When I shut down the system takes much longer than normal so probably a process is working until it is killed.
Things I have noticed:
Hyphens in service names are not a good idea. Changed the name from sound-shutdown.service to soundshutdown.service.
If I disable the service file it probably works obviously since the sound file is played.
But unfortunately I still have an error message that I don’t quite understand. It seems that another service is requested which is not active. Apparently the file system is already unmounted.
Summary
systemctl status /home/jag/.config/systemd/user/soundshutdown.service
Unit home-jag-.config-systemd-user-soundshutdown.service.mount could not be found.
I have then searched:
Summary
systemctl list-units --all | grep mount
● boot.automount not-found inactive dead boot.automount
proc-sys-fs-binfmt_misc.automount loaded active waiting Arbitrary Executable File Formats File System Automount Point
-.mount loaded active mounted Root Mount
boot-efi.mount loaded active mounted /boot/efi
● boot.mount not-found inactive dead boot.mount
dev-hugepages.mount loaded active mounted Huge Pages File System
dev-mqueue.mount loaded active mounted POSIX Message Queue File System
home.mount loaded active mounted /home
proc-fs-nfsd.mount loaded inactive dead NFSD configuration filesystem
proc-sys-fs-binfmt_misc.mount loaded inactive dead Arbitrary Executable File Formats File System
run-media-jag-550c6531\x2dbbe2\x2d4ca3\x2d8326\x2d1a16bc4a1049.mount loaded active mounted /run/media/jag/550c6531-bbe2-4ca3-8326-1a16bc4a1049
run-user-1000-doc.mount loaded active mounted /run/user/1000/doc
run-user-1000.mount loaded active mounted /run/user/1000
sys-fs-fuse-connections.mount loaded active mounted FUSE Control File System
sys-kernel-config.mount loaded active mounted Kernel Configuration File System
sys-kernel-debug.mount loaded active mounted Kernel Debug File System
sys-kernel-tracing.mount loaded active mounted Kernel Trace File System
● sysroot.mount not-found inactive dead sysroot.mount
tmp.mount loaded active mounted Temporary Directory /tmp
var-lib-nfs-rpc_pipefs.mount loaded active mounted RPC Pipe File System
● var.mount not-found inactive dead var.mount
dracut-mount.service loaded inactive dead dracut mount hook
dracut-pre-mount.service loaded inactive dead dracut pre-mount hook
nfs-mountd.service loaded inactive dead NFS Mount Daemon
ostree-remount.service loaded inactive dead OSTree Remount OS/ Bind Mounts
systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
umount.target
For another push in the right direction I would be grateful.
Yeah, I forgot about that. Hyphens in the service name (-) can be translated into forward slashes (/). But I thought that was only for “mount” units. I’m quite certain that I’ve seen hyphens in “service” unit names before.
As for the Before=... and After=... lines, those need to be in the [Unit] section of the service file, not the [Service] section. BTW, there are man pages for these things (man systemd.unit and man systemd.service) but they are not light reading.
As for something being unmounted, about the only thing I could think of there is that maybe the /home filesystem is being unmounted before your service runs. My suggestion would be to move your sound file to /opt which is normally part of the root partition. Also, if you want to make this sound play for all users instead of just your account, you might move it under /etc/systemd/user instead of ~/.config/systemd/user.
That’s about all I can come up with off-hand. But let us know if these changes don’t fix the problem.
I don’t think that would be needed in this case. Services normally only need that if they are trying to run very early in the startup process or very late in the shutdown process. The user wants this service to start after pipewire starts and stop before pipewire stops, so that would not be a low-level service that would want/need DefaultDependencies=no.
WHO UID USER PID COMM WHAT WHY MODE
ModemManager 0 root 864 ModemManager sleep ModemManager needs to reset devices delay
NetworkManager 0 root 1052 NetworkManager sleep NetworkManager needs to turn off networks delay
UPower 0 root 1769 upowerd sleep Pause device polling delay
xfce4-power-manager 1000 jag 1766 xfce4-power-man handle-suspend-key:handle-hibernate-key:handle-lid-switch xfce4-power-manager handles these events block
4 inhibitors listed.
I see that the corresponding service is blocked.
This confirms that I should actually manage this graphically with an autostart entry (see input post) if this service would not be blocked!
Indirectly, this is for me a confirmation that this is not to be done even with a service unit.
So the guys from XFCE have a bug or whatever in the system. I think I’ll step on their feet so that we do not continue to turn in circles and waste time.
Or what do you think?
Yes, according to this website logind is replaced by the xfce-power-manager. https://docs.xfce.org/xfce/xfce4-power-manager/4.16/faq
But I can’t find the right file to make a change.
This will block systemd. It seems to me like a stopgap solution from XFCE to avoid a bigger problem.