systemd restart service on resume

Greg Woods woods at
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 (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 "" has not
worked, and there doesn't seem to be anything like a or . Here's an example service file:

Description=Restart IPSEC tunnel on resume NetworkManager-wait-online.service

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
days ago
 Main PID: 2605 (code=exited, status=0/SUCCESS)
   CGroup: name=systemd:/system/racoon-resume.service

Nov 23 18:29:48 systemd[1]: Starting Restart IPSEC
tunnel on resume...
Nov 23 18:29:48 systemd[1]: 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

ExecStop=/usr/bin/pkill racoon
ExecStopPost=/usr/sbin/setkey -FP



More information about the users mailing list