summaryrefslogtreecommitdiffstats
path: root/aconf/persistence/backends/service.lua
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-03-10 22:45:18 +0200
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2014-03-24 01:18:13 +0200
commit7d9c43916b0600ac4879dfe9793eab807a83ab2b (patch)
treeec54ed64c9a557b6ea4ad88d31138a02d3e0cd04 /aconf/persistence/backends/service.lua
parentcb6c243dc356ef1d46d7ddb96e6ea6ae007c6cca (diff)
downloadaconf-7d9c43916b0600ac4879dfe9793eab807a83ab2b.tar.bz2
aconf-7d9c43916b0600ac4879dfe9793eab807a83ab2b.tar.xz
rename ACF2 to Alpine Configurator (aconf)
Diffstat (limited to 'aconf/persistence/backends/service.lua')
-rw-r--r--aconf/persistence/backends/service.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/aconf/persistence/backends/service.lua b/aconf/persistence/backends/service.lua
new file mode 100644
index 0000000..4569ce8
--- /dev/null
+++ b/aconf/persistence/backends/service.lua
@@ -0,0 +1,32 @@
+--[[
+Copyright (c) 2012-2014 Kaarle Ritvanen
+See LICENSE file for license details
+--]]
+
+local rc = require('rc')
+local stringy = require('stringy')
+
+
+local backend = require('aconf.object').class()
+
+function backend:get(path, top)
+ if #path == 1 then return {'enabled', 'status'} end
+ assert(#path == 2)
+ local status = rc.service_status(path[1])
+ if path[2] == 'status' then return status end
+ if path[2] == 'enabled' then return stringy.startswith(status, 'start') end
+end
+
+function backend:set(mods)
+ for _, mod in ipairs(mods) do
+ local path, value = unpack(mod)
+ assert(#path == 2 and path[2] == 'enabled')
+
+ local name = path[1]
+ if value then rc.service_add(name)
+ else rc.service_delete(name) end
+ os.execute('rc-service '..name..' '..(value and 'start' or 'stop'))
+ end
+end
+
+return backend