Skip to content

System controlling

Markus Enax edited this page Jan 7, 2017 · 6 revisions

systemd provides means to control the system/user daemon itself and to control deployed units. These are (among others):

  • Enabling and disabling of units (like shell command systemctl enable <unit>)
  • Starting, restarting and stopping of units (like shell command systemctl restart <unit>)

Controlling is also possible through D-Bus. Therefore the manager interface provides a range of methods which can be invoked to achieve the same as if performed on the command line.

Security

Some methods require higher privileges. For example the restart of a system unit requires root privileges. When working on the command line as a non-privileged user a command like systemctl restart <unit> would be invoked by using some privilege escalation framework (like sudo or similar) along a proper set of configuration for privilege escalation. For the invokation of protected commands via D-Bus the use of polkit is required.

Below is an example file /etc/polkit-1/rules.d/60-example.rules which grants starting, stopping and restarting of a systemd unit for everyone.

polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.systemd1.manage-units") {
        var verb = action.lookup("verb");

        if (verb == "start" || verb == "stop" || verb == "restart") {
            return polkit.Result.YES;
        }
    }
});
Clone this wiki locally