systemd restart service on resume
woods at ucar.edu
Sun Dec 8 17:14:25 UTC 2013
I am trying to find a way to get a service to restart when the system is
resumed from suspend or hibernation. I can get something to run when the
system is put to sleep by using sleep.target (for example, I have an
"ssh-suspend" service that kills all the ssh sessions because they are
always hung after a resume and I have to close the windows manually
anyway), but I haven't figured out the exact incantation to get a
service to restart on resume. Saying "After=sleep.target" has not
worked, and there doesn't seem to be anything like a resume.target or
wakeup.target . Here's an example service file:
Description=Restart IPSEC tunnel on resume
ExecStart=/usr/bin/systemctl restart racoon
(I have tried it both with and without the Install section).
This service never runs:
# systemctl status racoon-resume.service
racoon-resume.service - Restart IPSEC tunnel on resume
Loaded: loaded (/etc/systemd/system/racoon-resume.service; enabled)
Active: active (exited) since Sat 2013-11-23 18:29:48 MST; 2 weeks 0
Main PID: 2605 (code=exited, status=0/SUCCESS)
Nov 23 18:29:48 cobweb.gregandeva.net systemd: Starting Restart IPSEC
tunnel on resume...
Nov 23 18:29:48 cobweb.gregandeva.net systemd: Started Restart IPSEC
tunnel on resume.
That was from when I tested it manually. So how to I program it to
restart a service upon resume?
The real problem is that the racoon daemon (which negotiates IKE keys
for an IPSEC tunnel) stops working after a suspend/resume, and needs to
be restarted on resume in order for the tunnel to work again.
I have this service file that starts and stops the tunnel at
boot/shutdown time, and this works fine:
Description=IPSEC Tunnel Service
More information about the users