Re: Script in system-sleep that makes an HTTP post

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
_______________________________________________
systemd-devel mailing list
systemd-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux