[systemd-devel] Suspend does not work from a service

Cecil Westerhof cldwesterhof at gmail.com
Sat Mar 19 23:54:44 UTC 2016


2016-03-18 17:16 GMT+01:00 Cecil Westerhof <cldwesterhof at gmail.com>:

> I wrote as script to put my netbook into suspend when it is locked for
> five minutes and not connected to the AC adapter:
>
> https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/suspend.sh
>
> This works perfect when I start it from the command-line, but not when I
> use it as a systemd service. Then I get:
>     Failed to start suspend.target: Access denied
> when the
>     systemctl suspend || true
> is executed.
>

​For what it is worth: normally ‘systemctl​

​suspend’ returns 1, but from the systemd service it returns 4.​



> ​What could be happening here? And how do I solve it?
>
> My service file:
> [Unit]
> Description=Suspend machine when locked and no AC adaptor
>
> [Service]
> Type=simple
> ExecStart=/usr/local/bash/bin/suspend.sh
> Restart=always
> User=cecil
>
> [Install]
> WantedBy=multi-user.target
>>
> ​On a related note​: why does:
>     systemctl suspend
> give an exit status of 1?
> And why does it returns immediately? I had to add a sleep 5 to my script
> to make it work.
>
> --
> Cecil Westerhof
>



-- 
Cecil Westerhof
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20160320/9f31bc92/attachment.html>


More information about the systemd-devel mailing list