Re: [systemd-devel] From command-line 'systemctl suspend' works' from cron it does not

2016-04-01 Thread Cecil Westerhof
2016-04-01 21:34 GMT+02:00 Lennart Poettering :

> On Mon, 21.03.16 09:21, Cecil Westerhof (cldwester...@gmail.com) wrote:
>
> > When executing
> > systemctl suspend || echo "Error code: ${?}"
> > from the command-line it outputs
> > Error code: 1
> > and it puts my machine in suspend.
> >
> > When putting it in cron it gives the following errors:
> > Failed to execute operation: Access denied
> > Failed to start suspend.target: Access denied
> > and gives the output:
> > Error code: 4
> >
> > What is happening here? Is it possible to run 'systemctl suspend' from
> > cron, or is there a reason why this is not possible?
>
> if you run "systemctl suspend" as unprivileged user, PolicyKit is
> queried whether your user shall be allowed the opreatoin. The default
> policy for PolicyKit we install says that users on local consoles may
> suspend the system. However, a cron user is not on a local console,
> hence doesn't get this privilege.
>

​OK, thanks. I solved it by using sudo.


-- 
Cecil Westerhof
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] From command-line 'systemctl suspend' works' from cron it does not

2016-04-01 Thread Lennart Poettering
On Mon, 21.03.16 09:21, Cecil Westerhof (cldwester...@gmail.com) wrote:

> When executing
> systemctl suspend || echo "Error code: ${?}"
> from the command-line it outputs
> Error code: 1
> and it puts my machine in suspend.
> 
> When putting it in cron it gives the following errors:
> Failed to execute operation: Access denied
> Failed to start suspend.target: Access denied
> and gives the output:
> Error code: 4
> 
> What is happening here? Is it possible to run 'systemctl suspend' from
> cron, or is there a reason why this is not possible?

if you run "systemctl suspend" as unprivileged user, PolicyKit is
queried whether your user shall be allowed the opreatoin. The default
policy for PolicyKit we install says that users on local consoles may
suspend the system. However, a cron user is not on a local console,
hence doesn't get this privilege.

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] From command-line 'systemctl suspend' works' from cron it does not

2016-03-24 Thread Cecil Westerhof
2016-03-23 8:11 GMT+01:00 Cecil Westerhof :

> Have you tried running from a root
>
>> crontab?
>>
>
> ​Just tried it and that works. One important difference: it returns an
> error code of 0 instead of 1.
> So probably I need to setup a systemd session. How am I going to do that?
>

​I understood that not on all systems a normal user has the ability to use
suspend and hibernate. Which makes sense. So I now use sudo in the script
and added to '/etc/sudoers':
cecil ALL = (root) NOPASSWD: /bin/systemctl suspend
cecil ALL = (root) NOPASSWD: /bin/systemctl hibernate

-- 
Cecil Westerhof
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] From command-line 'systemctl suspend' works' from cron it does not

2016-03-23 Thread Cecil Westerhof
2016-03-23 1:32 GMT+01:00 Kai Krakow :

> Am Mon, 21 Mar 2016 09:21:39 +0100
> schrieb Cecil Westerhof :
>
> > When executing
> > systemctl suspend || echo "Error code: ${?}"
> > from the command-line it outputs
> > Error code: 1
> > and it puts my machine in suspend.
> >
> > When putting it in cron it gives the following errors:
> > Failed to execute operation: Access denied
> > Failed to start suspend.target: Access denied
> > and gives the output:
> > Error code: 4
> >
> > What is happening here? Is it possible to run 'systemctl suspend' from
> > cron, or is there a reason why this is not possible?
>
> It's probably because cron doesn't setup a systemd session. Do you
> eventually run from a user crontab?


​I am not sure what you mean here. It was run from my user crontab. It is a
simplification from what I want. I have a script that I like to put into
systemd as a service, but there I get this error.


Have you tried running from a root
> crontab?
>

​Just tried it and that works. One important difference: it returns an
error code of 0 instead of 1.
So probably I need to setup a systemd session. How am I going to do that?


​I would not want to run the script as root.​ The script is:
https://github.com/CecilWesterhof/BashLibrary/blob/master/bin/suspend.sh
Besides that I do not want to run a script as root when not necessary, with
root in cron you get:
No protocol specified
xscreensaver-command: can't open display :0.0
​with the initial while.​ Which I do not get when running as normal user.


​If you wondering why I wrote the script:

https://www.linkedin.com/pulse/saving-netbook-battery-bash-script-cecil-westerhof
​

-- 
Cecil Westerhof
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] From command-line 'systemctl suspend' works' from cron it does not

2016-03-22 Thread Kai Krakow
Am Mon, 21 Mar 2016 09:21:39 +0100
schrieb Cecil Westerhof :

> When executing
> systemctl suspend || echo "Error code: ${?}"
> from the command-line it outputs
> Error code: 1
> and it puts my machine in suspend.
> 
> When putting it in cron it gives the following errors:
> Failed to execute operation: Access denied
> Failed to start suspend.target: Access denied
> and gives the output:
> Error code: 4
> 
> What is happening here? Is it possible to run 'systemctl suspend' from
> cron, or is there a reason why this is not possible?

It's probably because cron doesn't setup a systemd session. Do you
eventually run from a user crontab? Have you tried running from a root
crontab?

-- 
Regards,
Kai

Replies to list-only preferred.

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] From command-line 'systemctl suspend' works' from cron it does not

2016-03-21 Thread Cecil Westerhof
When executing
systemctl suspend || echo "Error code: ${?}"
from the command-line it outputs
Error code: 1
and it puts my machine in suspend.

When putting it in cron it gives the following errors:
Failed to execute operation: Access denied
Failed to start suspend.target: Access denied
and gives the output:
Error code: 4

What is happening here? Is it possible to run 'systemctl suspend' from
cron, or is there a reason why this is not possible?

-- 
Cecil Westerhof
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel