Is it possible to configure a systemd service to start or stop using a custom keyboard shortcut?

As an example, systemd has a special target "ctrl-alt-del.target" that allows a service to be bound to it. So I think there is a way to create my own systemd targets with custom keybindings but I was not able to find anything about it. In fact I need something "low level" that is able to launch a process (as root) whatever the running software stack (bash, xorg, fullscreen app etc..)

closed as unclear what you're asking by Jeff Schaller, user259412, jasonwryan, jimmij, Archemar Nov 24 '17 at 12:07

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • With most window managers you can run arbitrary commands with key bindings, so you can start and stop processes. For example in gnome, or lxde. You might need to use sudo to give yourself permissions. – Att Righ Nov 23 '17 at 14:13
  • Thanks but i would need a solution that works in a non graphical environment. – sgt-hartman Nov 23 '17 at 14:16
  • Umm, so the issue is you need something to catch the keybindings. I know that zsh can run arbitrary functions in response to keybindings. I don't use this feature in bash so I'm not so sure. I don't know about the kernels ability to handle keybindings. – Att Righ Nov 23 '17 at 14:19
  • Right. i'll edit my question to add more precisions – sgt-hartman Nov 23 '17 at 14:26
  • ctrl-alt-del.target So I was looking at this and it seems to be a magic built-in rather than a keybinding 1. I don't know how switching virtual terminals though. – Att Righ Nov 23 '17 at 14:33

So, pretty convinced this feature didn't exist i sent a feature request on systemd github page: https://github.com/systemd/systemd/issues/7452

Quick answer was "won't implement" for pretty good reasons i suppose.

As a workaround a small daemonized script that listens to keyboard events should not be hard to implement. "inputexec" seems to simply do that but i have not tested it yet: https://github.com/rbarrois/inputexec

Not the answer you're looking for? Browse other questions tagged or ask your own question.