SystemRage / py-kms

KMS Server Emulator written in Python
The Unlicense
2.04k stars 618 forks source link

_tkinter.TclError: no display name and no $DISPLAY environment variable #34

Closed vosdev closed 5 years ago

vosdev commented 5 years ago

after building py-kms/docker-py3-kms I am left with this error.

Recreating kms ... done
Attaching to kms 
kms    | Traceback (most recent call last): 
kms    |   File "pykms_Server.py", line 266, in <module>
kms    |     srv_main_with_gui()
kms    |   File "pykms_Server.py", line 197, in srv_main_with_gui
kms    |     root = pykms_GuiBase.KmsGui()
kms    |   File "/home/py-kms/py-kms/pykms_GuiBase.py", line 77, in __init__ 
kms    |     tk.Tk.__init__(self, *args, **kwargs)
kms    |   File "/usr/lib/python3.6/tkinter/__init__.py", line 2017, in __init__
kms    |     self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
kms    | _tkinter.TclError: no display name and no $DISPLAY environment variable
kms exited with code 1

Modification to start.sh:

#!/bin/bash
# EN: Start daemons
# RU: Запуск демонов
-cd /home/py-kms/py3-kms
+cd /home/py-kms/py-kms
if [ "$SQLITE" == false ];

modifications made to the Dockerfile that still need a pull request/fix:

    py3-pygments \
    sqlite-libs \
+    python3-tkinter \
    py3-pip && \

(These changes are in PR #33)

# Set Workdir
-WORKDIR /home/py-kms/py3-kms
+WORKDIR /home/py-kms/py-kms
x-zvf commented 5 years ago

I encountered the same error. In the pykms_Server.py simply replace everything in the if __name__=="__main__": block with srv_main_without_gui(). The isatty function sometimes doesn't seem to detect it properly(my issue was when running it as a systemd service).

SystemRage commented 5 years ago

Created this service:

Description=py-kms
After=network.target
Wants=network-online.target

[Service]
ExecStart=/usr/bin/python3 -u path/to/py-kms/pykms_Server.py
Restart=always
KillMode=process
Type=simple
User=nobody
Group=nogroup

[Install]
WantedBy=multi-user.target

Reproduced the error and adjusted with a try-except. Another error met during debug is: IOError: [Errno 13] Permission denied: 'path/to/py-kms/pykms_logserver.log So if you get this, remember to grant permission with: sudo chmod 777 path/to/py-kms/pykms_logserver.log.

Finally: journalctl -b -u py-kms.service -o cat and i can now see that all works.

Note: I have to put -u option to see systemd messages output though print statements are flushed. I don't know why. Mystery.