Systemd - Find .Xauthority file to use

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I'm currently using a systemd unit file to configure a service which uses X server display.
The X server instance is launched by the user logged in (currently pi user) but the service is launched at root.
I can successfully launch the service using systemctl start test_graphic_app if I hard code the .Xauthority file location into XAUTHORITY variable from the unit file as follow
[Unit]
Description=Test Graphic App
After=multi-user.target
[Service]
Type=simple
User=root
Group=root
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/pi/.Xauthority"
ExecStart=/usr/bin/python3 /usr/sbin/test_graphic_app.py
KillSignal=SIGINT
SuccessExitStatus=SIGINT
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=test_graphic_app
Restart=on-failure
[Install]
WantedBy=default.target
However this obviously doesn't work if I log using another user or if I run it locally on my laptop cause the user launching X is not pi
I would like to dynamically get the .Xauthority file location on the system.
I've tried using sudo xauth info | grep Authority | awk 'print $3' as follow
Environment="XAUTHORITY=$(/usr/bin/xauth info | grep Authority | awk 'print $3')"
ExecStartPre=/bin/bash -c 'export XAUTHORITY=$XAUTHORITY'
However if the command works on my laptop, it doesn't on the pi
## On laptop ##
$ sudo xauth info | grep "Authority file" | awk 'print $3'
/run/user/1000/gdm/Xauthority
## On pi ##
$ sudo xauth info | grep "Authority file" | awk 'print $3'
xauth: file /root/.Xauthority does not exist
/root/.Xauthority
I was unable find how to get the .Xauthority file location depending on the user that have launched the X server instance. Also, I don't want to allow any user to use X display doing xhost +
How can I get the location within my systemd unit?
Is there any better solution other than finding the .Xauthority location?
systemd python raspberry-pi x-server xauth
add a comment |Â
up vote
2
down vote
favorite
I'm currently using a systemd unit file to configure a service which uses X server display.
The X server instance is launched by the user logged in (currently pi user) but the service is launched at root.
I can successfully launch the service using systemctl start test_graphic_app if I hard code the .Xauthority file location into XAUTHORITY variable from the unit file as follow
[Unit]
Description=Test Graphic App
After=multi-user.target
[Service]
Type=simple
User=root
Group=root
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/pi/.Xauthority"
ExecStart=/usr/bin/python3 /usr/sbin/test_graphic_app.py
KillSignal=SIGINT
SuccessExitStatus=SIGINT
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=test_graphic_app
Restart=on-failure
[Install]
WantedBy=default.target
However this obviously doesn't work if I log using another user or if I run it locally on my laptop cause the user launching X is not pi
I would like to dynamically get the .Xauthority file location on the system.
I've tried using sudo xauth info | grep Authority | awk 'print $3' as follow
Environment="XAUTHORITY=$(/usr/bin/xauth info | grep Authority | awk 'print $3')"
ExecStartPre=/bin/bash -c 'export XAUTHORITY=$XAUTHORITY'
However if the command works on my laptop, it doesn't on the pi
## On laptop ##
$ sudo xauth info | grep "Authority file" | awk 'print $3'
/run/user/1000/gdm/Xauthority
## On pi ##
$ sudo xauth info | grep "Authority file" | awk 'print $3'
xauth: file /root/.Xauthority does not exist
/root/.Xauthority
I was unable find how to get the .Xauthority file location depending on the user that have launched the X server instance. Also, I don't want to allow any user to use X display doing xhost +
How can I get the location within my systemd unit?
Is there any better solution other than finding the .Xauthority location?
systemd python raspberry-pi x-server xauth
The easy solution is not to launch your service at boot, but launch it when this particular user logs in. Or use a display manager, which will launch the X server, and launch the service once the X server is up. Trying to start your service before there is any X server it can connect is broken, no matter how many workarounds you try. If the service does anything important which you need at boot, split it into a non-graphical and a graphical part.
â dirkt
Sep 17 at 6:28
I'm using autolog on the raspberry pi anddefault.targetis set to graphical runlevel, so the service start after X has been launched.
â Arkaik
Sep 18 at 8:06
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'm currently using a systemd unit file to configure a service which uses X server display.
The X server instance is launched by the user logged in (currently pi user) but the service is launched at root.
I can successfully launch the service using systemctl start test_graphic_app if I hard code the .Xauthority file location into XAUTHORITY variable from the unit file as follow
[Unit]
Description=Test Graphic App
After=multi-user.target
[Service]
Type=simple
User=root
Group=root
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/pi/.Xauthority"
ExecStart=/usr/bin/python3 /usr/sbin/test_graphic_app.py
KillSignal=SIGINT
SuccessExitStatus=SIGINT
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=test_graphic_app
Restart=on-failure
[Install]
WantedBy=default.target
However this obviously doesn't work if I log using another user or if I run it locally on my laptop cause the user launching X is not pi
I would like to dynamically get the .Xauthority file location on the system.
I've tried using sudo xauth info | grep Authority | awk 'print $3' as follow
Environment="XAUTHORITY=$(/usr/bin/xauth info | grep Authority | awk 'print $3')"
ExecStartPre=/bin/bash -c 'export XAUTHORITY=$XAUTHORITY'
However if the command works on my laptop, it doesn't on the pi
## On laptop ##
$ sudo xauth info | grep "Authority file" | awk 'print $3'
/run/user/1000/gdm/Xauthority
## On pi ##
$ sudo xauth info | grep "Authority file" | awk 'print $3'
xauth: file /root/.Xauthority does not exist
/root/.Xauthority
I was unable find how to get the .Xauthority file location depending on the user that have launched the X server instance. Also, I don't want to allow any user to use X display doing xhost +
How can I get the location within my systemd unit?
Is there any better solution other than finding the .Xauthority location?
systemd python raspberry-pi x-server xauth
I'm currently using a systemd unit file to configure a service which uses X server display.
The X server instance is launched by the user logged in (currently pi user) but the service is launched at root.
I can successfully launch the service using systemctl start test_graphic_app if I hard code the .Xauthority file location into XAUTHORITY variable from the unit file as follow
[Unit]
Description=Test Graphic App
After=multi-user.target
[Service]
Type=simple
User=root
Group=root
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/pi/.Xauthority"
ExecStart=/usr/bin/python3 /usr/sbin/test_graphic_app.py
KillSignal=SIGINT
SuccessExitStatus=SIGINT
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=test_graphic_app
Restart=on-failure
[Install]
WantedBy=default.target
However this obviously doesn't work if I log using another user or if I run it locally on my laptop cause the user launching X is not pi
I would like to dynamically get the .Xauthority file location on the system.
I've tried using sudo xauth info | grep Authority | awk 'print $3' as follow
Environment="XAUTHORITY=$(/usr/bin/xauth info | grep Authority | awk 'print $3')"
ExecStartPre=/bin/bash -c 'export XAUTHORITY=$XAUTHORITY'
However if the command works on my laptop, it doesn't on the pi
## On laptop ##
$ sudo xauth info | grep "Authority file" | awk 'print $3'
/run/user/1000/gdm/Xauthority
## On pi ##
$ sudo xauth info | grep "Authority file" | awk 'print $3'
xauth: file /root/.Xauthority does not exist
/root/.Xauthority
I was unable find how to get the .Xauthority file location depending on the user that have launched the X server instance. Also, I don't want to allow any user to use X display doing xhost +
How can I get the location within my systemd unit?
Is there any better solution other than finding the .Xauthority location?
systemd python raspberry-pi x-server xauth
systemd python raspberry-pi x-server xauth
edited Sep 16 at 16:01
Goro
5,87052662
5,87052662
asked Sep 16 at 15:45
Arkaik
274217
274217
The easy solution is not to launch your service at boot, but launch it when this particular user logs in. Or use a display manager, which will launch the X server, and launch the service once the X server is up. Trying to start your service before there is any X server it can connect is broken, no matter how many workarounds you try. If the service does anything important which you need at boot, split it into a non-graphical and a graphical part.
â dirkt
Sep 17 at 6:28
I'm using autolog on the raspberry pi anddefault.targetis set to graphical runlevel, so the service start after X has been launched.
â Arkaik
Sep 18 at 8:06
add a comment |Â
The easy solution is not to launch your service at boot, but launch it when this particular user logs in. Or use a display manager, which will launch the X server, and launch the service once the X server is up. Trying to start your service before there is any X server it can connect is broken, no matter how many workarounds you try. If the service does anything important which you need at boot, split it into a non-graphical and a graphical part.
â dirkt
Sep 17 at 6:28
I'm using autolog on the raspberry pi anddefault.targetis set to graphical runlevel, so the service start after X has been launched.
â Arkaik
Sep 18 at 8:06
The easy solution is not to launch your service at boot, but launch it when this particular user logs in. Or use a display manager, which will launch the X server, and launch the service once the X server is up. Trying to start your service before there is any X server it can connect is broken, no matter how many workarounds you try. If the service does anything important which you need at boot, split it into a non-graphical and a graphical part.
â dirkt
Sep 17 at 6:28
The easy solution is not to launch your service at boot, but launch it when this particular user logs in. Or use a display manager, which will launch the X server, and launch the service once the X server is up. Trying to start your service before there is any X server it can connect is broken, no matter how many workarounds you try. If the service does anything important which you need at boot, split it into a non-graphical and a graphical part.
â dirkt
Sep 17 at 6:28
I'm using autolog on the raspberry pi and
default.target is set to graphical runlevel, so the service start after X has been launched.â Arkaik
Sep 18 at 8:06
I'm using autolog on the raspberry pi and
default.target is set to graphical runlevel, so the service start after X has been launched.â Arkaik
Sep 18 at 8:06
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
There are more sophisticated versions of xhost +, namely xhost +si:localuser:root which adds only local user root to the list of allowed connections.
You need to find where to put this command so it is run on login, depending on your distribution. Look in /etc/X11/ for an existing file using xhost already. On my pi I found it in /etc/X11/Xsession.d/35x11-common_xhost-local:
if type xhost >/dev/null 2>&1; then
xhost +si:localuser:$(id -un) || :
fi
On another system it was in /etc/X11/xinit/xinitrc.d/localuser.sh.
Do you know a way to do it permanently so I just have to run it at install ?
â Arkaik
Sep 16 at 16:24
I'm not sure what you mean. Just create a shell script file with a name like35-add-root-xhostin the appropriate directory, with the new extra xhost command in it, and make sure it is executable. It will be run at each login.
â meuh
Sep 16 at 17:58
My issue is that I will deploy the app on several linux systems using an install script so I'm looking for a way to allow root to connect X (withxhost +si:localuser:rootfor example) but permanently with one command ran at install. The script would be nice if the location were always the same on the system.
â Arkaik
Sep 16 at 20:15
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
There are more sophisticated versions of xhost +, namely xhost +si:localuser:root which adds only local user root to the list of allowed connections.
You need to find where to put this command so it is run on login, depending on your distribution. Look in /etc/X11/ for an existing file using xhost already. On my pi I found it in /etc/X11/Xsession.d/35x11-common_xhost-local:
if type xhost >/dev/null 2>&1; then
xhost +si:localuser:$(id -un) || :
fi
On another system it was in /etc/X11/xinit/xinitrc.d/localuser.sh.
Do you know a way to do it permanently so I just have to run it at install ?
â Arkaik
Sep 16 at 16:24
I'm not sure what you mean. Just create a shell script file with a name like35-add-root-xhostin the appropriate directory, with the new extra xhost command in it, and make sure it is executable. It will be run at each login.
â meuh
Sep 16 at 17:58
My issue is that I will deploy the app on several linux systems using an install script so I'm looking for a way to allow root to connect X (withxhost +si:localuser:rootfor example) but permanently with one command ran at install. The script would be nice if the location were always the same on the system.
â Arkaik
Sep 16 at 20:15
add a comment |Â
up vote
2
down vote
There are more sophisticated versions of xhost +, namely xhost +si:localuser:root which adds only local user root to the list of allowed connections.
You need to find where to put this command so it is run on login, depending on your distribution. Look in /etc/X11/ for an existing file using xhost already. On my pi I found it in /etc/X11/Xsession.d/35x11-common_xhost-local:
if type xhost >/dev/null 2>&1; then
xhost +si:localuser:$(id -un) || :
fi
On another system it was in /etc/X11/xinit/xinitrc.d/localuser.sh.
Do you know a way to do it permanently so I just have to run it at install ?
â Arkaik
Sep 16 at 16:24
I'm not sure what you mean. Just create a shell script file with a name like35-add-root-xhostin the appropriate directory, with the new extra xhost command in it, and make sure it is executable. It will be run at each login.
â meuh
Sep 16 at 17:58
My issue is that I will deploy the app on several linux systems using an install script so I'm looking for a way to allow root to connect X (withxhost +si:localuser:rootfor example) but permanently with one command ran at install. The script would be nice if the location were always the same on the system.
â Arkaik
Sep 16 at 20:15
add a comment |Â
up vote
2
down vote
up vote
2
down vote
There are more sophisticated versions of xhost +, namely xhost +si:localuser:root which adds only local user root to the list of allowed connections.
You need to find where to put this command so it is run on login, depending on your distribution. Look in /etc/X11/ for an existing file using xhost already. On my pi I found it in /etc/X11/Xsession.d/35x11-common_xhost-local:
if type xhost >/dev/null 2>&1; then
xhost +si:localuser:$(id -un) || :
fi
On another system it was in /etc/X11/xinit/xinitrc.d/localuser.sh.
There are more sophisticated versions of xhost +, namely xhost +si:localuser:root which adds only local user root to the list of allowed connections.
You need to find where to put this command so it is run on login, depending on your distribution. Look in /etc/X11/ for an existing file using xhost already. On my pi I found it in /etc/X11/Xsession.d/35x11-common_xhost-local:
if type xhost >/dev/null 2>&1; then
xhost +si:localuser:$(id -un) || :
fi
On another system it was in /etc/X11/xinit/xinitrc.d/localuser.sh.
answered Sep 16 at 16:14
meuh
30.2k11752
30.2k11752
Do you know a way to do it permanently so I just have to run it at install ?
â Arkaik
Sep 16 at 16:24
I'm not sure what you mean. Just create a shell script file with a name like35-add-root-xhostin the appropriate directory, with the new extra xhost command in it, and make sure it is executable. It will be run at each login.
â meuh
Sep 16 at 17:58
My issue is that I will deploy the app on several linux systems using an install script so I'm looking for a way to allow root to connect X (withxhost +si:localuser:rootfor example) but permanently with one command ran at install. The script would be nice if the location were always the same on the system.
â Arkaik
Sep 16 at 20:15
add a comment |Â
Do you know a way to do it permanently so I just have to run it at install ?
â Arkaik
Sep 16 at 16:24
I'm not sure what you mean. Just create a shell script file with a name like35-add-root-xhostin the appropriate directory, with the new extra xhost command in it, and make sure it is executable. It will be run at each login.
â meuh
Sep 16 at 17:58
My issue is that I will deploy the app on several linux systems using an install script so I'm looking for a way to allow root to connect X (withxhost +si:localuser:rootfor example) but permanently with one command ran at install. The script would be nice if the location were always the same on the system.
â Arkaik
Sep 16 at 20:15
Do you know a way to do it permanently so I just have to run it at install ?
â Arkaik
Sep 16 at 16:24
Do you know a way to do it permanently so I just have to run it at install ?
â Arkaik
Sep 16 at 16:24
I'm not sure what you mean. Just create a shell script file with a name like
35-add-root-xhost in the appropriate directory, with the new extra xhost command in it, and make sure it is executable. It will be run at each login.â meuh
Sep 16 at 17:58
I'm not sure what you mean. Just create a shell script file with a name like
35-add-root-xhost in the appropriate directory, with the new extra xhost command in it, and make sure it is executable. It will be run at each login.â meuh
Sep 16 at 17:58
My issue is that I will deploy the app on several linux systems using an install script so I'm looking for a way to allow root to connect X (with
xhost +si:localuser:root for example) but permanently with one command ran at install. The script would be nice if the location were always the same on the system.â Arkaik
Sep 16 at 20:15
My issue is that I will deploy the app on several linux systems using an install script so I'm looking for a way to allow root to connect X (with
xhost +si:localuser:root for example) but permanently with one command ran at install. The script would be nice if the location were always the same on the system.â Arkaik
Sep 16 at 20:15
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f469402%2fsystemd-find-xauthority-file-to-use%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
The easy solution is not to launch your service at boot, but launch it when this particular user logs in. Or use a display manager, which will launch the X server, and launch the service once the X server is up. Trying to start your service before there is any X server it can connect is broken, no matter how many workarounds you try. If the service does anything important which you need at boot, split it into a non-graphical and a graphical part.
â dirkt
Sep 17 at 6:28
I'm using autolog on the raspberry pi and
default.targetis set to graphical runlevel, so the service start after X has been launched.â Arkaik
Sep 18 at 8:06