diff options
author | Ted Trask <ttrask01@yahoo.com> | 2015-01-29 16:36:37 -0500 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2015-01-29 16:36:37 -0500 |
commit | 6898d43145abec567ced449b48ac4c1977e97332 (patch) | |
tree | 9fd0506848f3f399a726d3799265a98e0dd5fb8b /mysql-model.lua | |
download | acf-mariadb-6898d43145abec567ced449b48ac4c1977e97332.tar.bz2 acf-mariadb-6898d43145abec567ced449b48ac4c1977e97332.tar.xz |
Initial commit for acf-mariadb based on acf-mysql-0.1.1
Diffstat (limited to 'mysql-model.lua')
-rw-r--r-- | mysql-model.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/mysql-model.lua b/mysql-model.lua new file mode 100644 index 0000000..de867f9 --- /dev/null +++ b/mysql-model.lua @@ -0,0 +1,58 @@ +local mymodule = {} + +-- Load libraries +modelfunctions = require("modelfunctions") +fs = require("acf.fs") +format = require("acf.format") +db = require("acf.db") +dbmodelfunctions = require("dbmodelfunctions") + +-- Set variables +local conffile = "/etc/mysql/my.cnf" +local processname = "mariadb" +local packagename = "mariadb" + +-- ################################################################################ +-- LOCAL FUNCTIONS + +local determineconnection = function() + local port = format.parse_ini_file(fs.read_file(conffile), "client", "port") + return db.create(db.engine.mysql, nil, nil, nil, "", tonumber(port) or 3306) +end + +-- ################################################################################ +-- PUBLIC FUNCTIONS + +function mymodule.get_startstop(self, clientdata) + return modelfunctions.get_startstop(processname) +end + +function mymodule.startstop_service(self, startstop, action) + return modelfunctions.startstop_service(startstop, action) +end + +function mymodule.getstatus() + return modelfunctions.getstatus(processname, packagename, "MariaDB Status") +end + +function mymodule.getstatusdetails() + local retval = cfe({ type="longtext", value="", label="MariaDB Status Details" }) + retval.value, retval.errtxt = modelfunctions.run_executable({"mysqladmin", "extended-status"}) + return retval +end + +function mymodule.getfiledetails() + return modelfunctions.getfiledetails(conffile, {conffile}) +end + +function mymodule.updatefiledetails(self, filedetails) + return modelfunctions.setfiledetails(self, filedetails, {conffile}) +end + +for n,f in pairs(dbmodelfunctions) do + mymodule[n] = function(...) + return f(determineconnection, ...) + end +end + +return mymodule |