You are not logged in.

#1 2015-09-18 13:00:11

satori
Member
Registered: 2013-01-21
Posts: 29

[SOLVED]Systemd - how to write a service started only if NOT running X

Hello,

I've created a systemd user unit that is started on boot.
It uses actkbd for detecting keyboard shortcuts and launching custom commands when I'm working in console.

~/.config/systemd/user/actkbd.service

[Unit]
Description=Actkbd: Daemon for X-independent shortcuts

[Service]
Type=forking
ExecStart=/usr/bin/actkbd -c /home/adam/.config/actkbd.conf -d /dev/input/event2 -D -p /home/adam/tmp/actkbd_pid
PIDFile=/home/adam/tmp/actkbd_pid

[Install]
WantedBy=default.target

It works fine but I would like it to start only when no X server is running, since I'm using xbindkeys under X and mappings for certain keys overlap, making them unusable.
I thought about using Conflicts= under [Install] section but I cannot find appropriate target - such which is active while X runs and inactive when only in console.

I'm not running X as a systemd user service.

Do you have any hints?

Last edited by satori (2015-09-25 07:23:51)

Offline

#2 2015-09-18 13:13:46

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

Re: [SOLVED]Systemd - how to write a service started only if NOT running X

satori wrote:

I thought about using Conflicts= under [Install] section but I cannot find appropriate target - such which is active while X runs and inactive when only in console.

Then define one -- you're not going to find preinstalled units for every possible use case. Just like you created a service unit for actkbd, you can define a target for X and start that from ~/.xinitrc or a similar startup script. Or if you have a service unit for xbindkeys (started similarly), make actkbd.service conflict with that unit.

Edit: Conflicts= belongs in the [Unit] section.

Last edited by Raynman (2015-09-18 13:14:21)

Offline

#3 2015-09-18 13:39:59

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,548
Website

Re: [SOLVED]Systemd - how to write a service started only if NOT running X

satori wrote:

I would like it to start only when no X server is running

What does this mean?  If you can operationally define this, you'll likely be 99% of the way to the solution.

No X server is running while the system boots - even if one will be running shortly afterwards.  Should your service then start on every boot because there is no X server running?  What if X is running and you exit X, do you want your service to start?  What if your service is running and you start X, do you want your service to stop?  How do you start X, and how would a service file (or any other programmed system) be able to anticipate if/when you are going to start X?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2015-09-25 07:20:26

satori
Member
Registered: 2013-01-21
Posts: 29

Re: [SOLVED]Systemd - how to write a service started only if NOT running X

Thank you both for pointing me at the right direction.

However, after analyzing my typical use scenario, I decided to keep it simple:
- the actkbd service is started during each boot, as in original post
- in .xinitrc I simply stop the service

This is not exactly an answer for original question but I'll mark this thread as solved.

Last edited by satori (2015-09-25 07:23:13)

Offline

Board footer

Powered by FluxBB