-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.coffee
30 lines (23 loc) · 925 Bytes
/
app.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
dbus = require 'dbus-native'
{ EventEmitter } = require 'events'
#
# https://www.freedesktop.org/wiki/Software/systemd/dbus/
#
unitEvents = [ "UnitNew", "UnitRemoved", "JobNew", "JobRemoved", "StartupFinished" ]
class SystemdManager extends EventEmitter
constructor: ({ dbusSocket })->
super()
@serviceName = "org.freedesktop.systemd1"
@objectPath = "/org/freedesktop/systemd1"
bus = dbus.systemBus busAddress: "unix:path=#{dbusSocket}"
throw new Error 'Could not connect to the DBus system bus.' unless bus
@service = bus.getService @serviceName
init: (cb) ->
@service.getInterface @objectPath, "#{@serviceName}.Manager", (error, @manager) =>
cb error if error
unitEvents.forEach (event) =>
@manager.on event, (things...) =>
[ pid, path, serviceName, state ] = things
@emit event, { pid, path, serviceName, state }
cb null, @manager
module.exports = SystemdManager