Setting DISPLAY in systemd service file
Clash Royale CLAN TAG#URR8PPP
up vote
7
down vote
favorite
I'm trying to learn systemd services by trying to start xclock as a service; the service file is below
[Unit]
Description=clock
[Service]
Environment=DISPLAY=:0
ExecStart=/usr/bin/xclock
[Install]
WantedBy=graphical.target
Any ideas what's wrong here? I'm getting an error saying "cannot connect to display."
opensuse systemd
add a comment |
up vote
7
down vote
favorite
I'm trying to learn systemd services by trying to start xclock as a service; the service file is below
[Unit]
Description=clock
[Service]
Environment=DISPLAY=:0
ExecStart=/usr/bin/xclock
[Install]
WantedBy=graphical.target
Any ideas what's wrong here? I'm getting an error saying "cannot connect to display."
opensuse systemd
add a comment |
up vote
7
down vote
favorite
up vote
7
down vote
favorite
I'm trying to learn systemd services by trying to start xclock as a service; the service file is below
[Unit]
Description=clock
[Service]
Environment=DISPLAY=:0
ExecStart=/usr/bin/xclock
[Install]
WantedBy=graphical.target
Any ideas what's wrong here? I'm getting an error saying "cannot connect to display."
opensuse systemd
I'm trying to learn systemd services by trying to start xclock as a service; the service file is below
[Unit]
Description=clock
[Service]
Environment=DISPLAY=:0
ExecStart=/usr/bin/xclock
[Install]
WantedBy=graphical.target
Any ideas what's wrong here? I'm getting an error saying "cannot connect to display."
opensuse systemd
opensuse systemd
edited Oct 16 '16 at 13:10
Jeff Schaller
36k952119
36k952119
asked Aug 1 '13 at 21:57
dogs
3813
3813
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
14
down vote
accepted
An application needs two things to open a window on an X display. It needs to know the location of the X display; that's conveyed by the DISPLAY
environment variable. It also needs to authenticate with the X server. This is conveyed through a cookie, which is a secret value generated by the X server when it starts and stored in a file that only the user who started the X server can access. The default cookie file is ~/.Xauthority
.
If your X server is using the default cookie file location, then adding Environment=XAUTHORITY=/home/dogs/.Xauthority
will work (assuming /home/dogs
is the home directory of the user who is logged in under X). If you need to find the location, see Can I launch a graphical program on another user's desktop as root? and Open a window on a remote X display (why “Cannot open display”)?
Alternatively, running the program as the user who is running the X server will work, provided that the cookie file is in the default location (if not, you'll have to locate the cookie file, like in the root case). Add the User
directive (e.g. User=dogs
).
Of course the service won't run if there isn't an X display by that number owned by the user you specify.
It's rather bizarre to start a GUI program from Systemd. It wasn't designed for this. GUI programs live in an X session, started by a user. Systemd is for system processes. You should experiment with daemons instead.
add a comment |
up vote
-2
down vote
You can add in .xinitrc
:
xhost si:localuser:$USER
It works for me!
1
this is for systemd service files, not .xinitrc
– slang
Sep 28 '15 at 20:59
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
14
down vote
accepted
An application needs two things to open a window on an X display. It needs to know the location of the X display; that's conveyed by the DISPLAY
environment variable. It also needs to authenticate with the X server. This is conveyed through a cookie, which is a secret value generated by the X server when it starts and stored in a file that only the user who started the X server can access. The default cookie file is ~/.Xauthority
.
If your X server is using the default cookie file location, then adding Environment=XAUTHORITY=/home/dogs/.Xauthority
will work (assuming /home/dogs
is the home directory of the user who is logged in under X). If you need to find the location, see Can I launch a graphical program on another user's desktop as root? and Open a window on a remote X display (why “Cannot open display”)?
Alternatively, running the program as the user who is running the X server will work, provided that the cookie file is in the default location (if not, you'll have to locate the cookie file, like in the root case). Add the User
directive (e.g. User=dogs
).
Of course the service won't run if there isn't an X display by that number owned by the user you specify.
It's rather bizarre to start a GUI program from Systemd. It wasn't designed for this. GUI programs live in an X session, started by a user. Systemd is for system processes. You should experiment with daemons instead.
add a comment |
up vote
14
down vote
accepted
An application needs two things to open a window on an X display. It needs to know the location of the X display; that's conveyed by the DISPLAY
environment variable. It also needs to authenticate with the X server. This is conveyed through a cookie, which is a secret value generated by the X server when it starts and stored in a file that only the user who started the X server can access. The default cookie file is ~/.Xauthority
.
If your X server is using the default cookie file location, then adding Environment=XAUTHORITY=/home/dogs/.Xauthority
will work (assuming /home/dogs
is the home directory of the user who is logged in under X). If you need to find the location, see Can I launch a graphical program on another user's desktop as root? and Open a window on a remote X display (why “Cannot open display”)?
Alternatively, running the program as the user who is running the X server will work, provided that the cookie file is in the default location (if not, you'll have to locate the cookie file, like in the root case). Add the User
directive (e.g. User=dogs
).
Of course the service won't run if there isn't an X display by that number owned by the user you specify.
It's rather bizarre to start a GUI program from Systemd. It wasn't designed for this. GUI programs live in an X session, started by a user. Systemd is for system processes. You should experiment with daemons instead.
add a comment |
up vote
14
down vote
accepted
up vote
14
down vote
accepted
An application needs two things to open a window on an X display. It needs to know the location of the X display; that's conveyed by the DISPLAY
environment variable. It also needs to authenticate with the X server. This is conveyed through a cookie, which is a secret value generated by the X server when it starts and stored in a file that only the user who started the X server can access. The default cookie file is ~/.Xauthority
.
If your X server is using the default cookie file location, then adding Environment=XAUTHORITY=/home/dogs/.Xauthority
will work (assuming /home/dogs
is the home directory of the user who is logged in under X). If you need to find the location, see Can I launch a graphical program on another user's desktop as root? and Open a window on a remote X display (why “Cannot open display”)?
Alternatively, running the program as the user who is running the X server will work, provided that the cookie file is in the default location (if not, you'll have to locate the cookie file, like in the root case). Add the User
directive (e.g. User=dogs
).
Of course the service won't run if there isn't an X display by that number owned by the user you specify.
It's rather bizarre to start a GUI program from Systemd. It wasn't designed for this. GUI programs live in an X session, started by a user. Systemd is for system processes. You should experiment with daemons instead.
An application needs two things to open a window on an X display. It needs to know the location of the X display; that's conveyed by the DISPLAY
environment variable. It also needs to authenticate with the X server. This is conveyed through a cookie, which is a secret value generated by the X server when it starts and stored in a file that only the user who started the X server can access. The default cookie file is ~/.Xauthority
.
If your X server is using the default cookie file location, then adding Environment=XAUTHORITY=/home/dogs/.Xauthority
will work (assuming /home/dogs
is the home directory of the user who is logged in under X). If you need to find the location, see Can I launch a graphical program on another user's desktop as root? and Open a window on a remote X display (why “Cannot open display”)?
Alternatively, running the program as the user who is running the X server will work, provided that the cookie file is in the default location (if not, you'll have to locate the cookie file, like in the root case). Add the User
directive (e.g. User=dogs
).
Of course the service won't run if there isn't an X display by that number owned by the user you specify.
It's rather bizarre to start a GUI program from Systemd. It wasn't designed for this. GUI programs live in an X session, started by a user. Systemd is for system processes. You should experiment with daemons instead.
edited Apr 13 '17 at 12:36
Community♦
1
1
answered Aug 2 '13 at 0:24
Gilles
520k12610391569
520k12610391569
add a comment |
add a comment |
up vote
-2
down vote
You can add in .xinitrc
:
xhost si:localuser:$USER
It works for me!
1
this is for systemd service files, not .xinitrc
– slang
Sep 28 '15 at 20:59
add a comment |
up vote
-2
down vote
You can add in .xinitrc
:
xhost si:localuser:$USER
It works for me!
1
this is for systemd service files, not .xinitrc
– slang
Sep 28 '15 at 20:59
add a comment |
up vote
-2
down vote
up vote
-2
down vote
You can add in .xinitrc
:
xhost si:localuser:$USER
It works for me!
You can add in .xinitrc
:
xhost si:localuser:$USER
It works for me!
edited 2 days ago
GAD3R
24.3k1749103
24.3k1749103
answered Jul 17 '15 at 10:40
Monica
1
1
1
this is for systemd service files, not .xinitrc
– slang
Sep 28 '15 at 20:59
add a comment |
1
this is for systemd service files, not .xinitrc
– slang
Sep 28 '15 at 20:59
1
1
this is for systemd service files, not .xinitrc
– slang
Sep 28 '15 at 20:59
this is for systemd service files, not .xinitrc
– slang
Sep 28 '15 at 20:59
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f85244%2fsetting-display-in-systemd-service-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown