abendbrot
abendbrot copied to clipboard
Standalone Version of RetroArch like in Lakka
Lakka made a few adjustments for running RetroArch standalone.
Init-Files
Auto-Login with root on tty1
[Unit] Description=Getty on %I Documentation=man:agetty(8) man:systemd-getty-generator(8) Documentation=http://0pointer.de/blog/projects/serial-console.html After=systemd-user-sessions.service plymouth-quit-wait.service
Before=getty.target IgnoreOnIsolate=yes
ConditionPathExists=/dev/tty0
[Service] ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM Type=idle Restart=always RestartSec=0 UtmpIdentifier=%I TTYPath=/dev/%I TTYReset=yes TTYVHangup=yes TTYVTDisallocate=yes KillMode=process IgnoreSIGPIPE=no SendSIGHUP=yes
Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=
[Install] WantedBy=getty.target DefaultInstance=tty1
retroarch.service
With following kernel params: systemd.unit=retroarch.target retroarch=1 you can autostart RetroArch. Also quit RetroArch in the menu will auto restart RetroArch.
[Unit] Description=Retroarch After=graphical.target ConditionKernelCommandLine=!retroarch=0 Requires=graphical.target
[Service] Environment=DISPLAY=:0.0 Environment=SDL_MOUSE_RELATIVE=0 Environment=FB_MULTI_BUFFER=2 Environment=HOME=/storage EnvironmentFile=-/run/libreelec/retroarch.conf ExecStartPre=-/usr/lib/retroarch/retroarch-config ExecStart=/usr/bin/retroarch KillMode=process TimeoutStopSec=10 Restart=always RestartSec=2 StartLimitInterval=0
[Install] WantedBy=retroarch.target
retroarch.target
Needed systemd target for above described init-script.
[Unit] Description=Retroarch Requires=multi-user.target graphical.target After=graphical.target Conflicts=rescue.target AllowIsolate=yes
[Install] Alias=default.target
Lakka is also heavily depended on systemd and connman for autodetection and starts of ethernet, bluetooth, wlan.
All services are stored in /etc/systemd/system/
Additional Lakka configs
udevil.conf
Udevil is used to recognize new usb-sticks and to mount it to /storage/roms/
allowed_media_dirs = /storage/roms allowed_devices = /dev/*
If I may suggest following addition to your use flags:
IUSE="... lakka_standalone"
REQUIRED_USE=" ... lakka_standalone ( lakka bluez bluetooth ethernet connman alsa-utils wireless-tools dhcp ntfs3g net-tools udevil rfkill systemd kms egl opengl dbus ssh evdev udev)
Enabled are the additions with following commands
systemctl enable sshd systemctl enable systemd-networkd.service systemctl enable systemd-resolved.service systemctl enable wpa_supplicant.service systemctl enable bluetooth.service systemctl enable retroarch.service systemctl enable connman systemctl enable devmon@root
Gentoo should then boot without X11 / Xorg directly into RetroArch like Lakka if prompted with retroarch=1 on the kernel command line.
Please note that Lakka does run everything as root.
Well, maybe a new ebuild (perhaps called lakka) would be a better approach than using the retroarch ebuild.
Thanks for the write up.
My thoughts on this, if we include it: Since we have to support and test them ourselves we should completely rewrite them and reevaluate the necessary dependencies.
For example, drop the root dependency and provide instructions for users to create /etc/systemd/system/
It would annoy many users if we arbitrarily modify LANG variables. There are also many ways a user may have setup auto mounting of inserted devices.
We could basically strip the unit files down to the bare minimum with the proposed ones as a base. They could easily be dropped in the retroarch ebuild with a USE flag and perhaps a short one liner on how they are supposed to be used.
In principle, the start scripts would end up kind of generic and not really retroarch specific at all apart from the Exec line and the name. Perhaps it is better placed as a generic start script ebuild to make the live of headless users easier. I did setup something like this on all my thin clients down at work and it was quiet easy. Only one service file needed to be written by myself. Also, openrc should be not forgotten.
What do you think? This is basically work commonly done by the administrator/user himself.
Thank you for your feedback.
You are right. Gentoo is all about freedom / choice , so we should support openrc and systemd.
I posted the original files, because I read that you wanted to be as close as possible to upstream.
It would however maybe require some patching or contribution to Lakka / RetroArch, because Lakka / RetroArch currently only supports connman and afaik systemd for their RetroArch builtin-services.
You may have for example a look to WiFi (not in default RetroArch enabled), which only works right now with connmanctl.
[Lakka WIFI] (https://i.ytimg.com/vi/4Wr0jXKM3EY/maxresdefault.jpg)
I also wrote two scripts some weeks ago, which are using a systemd stage3 seed, your repository and some of the files I posted in my first comment to build a Lakka like system based on Gentoo.
If you don`t mind I could write some articles in your Wiki in order to get a clearer picture what would be to do.
There is a lack of documentation for Lakka / RetroArch for these kind of information.
*disclaimer I never used lakka
You are right. Gentoo is all about freedom / choice , so we should support openrc and systemd.
It would however maybe require some patching or contribution to Lakka / RetroArch, because Lakka / RetroArch currently only supports connman and afaik systemd for their RetroArch builtin-services.
I took the liberty of looking through the lakka repos yesterday, completely forgetting searching through retroarch itself. Oh well, now I noticed that systemd is nowadays used to get the machine name, regardless of configuration. So there is that :neutral_face:.
I posted the original files, because I read that you wanted to be as close as possible to upstream.
Yes, but I didn't intend to clone a different distribution 😆, it wouldn't be possible without rewriting lakka either way. Some features can of course be enabled here, as in runtime dependencies. For example most of lakkas integration menus like wifi. Can you try running your setup as a user and see how much actually works that way? I image that wifi, bluetooth, ssh and a preconfigured samba shouldn't face any problems since they are multi user to begin with.
I disabled lakka as default by the way, because it can accidentally shutdown systems that have a shutdown script in PATH and that would be kinda unexpected if it isn't in a full on lakka situation.
If you don`t mind I could write some articles in your Wiki in order to get a clearer picture what would be to do.
Sure, feel free to add what you want.
They way I use retroarch is through framebuffer (kms, egl) and not Xorg.
I created a new user and put him into the groups video usb input users audio
With these groups I was able to start RetroArch and control it with an Wii U Pro controller.
- Stopping the services ssh, bluetooth and samba was not successfull due to missing rights, e.g.
Failed to stop bluetooth.service: Access denied
- Shutdown and reboot did also not work, e.g.
sh: shutdown: command not found
- WiFi and Network scanning did also not work, e.g.
Error wifi: Rejected send message, 2 matched rules; type="method_call", sender=":1.8" (uid=1000 pid=661 comm="connmanctl enable wifi ") interface="net.connman.Technology" member="SetProperty" error name="(unset)" requested_reply="0" destination="net.connman" (uid=0 pid=369 comm="/usr/sbin/connmand --nodaemon ") Error /net/connman/technology/wifi: Rejected send message, 2 matched rules; type="method_call", sender=":1.9" (uid=1000 pid=662 comm="connmanctl scan wifi ") interface="net.connman.Technology" member="Scan" error name="(unset)" requested_reply="0" destination="net.connman" (uid=0 pid=369 comm="/usr/sbin/connmand --nodaemon ") Error: Rejected send message, 2 matched rules; type="method_call", sender=":1.10" (uid=1000 pid=663 comm="connmanctl services ") interface="net.connman.Manager" member="GetServices" error name="(unset)" requested_reply="0" destination="net.connman" (uid=0 pid=369 comm="/usr/sbin/connmand --nodaemon ")
Game starting and play did work as a non-root user with above groups.
For "user-mode" I think we would have to apply some small changes to RetroArch to use the command sudo in front of the systemctl service commands and the connmanctl commands.
Well, after some further research following adjustments seems to work. Sudo with connmanctl is not required.
-Network (connmanctl) For network connmanctl is used. Changing /etc/dbus-1/system.d/connman.conf
<policy context="default">
<deny send_destination="net.connman"/>
</policy>
to
everything here works as far as I can see.
Following files need to be altered with sudo because of systemctl can`t be started as non-root user:
./command.c: system("sudo shutdown -P now"); ./command.c: system("sudo shutdown -r now");
./wifi/drivers/connmanctl.c: pclose(popen("sudo systemctl restart connman", "r"));
The permissions can be solved with polkit and custom *.rules files to allow users to start/stop/enable specific unit files and also allow control of the programs. This does not require the user to be in a special group.
Something to read for inspiration: Polkit Arch Wiki (See the lower sections)
We would have to rely on pkttyagent (which probably doesn't work for us) or depend on a proper one for desktop usage like gnome-extra/polkit-gnome to get all the fancy features like allowing us to use wifi.
I like this approach better because we wouldn't have to hack and overwrite so many system files and it also allows to start/stop systemd units with proper rules. Plus we could easier upstream these sort of changes, if the lakka project wants to run retroarch as a user some day.
I would have played around with it if egl would work for me but I hit a bug that makes it unusable in any fashion on my system so i can not use retroarch on a tty for now.
I propose to play around with this in a separate branch with a lakka ebuild, like you mentioned above.
To make this clear, I will not accept an ebuild that would force users to run retroarch as root. Of course that only applies to ebuilds and not the wiki.
Hello Stefan,
you made your points clear and I agree with you.
May I add another idea instead of using polkit to use sudo?
There are less dependencies (no extra java script libraries needed for example), less to configure and it works also with root.
Following patches already work:
Shutdown, Reboot
--- command.c -- system("shutdown -P now"); ++ system("sudo shutdown -P now");
-- system("shutdown -r now"); ++ system("sudo shutdown -r now");
Listing and connecting to Wifi, Ethernet
--- wifi/drivers/connmanctl.c
-- pclose(popen("connmanctl enable wifi", "r")); ++ pclose(popen("sudo connmanctl enable wifi", "r"));
-- pclose(popen("connmanctl scan wifi", "r")); ++ pclose(popen("sudo connmanctl scan wifi", "r"));
-- serv_file = popen("connmanctl services", "r"); ++ serv_file = popen("sudo connmanctl services", "r");
-- strlcat(command, "connmanctl services ", sizeof(command)); ++ strlcat(command, "sudo connmanctl services ", sizeof(command));
-- pclose(popen("systemctl restart connman", "r")); ++ pclose(popen("sudo systemctl restart connman", "r"));
-- strlcat(command, "connmanctl connect ", sizeof(command)); ++ strlcat(command, "sudo connmanctl connect ", sizeof(command));
Hi, Sorry for the delay in response. I approve, but consider replacing shutdown with the systemctl equivalent since I couldn't find shutdown on my system and systemctl poweroff should also work without sudo.