I want to start emulationstation on-demand, this is what I've come up with:
Emulationstation heavily depends on a terminal being allocated for it to work. It switches a lot between graphical and text-mode. So in "/etc/systemd/system/my-emulationstation.service":
[Unit]
Description=my emulationstation
[Service]
User=pi
ExecStart=/usr/local/bin/run-emulationstation
Type=simple
StandardInput=tty-force
TTYVHangup=yes
TTYPath=/dev/tty20
TTYReset=yes
Also, there's a bug that requires emulationstation to be started inside /home/pi, so in "/usr/local/bin/run-emulationstation":
#! /bin/bash
# switch to same tty allocated in .service
chvt 20
# cd to home
cd /home/pi
# run emulationstation in foreground process
/opt/retropie/supplementary/emulationstation/emulationstation.sh
And for the curious: I want it to start when specific hardware is attached, specifically an 8Bitdo Zero Bluetooth Gamepad. So in "/etc/udev/rules.d/50-my-emulationstation.rules":
ACTION=="add", SUBSYSTEM=="input", ATTR{name}=="8Bitdo Zero GamePad", TAG+="systemd", ENV{SYSTEMD_WANTS}="my-emulationstation"