You are not logged in.
I have a service (say foo.service), of type simple (or forking, for that matter).
I wan't this service to be started every time when my notebook is connected to the power supply, and to be stopped again once it goes back to battery mode.
I know of ConditionACPower=, but this only checks once on the startup of the unit if the power is connected, and does not help triggering the unit in the first place.
Is there a way to achieve this? If not using systemd, then at least in some other way (e.g. calling a specific executable on AC Power events)?
Last edited by jobach (2016-04-24 23:50:47)
Offline
This sounds like an xy problem. How about you detail what you are trying to accomplish and why? Perhaps we can set you in a better direction?
Offline
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
I'm using the i3 window manager, and am expirencing some problems with tearing (see https://wiki.archlinux.org/index.php/I3#Tearing). As the wiki page suggests, Compton helps with that. However, compton increases my CPU load (not much admittedly, but it bugged me anyway). So I only wan't it to run when the power supply is connected.
I now have acpid start a systemd target I created, like this:
/etc/acpi/handler.sh
----------------------------
#!/bin/bash
[...]
case "$4" in
00000000)
logger 'AC unpluged'
systemctl stop ac-power.target
;;
00000001)
logger 'AC pluged'
systemctl start ac-power.target
;;
*)
logger "Don't know what to do: $4"
;;
esac
[...]
The target looks like this:
/etc/systemd/system/ac-power.target
---------------------------------------------------
[Unit]
Description=AC-only services
And the compton-services:
/etc/systemd/system/compton.service
[Unit]
Description=Compton - a compositor for X11
PartOf=ac-power.target
[Service]
Environment="DISPLAY=:0"
User=jobach
ExecStart=/usr/bin/compton [...]
[Install]
WantedBy=ac-power.target
The PartOf= is needed, so the service get's stopped once the targret is stopped (StopWhenUnneeded= might also work).
Last edited by jobach (2016-04-24 23:07:33)
Offline
So, is it solved? If so, please prepend [SOLVED] to your thread title. Thanks.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
Great to hear acpid has solved this for you. A method without acpid could be to utilize udev rules to run a script to start compton when ac is detected and kill compton when ac is unplugged.
Offline