summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2013-01-01 23:50:14 +0000
committerTed Trask <ttrask01@yahoo.com>2013-01-01 23:50:14 +0000
commit4f55c6157b49b400a9005a2b7d0fc2f155e6a930 (patch)
tree61c5050dd4e2368b74c9a9106a937a5b437a6fbf
parenta0edc5f3607d568e6c3ddc9d88b4eb9048cea81f (diff)
downloadacf-provisioning-4f55c6157b49b400a9005a2b7d0fc2f155e6a930.tar.bz2
acf-provisioning-4f55c6157b49b400a9005a2b7d0fc2f155e6a930.tar.xz
Replace io.popen with modelfunctions.run_executable
-rw-r--r--provisioning-model.lua44
1 files changed, 21 insertions, 23 deletions
diff --git a/provisioning-model.lua b/provisioning-model.lua
index 521273c..ca04d36 100644
--- a/provisioning-model.lua
+++ b/provisioning-model.lua
@@ -14,7 +14,6 @@ local DatabaseName = "provisioning"
local DatabaseUser = "postgres"
local DatabasePassword
-local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "
local baseurl = "/etc/provisioning/templates/"
local updatedevicescriptfile = "/etc/provisioning/update_device.lua"
local updatedeviceparamsscriptfile = "/etc/provisioning/update_device_params.lua"
@@ -53,28 +52,27 @@ end
local createdatabase = function()
local result = {}
+ local cmdresult, errtxt
-- First, create the user
if DatabaseUser ~= "postgres" then
- local cmd = path..'psql -U postgres -c "CREATE USER '..DatabaseUser..''
+ local cmd = "CREATE USER "..DatabaseUser
if DatabasePassword then
- cmd = cmd .. ' WITH PASSWORD \''..DatabasePassword..'\''
+ cmd = cmd .. " WITH PASSWORD '"..DatabasePassword.."'"
end
- cmd = cmd .. '" 2>&1'
- local f = io.popen(cmd)
- table.insert(result, f:read("*a"))
- f:close()
+ cmdresult, errtxt = modelfunctions.run_executable({"psql", "-U", "postgres", "-c", cmd}, true)
+ table.insert(result, errtxt)
+ table.insert(result, cmdresult)
end
-- Create the database
- local cmd = path..'psql -U postgres -c "CREATE DATABASE '..DatabaseName..' WITH OWNER '..DatabaseUser..'" 2>&1'
- local f = io.popen(cmd)
- table.insert(result, f:read("*a"))
- f:close()
+ local cmd = "CREATE DATABASE "..DatabaseName.." WITH OWNER "..DatabaseUser
+ cmdresult, errtxt = modelfunctions.run_executable({"psql", "-U", "postgres", "-c", cmd}, true)
+ table.insert(result, errtxt)
+ table.insert(result, cmdresult)
- cmd = path..'createlang -U postgres plpgsql '..DatabaseName
- f = io.popen(cmd)
- table.insert(result, f:read("*a"))
- f:close()
+ cmdresult, errtxt = modelfunctions.run_executable({"createlang", "-U", "postgres", "plpgsql", DatabaseName}, true)
+ table.insert(result, errtxt)
+ table.insert(result, cmdresult)
logevent(table.concat(result, "\n"))
@@ -85,16 +83,16 @@ end
local deletedatabase = function()
local result = {}
- local cmd = path..'psql -U postgres -c "DROP DATABASE '..DatabaseName..'" 2>&1'
- local f = io.popen(cmd)
- table.insert(result, f:read("*a"))
- f:close()
+ local cmd = "DROP DATABASE "..DatabaseName
+ local cmdresult, errtxt = modelfunctions.run_executable({"psql", "-U", "postgres", "-c", cmd}, true)
+ table.insert(result, errtxt)
+ table.insert(result, cmdresult)
if DatabaseUser ~= "postgres" then
- cmd = path..'psql -U postgres -c "DROP ROLE '..DatabaseUser..'" 2>&1'
- f = io.popen(cmd)
- table.insert(result, f:read("*a"))
- f:close()
+ cmd = "DROP ROLE "..DatabaseUser
+ local cmdresult, errtxt = modelfunctions.run_executable({"psql", "-U", "postgres", "-c", cmd}, true)
+ table.insert(result, errtxt)
+ table.insert(result, cmdresult)
end
logevent(table.concat(result, "\n"))