[systemd-devel] systemd-inhibit fails when run from a service file
Amish
anon.amish at gmail.com
Wed Dec 4 01:04:36 UTC 2019
(Resending because earlier one, date 26/11/2019, did not get any response)
Hello,
I have a small perl program which downloads something. While downloading
it inhibits (blocks) shutdown, reboot etc.
The program runs as user "foo".
Roughly the code is something like this:
$ cat /home/foo/downloads/dnld.sh
#!/bin/bash
/usr/bin/systemd-inhibit
--what=shutdown:sleep:idle:handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch
--who=Downloader '--why=Important download in progress' --mode=block
/home/foo/downloads/dnld.pl
This works fine when I run from a user foo's shell.
$ /home/foo/downloads/dnld.sh &
$ systemctl --dry-run suspend
Operation inhibited by "Downloader" (PID 27441 "systemd-inhibit", user
foo), reason is "Important download in progress".
But now I call same script via dnld.service file.
$ cat /etc/systemd/system/dnld.service
[Unit]
Description=Download files
After=network.target
[Service]
User=foo
Type=simple
WorkingDirectory=/home/foo/downloads
ExecStart=/home/foo/downloads/dnld.sh
When I start the service it gives "Failed to inhibit: Access denied" error.
# systemctl start dnld.service
# journalctl -u dnld.service
Nov 26 13:33:30 foo systemd[1]: Started Download files.
Nov 26 13:33:30 foo dnld.sh[27745]: Failed to inhibit: Access denied
Nov 26 13:33:30 foo systemd[1]: dnld.service: Main process exited,
code=exited, status=1/FAILURE
Nov 26 13:33:30 foo systemd[1]: dnld.service: Failed with result
'exit-code'.
If I change code to not call systemd-inhibit:
$ cat /home/foo/downloads/dnld.sh
#!/bin/bash
/home/foo/downloads/dnld.pl
Then service file runs fine.
# systemctl start dnld.service; sleep 30
# journalctl -u dnld.service
Nov 26 13:50:17 foo systemd[1]: Started Download files.
Nov 26 13:50:37 foo systemd[1]: dnld.service: Succeeded.
So how do I allow systemd-inhibit call when a script is called via
systemd instead of directly?
Is this systemd bug or am I missing something in dnld.service file?
Amish
More information about the systemd-devel
mailing list