From 81b17faab15a241bf0e99fc8856823fa687ea1e2 Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Wed, 9 Jan 2019 11:10:26 +0000 Subject: [PATCH] fix: Use logind manager to request reboots and shutdowns Change-type: patch Closes: #861 Signed-off-by: Cameron Diver --- src/lib/systemd.ts | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/lib/systemd.ts b/src/lib/systemd.ts index cfe9601f..279ee9b6 100644 --- a/src/lib/systemd.ts +++ b/src/lib/systemd.ts @@ -4,10 +4,21 @@ import * as dbus from 'dbus-native'; const bus = dbus.systemBus(); const invokeAsync = Bluebird.promisify(bus.invoke).bind(bus); +const defaultPathInfo = { + path: '/org/freedesktop/systemd1', + destination: 'org.freedesktop.systemd1', + interface: 'org.freedesktop.systemd1.Manager', +}; + const systemdManagerMethodCall = ( method: string, signature?: string, body?: any[], + pathInfo: { + path: string; + destination: string; + interface: string; + } = defaultPathInfo, ) => { if (signature == null) { signature = ''; @@ -16,9 +27,7 @@ const systemdManagerMethodCall = ( body = []; } return invokeAsync({ - path: '/org/freedesktop/systemd1', - destination: 'org.freedesktop.systemd1', - interface: 'org.freedesktop.systemd1.Manager', + ...pathInfo, member: method, signature, body, @@ -62,11 +71,27 @@ export function disableService(serviceName: string) { } export const reboot = Bluebird.method(() => - setTimeout(() => systemdManagerMethodCall('Reboot'), 1000), + setTimeout( + () => + systemdManagerMethodCall('Reboot', 'b', [false], { + path: '/org/freedesktop/login1', + destination: 'org.freedesktop.login1', + interface: 'org.freedesktop.login1.Manager', + }), + 1000, + ), ); export const shutdown = Bluebird.method(() => - setTimeout(() => systemdManagerMethodCall('PowerOff'), 1000), + setTimeout( + () => + systemdManagerMethodCall('PowerOff', 'b', [false], { + path: '/org/freedesktop/login1', + destination: 'org.freedesktop.login1', + interface: 'org.freedesktop.login1.Manager', + }), + 1000, + ), ); function getUnitProperty(unitName: string, property: string) {