2016-03-21 10:34 GMT+01:00 Colin Guthrie <[email protected]>: > Cecil Westerhof wrote on 19/03/16 23:54: > > 2016-03-18 17:16 GMT+01:00 Cecil Westerhof <[email protected] > > <mailto:[email protected]>>: > > > > 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. > > You're running the script as the user cecil (User=cecil). > > I suspect the problem is not so much the fact that it's run as this user > (you can probably issue "systemctl suspend" when logged in as the user > right? >
The problem was that from the command-line suspend and hibernate could be run, but not from cron, at, or a service. I solved it by using sudo with NOPASSWD in the script. -- Cecil Westerhof
_______________________________________________ systemd-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/systemd-devel
