3

I have an SBC (pine64) running Ubuntu 16_04 and I have a long process to do (build tensorflow). I'm using the nohup command to detach the process from my SSH session but two days consecutively my board rebooted at midnight. I saw that I can inhibit reboot, sleep and shutdown with systemd-inhibit.

Is there a way to use this command without sudo? Bazel build doesn't recognize my %JAVA_HOME when launched with sudo...

This is the command I'm trying to run:

systemd-inhibit --why="Compiling TF" nohup bazel build -c opt --copt="-funsafe-math-optimiza
tions" --copt="-ftree-vectorize" --copt="-fomit-frame-pointer" --verbose_failures tensorflow/tools/pip_package:build_pip_pa
ckage &  

which gives me:

Failed to inhibit: Access denied

Any advice?

3 Answers3

1

You can use systemd-inhibit --what=idle as a normal user to prevent the machine from suspending due to system idleness. Other locks require elevated privileges.

Daniel
  • 817
0

I had tested systemd-inhibit --what=idle and systemd-inhibit --what=sleep commands, both of them can using in normal user.

BTW, if you use elogind-inhibit all of the --what= arguments are working (if you set one).

0

One can customise polkit to allow users to inhibit sleep as well. For example, I allowed users of group wheel to inhibit sleep as follows:

As root, dump the following in /etc/polkit-1/rules.d/50-inhibit-sleep-wheel.rules:

polkit.addRule(function(action, subject) {
    if ((action.id == "org.freedesktop.login1.inhibit" || 
         action.id == "org.freedesktop.login1.inhibit-block-sleep")
        && subject.isInGroup("wheel")) {
        return polkit.Result.YES;
    }
});

Next restart polkit (optionally with sudo):

systemctl restart polkit

Test as follows:

systemd-inhibit --what=sleep --who=$(whoami) --why="Testing Polkit Rule" sleep 10 &
systemd-inhibit --list

If you are still blocked, you should get the following:

Failed to inhibit: Access denied

To create more complex rules, inspect the defaults in file /usr/share/polkit-1/actions/org.freedesktop.login1.policy.