I have this working. To be clear, I was VERY close to giving up. I’ve spent quite a lot of time on this and it left me feeling quite stupid, more than usual.
Here is everything that I’ve learned, just to document for others:
/zynthian/config/user_config.shwill run at boot, before X is started. If you add anything blocking in here you will prevent the GUI from coming up. So, a while loop to test for the gui process in your process list will hang your GUI if that code is directly in this script, so don’t do that (that makes this recommendation incorrect: Run bash script at startup - #15 by jofemodo )
1b. I tried the “obvious” fixes to make this non-blocking –running another script in a new process from user_config.sh which contained the while loop described above. I tried to put it in its own process every way I know how: Specifically with & at the end, nohup, and setsid. All of these work to get the other script running without blocking the gui from starting (my second script logs to a file in /tmp so I know it was running), but none would successfully run the xinput commands to reattach/enable the disconnected device. In all of these I had stderr and stdout redirected to a file but both were empty, so I don’t know why this was failing. My suspicion is that the first line of the new script was trying to export DISPLAY=:0.0 and perhaps that was not working, but failing silently. Again, I don’t know for sure.
An interesting point of note is that using nohup and sleep seemed to create a problem in which the commands after the sleep were never executed. Bizarre, but also so far from the original problem that it was hard to allocate too much time to understand why.
I even tried an excessively long sleep delay and it didn’t make a difference, but what is interesting is that if the delay is too long, the sleep never seemed to return? That didn’t make much sense to me.
- In my previous post last night I mistakenly said that
/zynthian/config/zynthian_custom_config.shdoes not run based on looking at the source, but I was looking in the zythian-sys repository rather than zythian-ui. Azynthian_custom_config.shfile does run if it exists; it runs when the xserver first starts, before the splash screen. Putting things in here (which is not recommended per other threads) will block the splash screen so again one must fork a new process to not block the execution. I tried the same tricks described in 1b above, but again the xinput commands don’t work. They either silently fail or possibly succeed, but either way nothing in the logs and they do so too late to make a difference to the zynthian app.
For the sake of clarity I knew my scripts would “work.” because if I ssh in and run either zynthian_custom_config.sh or my previous user_config.sh they successfully start the other script in another process, my device is reattached in the xinput tree, and my touch inputs are properly aligned, but of course I always do that after zynthian is running.
My conclusion and “the fix”
Running zynthian itself is causing the issue, so running xinput before the zynthian application is running was working, just being undone by the execution of the zynthian app.
My scripts are now as follows. Forgive the excessive logging, but paranoia leads to logging.
The one that kicks it off in its own process:
(venv) root@zynthian:~# cat /zynthian/config/zynthian_custom_config.sh
#!/bin/bash
# run the gui wait script in a separate process
/zynthian/config/user_config_nonblocking.sh > /tmp/postgui.log 2>&1 &
And the one that sleeps a very long time before doing it’s work. Any shorter sleep causes it not to work consistently. Also after the command is executed it takes about 30s for the change to be felt on the touchscreen so touch is misaligned for the first ~2m after the GUI is up.
(venv) root@zynthian:~# cat /zynthian/config/user_config_nonblocking.sh
#!/bin/bash
cd /tmp
echo “starting wait” > /tmp/ucnb.log
while [[ “$(pgrep -f zynthian_main.py)” == “” ]]; do
sleep 0.1
done
echo “gui is up.” >> /tmp/ucnb.log
sleep 45s # while this says 45s, it feels like 2m in practice.
echo “slept for a bit” >> /tmp/ucnb.log
export DISPLAY=:0.0
/usr/bin/xinput reattach 8 2
/usr/bin/xinput enable 8
echo “tasks complete” >> /tmp/ucnb.log
Does it work? Yes.
Is it right? Not exactly, and for two reasons: (1) The devs would tell me not to put it in the file I did, and I’m sure they know best. I might try to move it. (2) the issue with my touchscreen device is really an issue with the fact that I don’t know how to fix or address the Xorg errors I’m having. I don’t know how to fix that, but I did know how to do this. If nothing else, this should help others who want to kick off scripts after the GUI is up.