Skip to main content
Topic: Execute script after user login - universal autostart with runit? (Read 581 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Execute script after user login - universal autostart with runit?

There some tasks I want to execute no meter what login manager or window manager I use.
Keyboard remapping, keyboard switch, xset r rate.
Is it possible to create a script that executes after login? What to use?

Re: Execute script after user login - universal autostart with runit?

Reply #1
Would it work to run something in ~/.bashrc or the equivalent if you use another shell?
For instance when I "startx" using openrc I have this:
Code: [Select]
if (( [[ -z $DISPLAY && ! -e /tmp/.X11-unix/X0 ]] ) && (rc-status -r | grep -q 'default')); then
exec startx -- -verbose 6 -logverbose 6 >/home/$USER/.startx.log 2>&1
So that is mostly the opposite to what you would want as it checks DISPLAY is not set with -z (which is the opposite to -n), X is not running,  and looks at the run level status which you might want, using a runit equivalent method.
But I guess you would want it to start a separate script or process that could run these tests at short intervals in a loop until the conditions you desire are met, possibly ultimately timing out in case of other bugs, rather than running tests once in bashrc. You could just use sleep to delay for a while then simply run the commands you want, but that seems potentially suboptimal and error prone.
Having said all that there could be a much simpler answer someone else might come up with, some kind of service that has a dependency that can be provided by your various window managers and only runs when they are running?