I've spent most of the day trying to launch two commands after login of the GUI on Raspberry OS. I am trying to run a Ruby on Rails server after logging into the GUI (not on boot). The commands I would like to run are:
~/.xsessionrc
#!/bin/bash
. /home/pi/.rvm/scripts/rvm
cd /home/pi/base/ && rails s -b 10.3.141.1 -p 3000 -d &
I have been trying to do this using .profile
, .bash_profile
, .bashrc
, .xsession
, .xinitrc
but it's proving impossible and I haven't got further than breaking my installation. I've also had a go at the .desktop
and autostart
options and followed various articles and Q&As online. Also tried saving it into a separate script and running that, they all work as I expect from the command line when triggered but the server isn't running automatically after GUI login. The closest I've got is the server running automatically once I start a shell from within the GUI.
I think I should be editing the xsession
files as these are run by lightdm
after logging in via the GUI? But when I do the GUI breaks and just returns me to the login password screen after each attempt.
Despite a lot of time, I don't seem much closer to the solution - from experience this normally means I've misunderstood something fundamental!
Any help would be amazing
Many thanks
source ~/.xsessionrc
, in both cases the rails server will start as expected. I get the following error in~/.xsession-errors
:/etc/X11/Xsession: 3: /home/pi/.xsessionrc: rails: not found
. I have updated my question so that it reflects my.xsessionrc
file/bin/
to/wrappers/
in the path given bywhich rails
as per the accepted answer here