OpenWaterFoundation / cdss-app-snodas-tools

Colorado's Decision Support Systems (CDSS) Snow Data Assimilation System (SNODAS) Tools
8 stars 4 forks source link

Cron job errors out when running SNODASDaily_Automated.py script #38

Open Nightsphere opened 3 years ago

Nightsphere commented 3 years ago

The automated script runs correctly when manually run on command line, but when the cron job runs the same script, what I believe to be a X Windows error displays:

image

smalers commented 3 years ago

Try this solution:

https://stackoverflow.com/questions/50005195/headless-python-script-requires-x-server-to-run

smalers commented 3 years ago

Also, I ran into the same thing with GeoProcessor and the run script sets DISPLAY. I don't remember if I tried to run headless but the point is that if a self-contained run script is used, it can make sure that necessary setup is done in various environments.

Nightsphere commented 3 years ago

The DISPLAY env variable cannot be seen by cron when run from a user account instead of root. It needs to be set before the cron script is called:

* * * * * export DISPLAY=<full-display-name> && /path/to/script.bash

Closing the issue.

smalers commented 3 years ago

This is helpful for understanding places where DISPLAY might be getting set by the system:

https://stackoverflow.com/questions/52041092/setting-environment-variable-for-a-compute-engine-vm

smalers commented 3 years ago

It looks like it did not run again today. I still would like to understand why DISPLAY is so finicky. Here are some other ideas:

If it is necessary to do this, then I recommend updating the application to accept a command line parameter such as --noui (no UI) or similar. This can be used when running in headless mode. I searched GeoProcessor for something like this but don't see anything. I remember looking into it but perhaps there has not been a need to run the GeoProcessor headless.

Nightsphere commented 3 years ago

The issue was finally resolved. QT was trying to run GUI based code in a headless server. The original error up above gave possible plugins to use instead. One of these options is offscreen, which renders to an offscreen buffer. This is the fix that we've been looking for. When cron runs the SNODASDaily_Automated._forCRON.sh script, it sets the QT_QPA_PLATFORM environment variable before it runs the SNODASDaily_Automated.py python module.

The DISPLAY environment variable might not even need to be set, but I will update this issue once more after tests have been run, and will close the issue if correct.