You are not logged in.

#1 2014-06-27 04:50:49

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

[SOLVED]Correct way to restart a systemd service on resume from susp?

I have offlineimap setup to run as a daemon. It doesn't correctly resume operations after a resume from suspend to RAM without being restarted. The 'Conflicts=' line in the service file makes sure it is stopped when the machine suspends, but I can't figure out how to get it restarted again. Here is the service file:

[Unit]
Description=Start offlineimap as a daemon
Requires=network.target
Conflicts=suspend.target
After=network.target 

[Service]
User=%i
EnvironmentFile=/home/%i/.gnupg/gpg-agent-info
ExecStart=/usr/bin/offlineimap
KillSignal=SIGUSR2
Restart=always
RestartSec=15

[Install]
WantedBy=multi-user.target

I found an email thread here that seemed to imply that I could add sleep.target to 'WantedBy=' and sleep.target to 'After=' to get service to startup again after resume, but that didn't seem to work.

Any ideas? Thanks!

Scott

Last edited by firecat53 (2014-07-01 16:40:20)

Offline

#2 2014-06-27 11:08:04

Rexilion
Member
Registered: 2013-12-23
Posts: 784

Re: [SOLVED]Correct way to restart a systemd service on resume from susp?

I think that by using Conflicts= will cause the service to be semi-permanently disabled. I take it you used 'Conflicts=sleep.target' and 'WantedBy=sleep.target' which is a conflict in itself.

Ditch the conflict method and use a WantedBy for both a start and stop service of offlineimap. So you have three services:
- one handles offlineimap
- one handles stopping offlineimap before suspend
- one handles starrting offlineimap after suspend

That is the best I can come up with. Would be nice if a feature exists that would do this for you...


fs/super.c : "Self-destruct in 5 seconds.  Have a nice day...\n",

Offline

#3 2014-06-27 20:39:57

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED]Correct way to restart a systemd service on resume from susp?

More information here on Lennart's thoughts about a resume.target. Also based on that thread and my own existing resume/suspend services, I went ahead and created offlineimap-resume@.service:

[Unit]
Description=Restart offlineimap after resume
After=suspend.target

[Service]
Type=simple
ExecStart=/usr/bin/systemctl --no-block restart offlineimap@%i.service

[Install]
WantedBy=suspend.target

So, I'll mark this as solved. If anyone has a better/cleaner approach that actually uses only the service/unit file directives to accomplish this within a single service file, please let me know!

Thanks,
Scott

Offline

#4 2014-06-27 22:35:30

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: [SOLVED]Correct way to restart a systemd service on resume from susp?

firecat53 wrote:

It doesn't correctly resume operations after a resume from suspend to RAM without being restarted.

Is this just something you have observed on your own system, or is it a known bug?

Offline

#5 2014-06-27 22:53:41

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED]Correct way to restart a systemd service on resume from susp?

tomk wrote:
firecat53 wrote:

It doesn't correctly resume operations after a resume from suspend to RAM without being restarted.

Is this just something you have observed on your own system, or is it a known bug?

Something I noticed and figured it was just due to frequently switching networks with VPN on/off again. After a quick search, I discovered the 'socktimeout' option, which I'm testing now to see if that solves the problem. It appears (although I _just_  found this, that it is a known bug. Some have had luck with setting socktimeout, others haven't. I'll post back if I see a difference or not.

Thanks for the nudge smile
Scott

Offline

#6 2014-07-01 16:39:49

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [SOLVED]Correct way to restart a systemd service on resume from susp?

Well after several days of testing, offlineimap as a daemon is working great through suspend-resume cycles with no stop-restart systemd trickery required. I'm not sure if the socktimeout made the difference, or if I just didn't test it enough at first.

Scott

Offline

#7 2022-11-19 06:43:39

mikael
Member
From: Slovakia
Registered: 2011-05-22
Posts: 28
Website

Re: [SOLVED]Correct way to restart a systemd service on resume from susp?

Offline

Board footer

Powered by FluxBB