rbreaves / kinto

Mac-style shortcut keys for Linux & Windows.
http://kinto.sh
GNU General Public License v2.0
4.45k stars 213 forks source link

Kinto Fails to Restart after Logout + Login #363

Open bhedavivek opened 3 years ago

bhedavivek commented 3 years ago

Describe the bug Kinto fails to restart after logging back into system after logout

Expected behavior Expectation would be kinto is able to restart again.

Install Type: Bare Metal Distro:

➜  kinto git:(master) ✗ uname -a    
Linux pop-os 5.8.0-7630-generic #32~1607010078~20.04~383a644-Ubuntu SMP Thu Dec 3 19:14:47 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

DE: Gnome Branch: master Commit: git rev-parse --short HEAD : 51f1498

During the Initial setup DISPLAY=:0 after log out and log in for some reason on my system, it changes to DISPLAY=:1.

I see when creating the xkeysnail service file we are setting environment variable DISPLAY={displayId}. Not sure why that is set, couldn't see any reasoning specific to it in the git log. Maybe we could remove it? updating my service file with the correct display id fixed it, but now I am assuming after a restart kinto will fail to start again since DISPLAY will reset to :0.

Gathered relevant log messages. I believe it's failing because xhost is targeting the wrong display.

Dec 26 14:26:20 pop-os systemd[1]: Started xkeysnail.
Dec 26 14:26:20 pop-os sudo[265393]: No protocol specified
Dec 26 14:26:20 pop-os sudo[265393]: /usr/bin/xhost:  unable to open display ":0"
Dec 26 14:26:20 pop-os systemd[1]: xkeysnail.service: Main process exited, code=exited, status=1/FAILURE
Dec 26 14:26:20 pop-os systemd[1]: xkeysnail.service: Failed with result 'exit-code'.
Dec 26 14:26:21 pop-os kinto.desktop[265394]: TERM environment variable not set.
Dec 26 14:26:22 pop-os kintotray.desktop[265397]: TERM environment variable not set.
Dec 26 14:26:23 pop-os kinto.desktop[265601]: TERM environment variable not set.
Dec 26 14:26:24 pop-os systemd[1]: xkeysnail.service: Scheduled restart job, restart counter is at 1.
Dec 26 14:26:24 pop-os systemd[1]: Stopped xkeysnail.
Dec 26 14:26:24 pop-os systemd[1]: Started xkeysnail.
Dec 26 14:26:24 pop-os sudo[265965]: No protocol specified
Dec 26 14:26:24 pop-os sudo[265965]: /usr/bin/xhost:  unable to open display ":0"
Dec 26 14:26:24 pop-os systemd[1]: xkeysnail.service: Main process exited, code=exited, status=1/FAILURE
Dec 26 14:26:24 pop-os systemd[1]: xkeysnail.service: Failed with result 'exit-code'.

xkeysnail

sudo systemctl status xkeysnail sudo journalctl --unit=xkeysnail.service -b

➜  ~ sudo systemctl status xkeysnail
sudo journalctl --unit=xkeysnail.service -b
● xkeysnail.service - xkeysnail
     Loaded: loaded (/lib/systemd/system/xkeysnail.service; disabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Sat 2020-12-26 14:29:08 PST; 2s ago
    Process: 269823 ExecStart=/usr/bin/sudo /bin/bash -c /usr/bin/xhost +SI:localuser:root && /home/krypton/.config/kinto/killdups.sh && /usr/local/bin/xkeysnail --quiet --watch /home/krypton/.config/kinto/kinto.p>
   Main PID: 269823 (code=exited, status=1/FAILURE)

xkb

systemctl --user status keyswap journalctl --user-unit=keyswap.service -b

➜  ~ systemctl --user status keyswap
journalctl --user-unit=keyswap.service -b
Unit keyswap.service could not be found.
-- Logs begin at Fri 2020-10-23 16:40:38 PDT, end at Sat 2020-12-26 14:29:36 PST. --
-- No entries --

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Rerunning setup.py or restarting computer fixes issue with kinto startup. Running kinto in debug mode also works.

bhedavivek commented 3 years ago

UPDATE: I guess the DISPLAY env variable is important. Maybe found a solution to dynamically fetch correct value for DISPLAY for plebs like me: https://askubuntu.com/a/744751

rbreaves commented 3 years ago

This is actually a known issue but one that hasn't come up for me in a long time and doesn't often get reported. It has probably been several months since it was last brought up, but thank you for letting me know as this issue does need to be addressed and providing that link does give a nice starting point.

There are likely other users who have had this same issue but not been reporting it so it gives me the opportunity to address it before potentially losing anyone due to this oversight. Initially I did not want to set it statically and tbh it shouldn't be - if it has to be then it still needs to be somewhat dynamic. It is strange but not every distro requires the display var to be set and I think it is very dependent on the order things come up with systemd.

bhedavivek commented 3 years ago

Found a working version of the command for me

➜  ~ sudo cat /usr/lib/systemd/system/xkeysnail.service
[sudo] password for krypton: 
[Unit]
Description=xkeysnail

[Service]
Type=simple
KillMode=process
ExecStart=/usr/bin/sudo /bin/bash -c 'export DISPLAY=$$(w -h krypton | awk \'$$2 ~ /:[0-9.]*/{print $$2}\'); /usr/bin/xhost +SI:localuser:root && /home/krypton/.config/kinto/killdups.sh && /usr/local/bin/xkeysnail --quiet --watch /home/krypton/.config/kinto/kinto.py'
ExecStop=/usr/bin/sudo /bin/bash -c '/usr/bin/sudo pkill -f bin/xkeysnail && exit 0'
Restart=on-failure
RestartSec=3

[Install]
WantedBy=graphical.target

we can't use $USER in this command since USER is root and display server is probably running for normal user. I updated the xkeysnail.service template that is generated by setup.py to inject/replace the user's actual username into the command so we can generate the right username.

Although I am not sure if that would be the right path for people with a multi-user setup. maybe we can pass args through systemctl to the command ?

rbreaves commented 3 years ago

Multi-user support I think is the final step that needs to happen before I start the process of creating repo and submitting the app to the official repos.

Here's a link on how to pass variables through an external file https://superuser.com/questions/728951/systemd-giving-my-service-multiple-arguments.

I tend to start the service via a desktop shortcut under ~/.config/autostart/kinto.desktop - it could be configured to edit the systemd service directly for the current user before start the service or updating a separate arguments file and then starting the systemd service which will link to that file.

nabinkhadka commented 2 years ago

I am facing same issue in fedora.

serafeimgr commented 1 year ago

facing the same issue in Ubuntu 22.04.1 LTS

rbreaves commented 1 year ago

facing the same issue in Ubuntu 22.04.1 LTS

Different issue most likely. Latest master should fix the install on Ubuntu 22.04.1. Whether it’ll fix it for others in this thread I dunno.

QNoir commented 1 year ago

@rbreaves unfortunately, it did not. the same issue on Ubuntu 22.04.1. it worked one time after removing and reinstallation and then broke again after restart.

only this solution helped me, not sure how for long: https://github.com/rbreaves/kinto/issues/363#issuecomment-751411920

rreina commented 1 year ago

I'm experiencing this bug under Elementary OS 7 (Ubuntu 22.04.1 LTS based) Linux MacBookPro-eOS 5.15.0-58-generic #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux Tried modifying xkeysnail service config #363 (comment) with no luck.

More details

artokun commented 1 year ago

I'm experiencing this bug under POP OS (Ubuntu 22.04.1 LTS based), same thing. as above, except for me it happened on restart not just log in/out

mateoradman commented 1 year ago

I experienced the same problem on Ubuntu 22.04.1 LTS.

Steps to reproduce:

  1. Toggle "Automatic Login" on in Ubuntu settings
  2. reboot and kinto will not be able to start
  3. Toggle auto login off
  4. reboot, login manually to your account, and kinto will start
shubham-shinde commented 1 year ago

I experienced the same problem on Ubuntu 20.04 LTS. I solved it by changing line

Environment=Display=:1 to Environment=Display=:0

in file sudo vim /usr/lib/systemd/system/xkeysnail.service

RedBearAK commented 1 year ago

My project (Toshy, an experimental offshoot of Kinto) seems to have avoided this kind of issue because it runs as the same user, from systemd "user" services, rather than a system-level service file running the keymapper as root. A udev rules file is used to manage the permissions on the /dev/uinput device.

One of the reasons for this was to get it to work with some Wayland environments more easily (Wayland+GNOME and Wayland+KDE Plasma). I'm not sure how easy it will ever be to open up a Wayland compositor instance to root the way Kinto does in the xkeysnail.service file with xhost.

Multi-user support:

Toshy uses a separate service to monitor the user's session to see if it is "active", and disables the keymapper service if the session becomes "inactive". This is according to an obscure bit of info from loginctl, so this only works if the system is using systemd. But in that case, this enables viable multi-user support. As long as at least the user account in the background is running the keymapper from the service files, rather than manually, it has worked in testing.

This thread also made me realize that the Toshy session monitor service was not stopping itself when the user logs out, so I fixed that issue. That's a much simpler situation to deal with, compared to when the user chooses the "Switch user" option and keeps the original session logged in in the background.