I am starting to set up a Smarthome and have followed Openhab for a while now. couple of weeks ago i actually started to set up some test services and stuff. SO it might be that my Isuue is noob related and i apologize but i couldnt find it anywhere.
in short:
I try using Openhab in combination with Kubuntu 16.10 (new Hardware so i need the newest drivers) but am unable to start a desktop program (Kodi) on (not as. i want to start it through exec which is logged under Openhab user, but i am logged in as another user, through desktop) my logged in User (not Openhab).
My research lead me to the conclusion, that the Exec Binding can not export the display or in any case use one at all. I can start Kodi with ssh loged in as Openhab and “export Display:0 ; kodi” or even running “su -c kodi lukas” (with some sudo tinkering).
I will try to provide a clear description soon if its not a common noob issue, or not descriptive enough.
Greetings,
Lukas
edit1:
Openhab user controls exec
"normal" user controls display
Openhab user start kodi = kodi running but not on Display
"normal" user start kodi = works fine
manual start through ssh as Openhab= works fine (described commands)
Openhab user trying to start kodi AS “normal” user (described commands)= kodi crash
You say you cannot start kodi with your non-openhab user but you conclude that the Exec binding is causing the problem.
These are completely different environments. openHAB, running under the openhab user, has no impact or influence over your other logged in users and therefore would not be preventing you from starting any X programs under that user.
If you are trying to say that you are trying to start an X program through openHAB using the Exec binding, then you will probably want to write a shell script that exports the display and runs the program all from the script. Then use the Exec binding to run that script.
The problem people run into with the Exec binding is they assume:
programs and scripts have the same environment variables, paths, and other settings as the normal logged in user
the binding gets a shell and therefore standard shell commands (e.g. export) are available.
Neither of the above is true. But when you run a shell script, you are given a shell and can run shell commands, set environment variables, etc.
thx for the reply. what i meant by not beeing able to start is through the openhab binding, as u concluded correctly out of my badly written explanation. I tried using shell scripts, and am able to start kodi on my logged in user (not openhab) through a command in a shell logged in as Openhab. for example i can log in into my server using putty, as Openhab, run the described commands and it will start kodi. now then i tell the exec binding to run the same commands, either directly or placed in a .sh file (e.g: kodi.sh) kodi will crash telling me there is no display available
here is the crash log:
20:13:23 T:139657917528960 NOTICE: Setup SDL
20:13:23 T:139657917528960 ERROR: GLX Error: No Display found
20:13:23 T:139657917528960 FATAL: CApplication::Create: Unable to init windowing system
############### END LOG FILE ################
now the thing that completely puzzles me is, when i just run “kodi” in the exec, it starts (under user openhab in the taskmanager), but i dont see it on my display… shouldnt it crash as well telling me it doesnt have a display? Has noone ever needed to run a gui interface through exec on ubuntu?
Probably not. Strictly speaking, this is not something that openHAB is expected to do. It is designed to be a server based application and to typically run on a headless machine. Using OH to control GUI based programs would be, in my opinion, an edge case.
Personally, I think you should be looking to use a service manager to start and control Kodi. Since you are on Ubuntu the default one is systemd. You would create a service config and your openHAB Exec binding would start/stop/etc the program using systemd commands.
I can’t answer what the correct way to do it would be through OH. I know that if you want to open a display on the default display from a user who doesn’t own that display you need to run xhost + from a terminal in that display. But I have no idea how or whether it is possible if no one is logged in.
Well, in case someone else tries to do similiar things, here is how i finally got it to work:
Like for other exec commands, you have to allow openhab to run in sudo, this is needed to run a programm as a different user. Create or modify /etc/sudoers.d/* for me its /etc/sudoers.d/kodi.
sudo nano /etc/sudoers.d/kodi
add the line that allows openhab to run the program as sudo
openhab ALL=(ALL:ALL)NOPASSWD:/usr/bin/kodi
and now comes the tricky part :-). Normally if you now run “sudo -H -u username kodi” it will crash because it has no Display specified. The easiest (and only) way i found is to globally define my display as a system variable. THis might give you problems if you have multiple displays or other cases, for me it solved the problem. So go to /etc/environment
sudo nano /etc/environment
and add the following line
DISPLAY=:0
thats it, now the exec binding knows where to open kodi to.
I bet there are nicer or more proper ways to do it, i am not a coder, but it works for now.
Hope i can save someone else the hours it took me to figure this one out
always use visudo to edit sudoers files. If you have a typo or something else wrong you will completely break sudo and it is a real pain to recover. Visudo checks for errors before activating the edits.
some users may need to execute xhost + to enable another user to open the display.
Thx for the comment, i didnt know visudo does that, the last time i used it i couldnt exit or save and ended up closing the shell .
About the xhost, my understanding is that sudo -u skips this, as the programm isnt run as a different user. But lets see what others report.
Since this should generally eork for all gui displays, a sentence in the wiki or somewhere, where more are able to find it might be a an idea.
There are a few very simple commands that can completely break your install and editing sudoers without using visudo is one of them.
You cannot fix this on the machine you are running on. You have to mount the file system on another computer that can read that file system (i.e. not Windows, I think not Mac) and edit the file on that other machine, using visudo this time. You may need to create a VM, or download and run an Ubuntu Live CD or something like that to access the file.
Often it is easier to just reinstall the OS at this point. It depends on whether you have good backups or not.