--- /dev/null
+-- -*- mode: lua -*-
+
+if not loaded('system-monitor') then
+ return
+end
+
+cg = m:CGroupOpen({ type = 'cpuacct',
+ name = 'murphy-test',
+ mode = 'readonly',
+ foo = 3,
+ bar = 'foobar',
+ foobar = 9.81 })
+
+print('cg: ' .. tostring(cg))
+print('cg.mode: ' .. tostring(cg.mode))
+print('cg.foo: ' .. tostring(cg.foo))
+print('cg.bar: ' .. tostring(cg.bar))
+print('cg.foobar: ' .. tostring(cg.foobar))
+
+--status = cg:add_process(4214)
+--cg.tasks = 4214
+print('cg.tasks: ' .. cg.tasks)
+
+
+cg1 = m:CGroupOpen({ type = 'cpu',
+ name = 'test',
+ mode = 'readwrite,create',
+ Shares = 2048 })
+
+print('cg1: ' .. tostring(cg1))
+print('cg1.mode: ' .. cg1.mode)
+print('cg1.shares: ' .. cg1.Shares)
+print('cg1.tasks: ' .. cg1.tasks)
--- /dev/null
+-- -*- mode: lua -*-
+
+-- plugin optionality constants
+OPTIONAL = 1 -- mark a plugin optional
+IFEXISTS = 2 -- mark a plugin mandatory if present
+MANDATORY = 3 -- mark a plugin mandatory
+
+-- function to try loading an optional plugin, ignoring errors
+function try_load(plugin, ...)
+ local a = {...}
+ m:info('* Trying to load (optional) plugin ' .. plugin)
+ if #a == 0 then return m:try_load_plugin(plugin )
+ elseif #a == 1 then return m:try_load_plugin(plugin, a[1] )
+ else return m:try_load_plugin(plugin, a[1], a[2])
+ end
+end
+
+-- function to load a plugin if it exists
+function load_if_exists(plugin, ...)
+ local a = {...}
+ if m:plugin_exists(plugin) then
+ m:info('* Loading (existing) plugin ' .. plugin)
+ else
+ return true
+ end
+ if #a == 0 then return m:load_plugin(plugin )
+ elseif #a == 1 then return m:load_plugin(plugin, a[1] )
+ else return m:load_plugin(plugin, a[1], a[2])
+ end
+end
+
+-- function to load a mandatory plugin
+function load(plugin, ...)
+ local a = {...}
+ m:info('* Loading (mandatory) plugin ' .. plugin)
+ if #a == 0 then return m:load_plugin(plugin )
+ elseif #a == 1 then return m:load_plugin(plugin, a[1] )
+ else return m:load_plugin(plugin, a[1], a[2])
+ end
+end
+
+-- function to check if a plugin has been successfully loaded (and running)
+function loaded(plugin)
+ return m:plugin_loaded(plugin)
+end
+
+-- function to include a file
+function include(file, necessity)
+ if necessity < MANDATORY then
+ m:info('* Trying to include (optional) ' .. file)
+ m:try_include(file)
+ else
+ m:info('* Including (mandatory) ' .. file)
+ m:include(file)
+ end
+end
--- /dev/null
+-- -*- mode: lua -*-
+
+-- load the oridnary console
+load('console')
+
+-- load a web console
+try_load('console',
+ 'webconsole', {
+ address = 'wsck:127.0.0.1:3000/murphy',
+ httpdir = 'src/plugins/console',
+ --[[
+ sslcert = 'src/plugins/console/console.crt',
+ sslpkey = 'src/plugins/console/console.key'
+ --]] })
--- /dev/null
+-- -*- mode: lua -*-
+
+-- load the D-Bus plugin if it exists
+load_if_exists('dbus')
--- /dev/null
+-- -*- mode: lua -*-
+
+-- load the domain control plugin if it exists
+load_if_exists('domain-control')
+
+-- load a domain-control instance for exposing data to the WRT
+try_load('domain-control',
+ 'wrt-export', {
+ external_address = '',
+ internal_address = '',
+ wrt_address = "wsck:127.0.0.1:5000/murphy",
+ httpdir = "src/plugins/domain-control" })
--- /dev/null
+-- -*- mode: lua -*-
+
+-- try loading the GLIB plugin
+try_load('glib')
--- /dev/null
+-- -*- mode: lua -*-
+
+--
+-- pull in the common configuration support bits
+--
+m = murphy.get()
+m:include_once('common.cfg')
+
+
+--
+-- configuration files and rulesets to pull in
+--
+config = {
+ { 'console' , OPTIONAL },
+ { 'systemd' , OPTIONAL },
+ { 'dbus' , MANDATORY },
+ { 'glib' , OPTIONAL },
+ { 'resource' , MANDATORY },
+ { 'domain-control' , MANDATORY },
+ { 'system-controller', OPTIONAL },
+ { 'system-monitor' , OPTIONAL },
+}
+
+ruleset = {
+ { 'speed-volume' , MANDATORY },
+ { 'system-monitor' , OPTIONAL },
+ { 'cgroup-test' , OPTIONAL },
+}
+
+
+--
+-- pull in the given configuration and ruleset files
+--
+
+for idx,cfg in ipairs(config) do
+ include(cfg[1] .. '.cfg', cfg[2])
+end
+
+for idx,rules in ipairs(ruleset) do
+ include(rules[1] .. '.rules', rules[2])
+end
--- /dev/null
+load-plugin lua config="src/daemon/sample-config/main.cfg"
--- /dev/null
+-- -*- mode: lua -*-
+
+-- load the native resource plugin
+load_if_exists('resource-native')
+
+-- load the D-Bus resource plugin if we have it and D-Bus
+if loaded('dbus') then
+ try_load('resource-dbus', {
+ dbus_bus = "system",
+ dbus_service = "org.Murphy",
+ dbus_track = true,
+ default_zone = "driver",
+ default_class = "implicit"
+ })
+end
+
+-- try loading the WRT resource plugin
+try_load('resource-wrt', {
+ address = "wsck:127.0.0.1:4000/murphy",
+ httpdir = "src/plugins/resource-wrt",
+ --[[
+ sslcert = 'src/plugins/resource-wrt/resource.crt',
+ sslpkey = 'src/plugins/resource-wrt/resource.key',
+ --]]
+ })
+
+-- load the IVI resource manager if it is available
+load_if_exists('ivi-resource-manager')
+
+--
+-- define application classes
+--
+application_class { name="interrupt", priority=99,
+ modal=true , share=false, order="fifo" }
+application_class { name="navigator", priority=4 ,
+ modal=false, share=true , order="fifo" }
+application_class { name="phone" , priority=3 ,
+ modal=false, share=true , order="lifo" }
+application_class { name="game" , priority=2 ,
+ modal=false, share=true , order="lifo" }
+application_class { name="player" , priority=1 ,
+ modal=false, share=true , order="lifo" }
+application_class { name="implicit" , priority=0 ,
+ modal=false, share=true , order="lifo" }
+
+--
+-- define zones
+--
+zone.attributes {
+ type = {mdb.string, "common", "rw"},
+ location = {mdb.string, "anywhere", "rw"}
+}
+
+zone {
+ name = "driver",
+ attributes = {
+ type = "common",
+ location = "front-left"
+ }
+}
+
+zone {
+ name = "passanger1",
+ attributes = {
+ type = "private",
+ location = "front-right"
+ }
+}
+
+zone {
+ name = "passanger2",
+ attributes = {
+ type = "private",
+ location = "back-left"
+ }
+}
+
+zone {
+ name = "passanger3",
+ attributes = {
+ type = "private",
+ location = "back-right"
+ }
+}
+
+zone {
+ name = "passanger4",
+ attributes = {
+ type = "private",
+ location = "back-left"
+ }
+}
+
+
+--
+-- define resource classes
+--
+if not m:plugin_loaded('ivi-resource-manager') then
+ resource.class {
+ name = "audio_playback",
+ shareable = true,
+ attributes = {
+ role = { mdb.string, "music", "rw" },
+ pid = { mdb.string, "<unknown>", "rw" },
+ policy = { mdb.string, "relaxed", "rw" }
+ }
+ }
+end
+
+resource.class {
+ name = "audio_recording",
+ shareable = false,
+ attributes = {
+ role = { mdb.string, "music", "rw" },
+ pid = { mdb.string, "<unknown>", "rw" },
+ policy = { mdb.string, "relaxed", "rw" }
+ }
+}
+
+resource.class {
+ name = "video_playback",
+ shareable = false,
+}
+
+resource.class {
+ name = "video_recording",
+ shareable = false,
+}
+
+resource.class {
+ name = "speech_synthesis",
+ shareable = true,
+}
+
+resource.class {
+ name = "speech_recognition",
+ shareable = true,
+}
--- /dev/null
+-- test for creating selections
+mdb.select {
+ name = "audio_owner",
+ table = "audio_playback_owner",
+ columns = {"application_class"},
+ condition = "zone_name = 'driver'",
+}
+
+element.lua {
+ name = "speed2volume",
+ inputs = { owner = mdb.select.audio_owner, param = 5 },
+ outputs = { mdb.table { name = "speedvol",
+ index = {"zone", "device"},
+ columns = {{"zone", mdb.string, 16},
+ {"device", mdb.string, 16},
+ {"value", mdb.floating}},
+ create = true
+ }
+ },
+ update = function(self)
+ if (self.inputs.owner.single_value) then
+ print("*** element "..self.name.." update "..
+ self.inputs.owner.single_value)
+ else
+ print("*** element "..self.name.." update <nil>")
+ end
+ end
+}
--- /dev/null
+-- -*- mode: lua -*-
+
+load_if_exists('system-controller')
--- /dev/null
+-- -*- mode: lua -*-
+
+-- try loading the system-monitor plugin
+load_if_exists('system-monitor')
--- /dev/null
+-- -*- mode: lua -*-
+
+if not loaded('system-monitor') then
+ return
+end
+
+-- get and configure system-monitor
+sm = m:get_system_monitor()
+
+sm.polling = 1000 -- poll 1 / second
+
+--
+-- monitor overall CPU load (load of the virtual combined CPU)
+--
+sm:CpuWatch({
+ cpu = 'cpu', -- virtual 'combined' CPU
+ sample = 'load', -- monitor 'load'
+ limits = { -- load threshold %'s
+ [1] = { label = 'idle' , limit = 5 },
+ [2] = { label = 'low' , limit = 20 },
+ [2] = { label = 'moderate', limit = 40 },
+ [3] = { label = 'medium' , limit = 50 },
+ [4] = { label = 'high' , limit = 80 },
+ [5] = { label = 'critical' }
+ },
+ window = 15000, -- use an EWMA of 15 secs
+ notify = function (w, prev, curr) -- threshold change callback
+ print('CPU load change: ' .. prev .. ' -> ' .. curr)
+ end
+ })
+
+
+--
+-- monitor length of the writeback queue
+--
+sm:MemWatch({
+ sample = 'Writeback',
+ limits = { -- pressure thresholds
+ [1] = { label = 'none' , limit = 1024 },
+ [2] = { label = 'low' , limit = 8192 },
+ [3] = { label = 'medium' , limit = '1M' },
+ [4] = { label = 'high' , limit = '4M' },
+ [5] = { label = 'critical', limit = '16M' }
+ },
+ window = 0, -- don't average/integrate
+ notify = function (w, prev, curr) -- threshold change callback
+ print(w.sample .. ' change: ' .. prev .. ' -> ' .. curr)
+ end
+ })
+
+--
+-- monitor the amount of dirty memory
+--
+sm:MemWatch({
+ sample = 'Dirty',
+ limits = { -- pressure thresholds
+ [1] = { label = 'none' , limit = 1024 },
+ [2] = { label = 'low' , limit = 8192 },
+ [3] = { label = 'medium' , limit = '1M' },
+ [4] = { label = 'high' , limit = '4M' },
+ [5] = { label = 'critical', limit = '16M' }
+ },
+ window = 10000, -- use an EWMA of 10 secs
+ notify = function (w, prev, curr) -- threshold change callback
+ print(w.sample .. ' change: ' .. prev .. ' -> ' .. curr)
+ end
+ })
--- /dev/null
+-- -*- mode: lua -*-
+
+-- try loading the systemd plugin (for systemd-aware logging)
+try_load('systemd')