1
I have raspberry pi with stock raspbian installed. I have also installed RetroPI which works just fine.
What I wanted to do, is to write small autostart script that would start emulationstation (retropi main run script) when game pad is connected via bluetooth. I mave made simple udev rule
pi@raspberrypi:~ $ cat /etc/udev/rules.d/99-zlocal.rules
SUBSYSTEM=="bluetooth",SUBSYSTEMS=="amba", ATTRS{id}=="00241011", ACTION=="add", RUN+="/usr/local/bin/emulator-controll.sh start"
which works as expected, script is ran when gamepad is paired.
The problem is, that if i run my script via eg SSH like
sudo emulator-controll.sh start #sudo is optional here, but I want the same conditions as in udev trigger context
emulationstation as expected. However, if the same script is used as action trigger for udev rule above, it fails with errors like
Wed Aug 21 00:02:33 CEST 2019
Invoking user: root
Invoked start command
Invoking emulation station start command
Done
'unknown': I need something more specific.
tput: unknown terminal "unknown"
Segmentation fault
/usr/bin/emulationstation: line 23: /dev/tty: No such device or address
tput: unknown terminal "unknown"
I think that for some reasons (im linux newb) tty is not accessible from udev trigger context. Can I fix it somehow?
PS. I have tried to run background deamon (to use named pipes) that is launching on boot time, but effect is exactly the same - no tty in script execution context which makes me think that is is general behavior of background tasks
Script itself is irrelevant IMHO, but I will provide it as well for clarity:
#!/bin/bash
#/bin/date >> /tmp/udev.log
#env >> /tmp/udev.log
#echo "Connected" > /dev/pts/2
log=/var/log/emulator-controll.log
{
readarray -t PIDS <<< $(ps aux | grep [e]mulationstation | awk '{print $2}')
echo ">${PIDS[@]}<"
echo >> $log
/bin/date >> $log
echo "Invoking user: $(whoami)"
case "$1" in
start )
echo "Invoked start command" >> $log
if [[ "${#PIDS[@]}" -ge 3 ]]; then
echo "Emulator is already running. No action is taken" >> $log
else
echo "Invoking emulation station start command" >> $log
export DISPLAY=:0
sudo -u pi nohup emulationstation &
fi
echo "Done" >> $log
;;
stop )
echo "Invoked stop command" >> $log
if [[ -z "${PIDS[0]}" ]]; then
echo "Emulator is not running, no action is taken" >> $log
else
echo "Killing processes with PIDs ${PIDS[@]}" >> $log
for pid in "${PIDS[@]}"; do
kill $pid
done
echo "Done" >> $log
fi
;;
*)
echo "Usage: $0 {start|stop}"
esac
} >> $log 2>>$log
It may not be the best approach, still running
emulationstation
insidescreen
ortmux
will probably help. Something likesudo -u pi tmux new-session -d -s some_name emulationstation
. Untested, hence not an answer. A useful side effect is you can use the exit status oftmux has-session -t some_name
to know if the utility is running, andtmux kill-session -t some_name
to kill it. Unlessemulationstation
daemonizes itself (I don't know the utility at all); but it probably doesn't, since it tries to do something with its controlling terminal. – Kamil Maciorowski – 2019-08-21T07:43:44.993I have tried that with screen, but the problem is, that it simply wont start - lvl0: Error initializing SDL!
lvl0: Renderer failed to initialize! lvl0: Window failed to initialize!
It is part of RetroPI suite. It acts as frontend for emulators and uses HW acceleration to draw. – Antoniossss – 2019-08-21T07:50:33.363