daisyUniverse / Keebie

Easy Second Keyboard support in Linux (With layers!)
84 stars 18 forks source link

Not working as systemd service #10

Closed parasbhanot closed 3 years ago

parasbhanot commented 3 years ago

Hi,

I am trying to run keebie.py using as systemd service so that i can turn the script on and off using systemctl command but for some reasons keebie.py refuse to work with systemd but if i run the keebie.py from the terminal emulator everthing works as expected

The keeebie service seems to be working but it is not executing any command that i have defined in default.json.

~ ❯ sudo systemctl status keebie                                              11:17:33
● keebie.service - Keebie service
     Loaded: loaded (/etc/systemd/system/keebie.service; disabled; vendor preset: dis>
     Active: active (running) since Sat 2021-01-30 11:17:33 IST; 1s ago
   Main PID: 62904 (python3)
      Tasks: 1 (limit: 9366)
     Memory: 12.6M
     CGroup: /system.slice/keebie.service
             └─62904 /usr/bin/python3 /home/parasbhanot/Keebie/keebie.py

i have created the keebie service with the following content :

[Unit]
Description=Keebie service 

[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/parasbhanot/Keebie/keebie.py

[Install]
WantedBy=multi-user.target

Please note that i have also created the udev rule for my second keyboard so it cannot not be a permission issue.

if i disconnect my second keyboard and then check the status of the keebie service i get the following :


/etc/systemd/system🔒 ❯ sudo systemctl status keebie                          11:31:33
[sudo] password for parasbhanot: 
● keebie.service - Keebie service
     Loaded: loaded (/etc/systemd/system/keebie.service; disabled; vendor preset: dis>
     Active: failed (Result: exit-code) since Sat 2021-01-30 11:34:31 IST; 7s ago
    Process: 62904 ExecStart=/usr/bin/python3 /home/parasbhanot/Keebie/keebie.py (cod>
   Main PID: 62904 (code=exited, status=1/FAILURE)

Jan 30 11:34:31 garuda python3[62904]: Exception ignored in: <function InputDevice.__>
Jan 30 11:34:31 garuda python3[62904]: Traceback (most recent call last):
Jan 30 11:34:31 garuda python3[62904]:   File "/usr/lib/python3.9/site-packages/evdev>
Jan 30 11:34:31 garuda python3[62904]:   File "/usr/lib/python3.9/site-packages/evdev>
Jan 30 11:34:31 garuda python3[62904]:   File "/usr/lib/python3.9/site-packages/evdev>
Jan 30 11:34:31 garuda python3[62904]:   File "/usr/lib/python3.9/asyncio/events.py",>
Jan 30 11:34:31 garuda python3[62904]:   File "/usr/lib/python3.9/asyncio/events.py",>
Jan 30 11:34:31 garuda python3[62904]: ImportError: sys.meta_path is None, Python is >
Jan 30 11:34:31 garuda systemd[1]: keebie.service: Main process exited, code=exited, >
Jan 30 11:34:31 garuda systemd[1]: keebie.service: Failed with result 'exit-code'.

i have also cheked the jorunal logs . it seems script is working but it is not executing xdotool when it is run as service which is strange but simple echo commands are working fine as given below.

16:11 garuda python3[28139]: error: Your personal settings will not be saved.
Jan 31 13:16:11 garuda python3[28139]: error: Unable to locate the config directory.
Jan 31 13:16:11 garuda python3[28139]: error: Please set the XDG_CONFIG_HOME or HOME environment variable before starting fish.
Jan 31 13:16:11 garuda python3[28141]: Error: Can't open display: (null)
Jan 31 13:16:11 garuda python3[28141]: Failed creating new xdo instance

Jan 31 13:18:14 garuda python3[28189]: hello from default

My default.json file :

{
   "KEY_F10": "layer:parasbhanot",
   "KEY_SPACE": "echo 'hello from default' ",
   "KEY_F1": "/home/parasbhanot/Automation/scripts/ping.sh",
   "KEY_SCROLLLOCK": "xdotool key ctrl+n"
}

i am running out of ideas .

has anyone tested keebie.py with systemd ?

parasbhanot commented 3 years ago

For anyone who is facing same issue simply set the Display Environment variable in your unit file as given below :

[Unit] Description=Keebie service

[Service] Type=simple Environment=DISPLAY=:0 ExecStart=/usr/bin/python3 /home/parasbhanot/Keebie/keebie.py

[Install] WantedBy=multi-user.target