I'm trying to have a service restart itself on system resume. This is my the .service
file:
[Unit]
Description=Set the battery charge threshold
After=multi-user.target
After=sleep.target
StartLimitBurst=0
[Service]
Type=oneshot
Restart=on-failure
ExecStart=/bin/bash -c 'echo 60 > /sys/class/power_supply/BAT1/charge_control_end_threshold'
[Install]
WantedBy=multi-user.target
WantedBy=sleep.target
I've set WantedBy
and After
to sleep.target
with the hopes that this service will be run after sleep.target
is run. However, the service is started just before being putting to sleep instead of on resume. Is this a known bug? Or am I doing something wrong?
I'd also like it to run after resuming from suspend (i.e hibernation). But suspend.target pulls in sleep.target, so fixing this issue ought to allow this to on resume-from-suspend.
I know similar questions exist, however none of the solutions there work (specifically setting WantedBy
and After
).
PS: Please don't recommend using bash scripts placed in specific folders. Those seem too clunky for my use case and I'd like a simpler solution first instead.