You are not logged in.

#1 2015-08-26 13:02:26

Kotrfa
Member
Registered: 2012-10-25
Posts: 213

systemd unit start on network.target and restart on suspend.target

Hello,

I wan't to make my systemd unit to be started after network.target, but restarted on resuming laptop from sleep. Is this possible? I tried the following but that do not work. Mainly because unit do not fail after resuming, but the daemon just doesn't work. Is there a way how to enforce the restart without needing another unit, which would restart this one?

$ /etc/systemd/user/create_ap_givehug.service

[Unit]
Description=Create an AP 
After=network.target suspend.target

[Service]
Type=simple
ExecStart=/usr/bin/bash /root/scripts/create_an_ap
KillSignal=SIGINT
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

Thank you

Last edited by Kotrfa (2015-08-26 16:24:23)

Offline

#2 2015-08-27 08:15:09

seqizz
Member
Registered: 2011-04-04
Posts: 37

Re: systemd unit start on network.target and restart on suspend.target

I think an example from tlp-sleep.service file will help you. From what I understand, this runs execstart before sleep and runs execstop when waking up :

# tlp - systemd suspend/resume service
#
# Copyright (c) 2015 Thomas Koch <linrunner at gmx.net>
# This software is licensed under the GPL v2 or later.

[Unit]
Description=TLP suspend/resume
Before=sleep.target
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/tlp suspend
ExecStop=/usr/bin/tlp resume

[Install]
WantedBy=sleep.target

Creeds matter very little… The optimist proclaims that we live in the best of all possible worlds; and the pessimist fears this is true. So I elect for neither label. - James Branch Cabell

Offline

#3 2015-08-30 07:48:53

Kotrfa
Member
Registered: 2012-10-25
Posts: 213

Re: systemd unit start on network.target and restart on suspend.target

But if I understand it correctly, I would need second unit for this to implement (this is tlp-sleep.service which restarts tlp.service). That's not exactly what I want. But thank you anyway. Maybe this is the only way...

Last edited by Kotrfa (2015-08-30 07:49:08)

Offline

Board footer

Powered by FluxBB