You are not logged in.

#1 2014-04-07 05:32:36

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

systemd: starting service after graphical target without

Hi there,

I have a service that I want to start after X has been started.

This is my service file:

[Unit]
Description=Run powersaving script depending on AC state
After=graphical.target

[Service]
Type=oneshot
KillMode=none
ExecStart=/usr/bin/powersaving

[Install]
WantedBy=multi-user.target

However, during boot I get the following error message:

~ systemctl status powersaving
● powersaving.service - Run powersaving script depending on AC state
   Loaded: loaded (/usr/lib/systemd/system/powersaving.service; enabled)
   Active: inactive (dead)

Apr 07 07:16:14 thinkpad systemd[1]: Found ordering cycle on powersaving.service/start
Apr 07 07:16:14 thinkpad systemd[1]: Found dependency on graphical.target/start
Apr 07 07:16:14 thinkpad systemd[1]: Found dependency on multi-user.target/start
Apr 07 07:16:14 thinkpad systemd[1]: Found dependency on powersaving.service/start
Apr 07 07:16:17 thinkpad systemd[1]: Found ordering cycle on powersaving.service/start
Apr 07 07:16:17 thinkpad systemd[1]: Found dependency on graphical.target/start
Apr 07 07:16:17 thinkpad systemd[1]: Found dependency on multi-user.target/start
Apr 07 07:16:17 thinkpad systemd[1]: Found dependency on powersaving.service/start
~ dmesg | grep powersaving
[    7.492597] systemd[1]: Found dependency on powersaving.service/start
[    7.492604] systemd[1]: Breaking ordering cycle by deleting job powersaving.service/start
[    7.492608] systemd[1]: Job powersaving.service/start deleted to break ordering cycle starting with graphical.target/start

I found this thread which suggests to use display-manager.service instead of the graphical target.

However, I start X manually using startx and no display-manager.

So how can I run my service after starting of X without a display-manager?

Thanks!

Offline

#2 2014-04-07 07:15:05

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: systemd: starting service after graphical target without

If you start X manually with startx; then you use the multi-user.target, graphical.target start a display manager. After launching X startx execute ~/.xinitrc to start your X session. Put your command there.

Last edited by olive (2014-04-07 07:50:26)

Offline

#3 2014-04-07 08:13:01

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: systemd: starting service after graphical target without

Thanks olive!

I cannot just put the content of my script which is started by the systemd service into .xinitrc because it requires root priviliges.

But good to know that the graphical.target relates to a display-manager.

So, you advise me to use the multi-user.target instead like that?

[Unit]
Description=Run powersaving script depending on AC state
After=multi-user.target

[Service]
Type=oneshot
KillMode=none
ExecStart=/usr/bin/powersaving

[Install]
WantedBy=multi-user.target

Is the service then really just started after launching X or not already when logging in into tty?

Offline

#4 2014-04-07 08:23:54

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: systemd: starting service after graphical target without

I don't think your new version will work. Your new version will make your service part of multi-user.target and started after multi-user.target; so you are asking systemd to start your service after itself. In any case such attempts will start the service before startx. startx is a command that you run as an ordinary user, X has the special privilege to get root access (it has the suid bit set) and systemd is not involved in the process. I do not think that you can tell systemd to start a service after a command that you launch by hand; and I don' think it's the purpose of systemd. You are really asking to launch a daemon that needs root access as part of a command that you run as an ordinary user. One of the solution is to use sudo and put sudo /usr/bin/powersaving into ~/.xinitrc after having properly configured sudo.

Last edited by olive (2014-04-07 08:34:32)

Offline

Board footer

Powered by FluxBB