You are not logged in.

#1 2016-03-30 06:49:04

hiveNzin0
Member
Registered: 2011-10-02
Posts: 84

[systemd] creation of service - Unable to connect to X server

Hi guys,

I am using a script to map the keys of my Razer naga and I need to execute it each time the computer starts.

Here is the script :

#!/usr/bin/bash

# key map taken from : /usr/include/X11/keysymdef.h

remote_id=$(
 xinput list |
 sed -n 's/.*Naga.*id=\([0-9]*\).*keyboard.*/\1/p'
)
[ "$remote_id" ] || exit

mkdir -p /tmp/xkb/symbols
cat >/tmp/xkb/symbols/custom <<\EOF

xkb_symbols "remote" {
 key <AE01> { [0xffe9] }; # ALT
 key <AE02> { [0xffe3] }; # CTRL
 key <AE03> { [0xff09] }; # TAB
 key <AE04> { [0xff50] }; # 7 - XK_Home
 key <AE05> { [0xff52] }; # 8 - XK_Up
 key <AE06> { [0xff55] }; # 9 - XK_Page_Up
 key <AE07> { [0xff51] }; # 4 - XK_Left
 key <AE08> { [0xff58] }; # 5 - XK_Begin
 key <AE09> { [0xff53] }; # 6 - XK_Right
 key <AE10> { [0xff57] }; # 1 - XK_End
 key <AE11> { [0xff54] }; # 2 - XK_Down
 key <AE12> { [0xff56] }; # 3 - XK_Page_Down
};
EOF

setxkbmap -device $remote_id -print | sed 's/\(xkb_symbols.*\)"/\1+custom(remote)"/' | xkbcomp -I/tmp/xkb -i $remote_id -synch - $DISPLAY 2>/dev/null

When I execute it manually, it works.

I tried to create a service to execute this script but I get the error "Unable to connect to X server"

Here is what I tried :

[Unit]
Description=Razer Naga key mapping service
After=graphical.target
Requires=graphical.target

[Service]
Type=oneshot
ExecStart=/mnt/data/scripts/own/shell/naga_map.sh

[Install]
Alias=naga.service

I am not sure of the values or if something is missing though.

When I enable it (systemctl enable naga.service), no problem.

When I start it (systemctl start naga.service), I get this error :

● naga.service - Razer Naga key mapping service
   Loaded: loaded (/usr/lib/systemd/system/naga.service; linked; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2016-03-30 08:47:05 CEST; 4s ago
  Process: 18813 ExecStart=/mnt/data/scripts/own/shell/naga_map.sh (code=exited, status=1/FAILURE)
Main PID: 18813 (code=exited, status=1/FAILURE)

Mar 30 08:47:05 arch systemd[1]: Starting Razer Naga key mapping service...
Mar 30 08:47:05 arch naga_map.sh[18813]: Unable to connect to X server
Mar 30 08:47:05 arch systemd[1]: naga.service: Main process exited, code=exited, status=1/FAILURE
Mar 30 08:47:05 arch systemd[1]: Failed to start Razer Naga key mapping service.
Mar 30 08:47:05 arch systemd[1]: naga.service: Unit entered failed state.
Mar 30 08:47:05 arch systemd[1]: naga.service: Failed with result 'exit-code'.

Any idea of what I am doing wrong ?

Thanks a lot.

Offline

#2 2016-03-30 07:06:40

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [systemd] creation of service - Unable to connect to X server

Not a Sysadmin issue, moving to NC...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2016-03-30 07:08:24

hiveNzin0
Member
Registered: 2011-10-02
Posts: 84

Re: [systemd] creation of service - Unable to connect to X server

jasonwryan wrote:

Not a Sysadmin issue, moving to NC...

Sorry, I thought the "System administration" forum was more appropriate, my bad.

Thanks for moving it.

Offline

#4 2016-03-30 07:15:13

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [systemd] creation of service - Unable to connect to X server


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2016-03-30 07:19:38

hiveNzin0
Member
Registered: 2011-10-02
Posts: 84

Re: [systemd] creation of service - Unable to connect to X server

Thanks for the link.

I don't start X in a non standard way and both variables contain something so I don't know what's wrong with my naga.service

echo $DISPLAY
:0

echo $XAUTHORITY
/tmp/xauth-1001-_0

Offline

#6 2016-03-30 08:53:29

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [systemd] creation of service - Unable to connect to X server

That wiki link adresses user services (started after those variables have been imported by the xinitrc.d snippet). What you have here, is a system service.

But why use a systemd service at all? If you use a graphical DM, you could use, for example, LightDM's display-setup-script to activate the mapping at the login screen. Otherwise you could simply run it from your ~/.xinitrc.

Offline

#7 2016-03-30 09:29:36

hiveNzin0
Member
Registered: 2011-10-02
Posts: 84

Re: [systemd] creation of service - Unable to connect to X server

Raynman wrote:

That wiki link adresses user services (started after those variables have been imported by the xinitrc.d snippet). What you have here, is a system service.

But why use a systemd service at all? If you use a graphical DM, you could use, for example, LightDM's display-setup-script to activate the mapping at the login screen. Otherwise you could simply run it from your ~/.xinitrc.

Why use a systemd service ? I don't know, I thought it was the right thing to do... it seems I was wrong.

I'll have a look at the xinitrc file. I use KDE and SDDM but yeah, I forgot I could do that too.

Thanks.

Offline

Board footer

Powered by FluxBB