[systemd-devel] Script in system-sleep that makes an HTTP post

Mantas Mikulėnas grawity at gmail.com
Fri Jun 11 16:15:16 UTC 2021


perror doesn't define exit statuses. It defines syscall return codes and
libc function errno values, which usually have nothing to do with the exit
code of the whole process.

Aside from the convention that "non-zero = failure", you have to look at
the docs of the whole program (e.g. if it's a shell script and the last
thing it did was call `curl` then the exit status is defined by curl).

I don't think system-sleep hooks are the right place to do network calls.
They're run at the last possible point, right before systemd tells the
kernel to suspend, but after it has informed userspace.

Hooking into sleep.target or using dbus to listen for the "PrepareForSleep"
signal might work better. Though I'm not sure how to make sure you get to
process the signal before NetworkManager does the same thing.

On Fri, Jun 11, 2021, 18:05 Doug Koobs <dkoobs at dkoobs.com> wrote:

> Hello all,
>
> tldr: Is there way I can use systemd to run scripts in
> /usr/lib/systemd/system-sleep at suspend before disabling the network?
>
> I've put a script in /usr/lib/systemd/system-sleep that makes an HTTP
> post to an IFTTT webhook when it's passed "pre" as $1. The script is
> successful if I run it manually, but when systemd runs it when I suspend
> the laptop, running "journalctl -b -u systemd-suspend.service" reports:
>
>      /usr/lib/systemd/system-sleep/outlet.sh failed with exit status 6.
>
> perror defines exit status 6 as: OS error code   6:  No such device or
> address
>
> This sounds like a network problem. If I disable networking and manually
> run the script, I get:
>
>      curl: (6) Could not resolve host: maker.ifttt.com
>
> My assumption is that systemd disables networking before the
> system-sleep scripts are run. Is there way I can use systemd to run the
> script before disabling the network?
>
> Thanks!
>
> Doug
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20210611/7ff56923/attachment.htm>


More information about the systemd-devel mailing list