Execute DB actions through Chef


#1

Hi All,

In my release deployment through chef, I would like to execute DBA actions
through chef.

This is the code snippet that I will be using to run DBA actions.

node[:release][:rel_dir] is same as d:\release.

powershell_script ‘Execute DBA Actions’ do
cwd Chef::node[:release][:rel_dir]
code <<-EOH
Start-Process -WorkingDirectory “D:\release” -FilePath “cmd.exe”
-ArgumentList “/k UpdateDB.bat zeyt sa abcde” -Verb runAs
EOH
end

here UpdateDb.bat is batch script that will accept arguments as
database_name, username and password . the syntax is

runSQL^
jdbc.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver^
uri=jdbc:sqlserver://10.10.10.10;DatabaseName=ZEYT;encrypt=false^
user=%2^
password=%3^
input.file=sql\DBUpdate.txt^
error.handling=EXIT^
output.verbose=%5

When I am executing powershell script this way, updateDB.bat is executed
through cmd.exe and chef has no control over it. Is it fine to execute a
second script this way??
or do I need to put some guards to check until the script is executed
completely like WaitforExit().

Any idea how to deal these use cases.

Thanks,
Sachin


#2

I would use a simple execute resource to run a script. there’s no need to start a powershell env to ask it to run a .bat and this create another nesting level begging to return OK when it is not.

As you want to wait the script to end, use execute, the hard bits are already handled there, just be sure your script return a non 0 exit code when it fail.


#3

Thanks Tensibai,

I added this code and it worked …

batch “Execute DBA Actions” do
cwd 'D:\release’
code "UpdateDB.bat zeyt sa abcde"
action :run
end

Just need to add few checks in case of failure.

Actually i was going in the wrong direction to use script within script .
but thanks to tensibai.

Sachin