emulationstation running as a service
-
I cannot find documentation on how to setup emulationstation as a service under systemd so I tried to execute it within another script I already have (TelegramBot) but I cannot make it work, I was getting a TERM error so I define a bunch of variables but it didn't work, now I see a weird error saying "[80B blob data]"
I even tried to call another script instead and it didn't work.My goal is to be able to start emulation station on demand since I don't want it running all the time due to other resource intensive tasks I have running on my rPi.
Suggestion?
import subprocess import sys import time import telepot import os import uuid from telepot.loop import MessageLoop from telepot.namedtuple import ReplyKeyboardMarkup os.setuid(1001) enviroment = [ ('LC_ALL','en_US.UTF-8'), ('LC_MEASUREMENT','en_US.UTF-8'), ('LC_PAPER','en_US.UTF-8'), ('LC_MONETARY','en_US.UTF-8'), ('LANG','en_US.UTF-8'), ('LC_NAME','en_US.UTF-8'), ('LC_COLLATE','en_US.UTF-8'), ('LC_IDENTIFICATION','en_US.UTF-8'), ('LC_TIME','en_US.UTF-8'), ('LC_TELEPHONE','en_US.UTF-8'), ('LC_MESSAGES','en_US.UTF-8'), ('LC_CTYPE','en_US.UTF-8'), ('LC_ADDRESS','en_US.UTF-8'), ('LC_NUMERIC','en_US.UTF-8'), ('PWD','/home/dark_wolfslv'), ('HOME','/home/dark_wolfslv'), ('TERM','xterm'), ('PATH','/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games'), ('LS_COLORS','rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:'), ('NO_AT_BRIDGE','1'), ('XDG_SESSION_ID','c12'), ('USER','dark_wolfslv'), ('TEXTDOMAIN','Linux-PAM'), ('MAIL','/var/mail/dark_wolfslv'), ('SHELL','/bin/bash'), ('SHLVL','1'), ('LANGUAGE','en_US:en'), ('LOGNAME','dark_wolfslv'), ('XDG_RUNTIME_DIR','/run/user/1001') ] def handle(msg): chat_id = msg['chat']['id'] command = msg['text'] sys.stderr.write('Got command: %s' % command) if command == '1': #Do Something elif command == '2': #Do Something elif command == '3': #Do Something elif command == 'EmulationStation': #pid = subprocess.Popen([sys.executable, "/home/dark_wolfslv/ppp.py"]) #os.system('bash /home/dark_wolfslv/run_emulationstation.sh') #os.system('emulationstation') #os.chdir('/home/dark_wolfslv') #bot.sendMessage(chat_id, 'cdw: %s' % os.getcwd()) for varname,value in enviroment: os.putenv(varname,value) os.system('emulationstation') bot.sendMessage(chat_id, 'EmulationStation started') else: bot.sendMessage(chat_id, 'Invalid command') bot = telepot.Bot('ID') MessageLoop(bot, handle).run_as_thread() sys.stderr.write('Listening...\n') # Keep the program running. while 1: time.sleep(10) >>>>>>>>>>>>>>>>>>>>>>>>> import os import subprocess import sys print "start" pid = subprocess.Popen(['python3', '/home/dark_wolfslv/ppp.py']) # pid = subprocess.Popen([sys.executable, "/home/dark_wolfslv/ppp.py"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)) # pid = subprocess.Popen([sys.executable, "/home/dark_wolfslv/ppp.py"]) # pid = subprocess.Popen([sys.executable, "/bin/bash", "/home/dark_wolfslv/run_emulationstation.sh"]) # subprocess.Popen(["/bin/bash", "/home/dark_wolfslv/run_emulationstation.sh"]) # subprocess.Popen(bash /home/dark_wolfslv/run_emulationstation.sh) # # os.system('bash /home/dark_wolfslv/run_emulationstation.sh') # subprocess.call("./run_emulationstation.sh") print "end"
-
+1 I would love if Retropie configured Emulation Station to run as a systemd service. I personally wouldn't disable it at boot, but it would make it a lot easier to programmatically start/stop/enable/disable based on my needs.
As it stands now I don't even know where it's even invoked at boot :-O
-
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"
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.