I have a cookbook recipe which calls a shell script in a node. The recipe runs without any error, I also tried running it with -l debug and found no error. The shell script basically checkout a subversion tag and builds. For now I have commented out the build part and kept only checkout.
If I run the shell script it does exactly the checkout. But via recipe it shows execute success.
INFO: execute[test shell script] ran successfully
- execute sh /home/user_test/abc/test.sh release_xxxx release_xxxx
From Node I also tried chef-client -l debug, it shows same thing but checkout doesn't happened. The log shows files being checked-out but I can't find it.
Does your script explicitly/implicitly rely on environment variables like HOME
or similar that may not be set or be set to incorrect values?
What does the recipe code look like?
Thanks,
Matt Ray
Director of Partner Integration :: Chef
matt@chef.io :: 512.731.2218
mattray :: GitHub :: IRC :: Twitter
well just keep in mind that it probably is running either way…
it creates a shell script in tmp i think and runs it…
I shy away from execute/bash in chef as it is not idempotent and can sometimes cause more harm than good.
if you must - you should look to extend it with a creates
execute 'hello script' do
command 'echo hello > /tmp/hello'
creates '/tmp/hello'
end
something like that i think
First, look at subversion resource.
Second, run shell script with content = “export” only. It looks like You
have’t some environment variables (due to noninteractive mode of shell).
Here is the recipe below.
include_recipe 'subversion::client'
cookbook_file "/home/user_test/test/test.sh" do
source "test.sh"
mode 0755
end
execute "test shell script" do
command "sh /home/user_test/test/test.sh release_25022 release_25022"
end
and the test.sh containts
#!/bin/bash
basedir=.
if [ "$1" != "" ] && [ "$2" != "" ]; then
{
release=$1
schrelease=$2
echo "Tag version is $release "
echo "Cleaning up the workspace"
rm -rf $basedir/one
rm -rf $basedir/two
echo "checkout the $release source"
==== Checkout from tag
svn co https://path_to_tag/$release one --non-interactive --no-auth-cache --username xxxx --password xxxx
svn co https://path_to_tag/$schrelease two --non-interactive --no-auth-cache --username xxxx --password xxxx
}
else
{
echo "build required release label as parameter"
}
fi
It runs without any issues if I call the shell script directly on node. But through recipe it runs success but nothing happens.
For the subversion resource. How to provide tags?
subversion 'CouchDB Edge' do
svn_arguments '$release'
svn_username xxxx
svn_password xxxx
repository 'http://svn.apache.org/repos/asf/couchdb/tags/$release'
destination '/opt/mysources/couch'
action :checkout
end
revision
Ruby Type: String
A branch, tag, or commit to be synchronized with git. This can be symbolic,
like HEAD or it can be a source control management-specific revision
identifier. Default value: HEAD.
you should make certain to exit with a non-zero exit code from your shell script on error:
{
echo "build required release label as parameter"
exit 1
}
you should also begin your bash script by turning on bash ‘strictmode’:
http://redsymbol.net/articles/unofficial-bash-strict-mode/
that’ll actually surface failures in the script and won’t just print error messages and exit 0
then you should probably look at the cwd property to the execute resource and make sure you’re executing in the directory you think you are. you may also want to look at making certain that PATH and HOME and other env vars are set correctly:
https://docs.chef.io/resource_execute.html
Hi Lamont,
When I do chef-client -l info I can see the script is actually doing what it needs to do. for e.g. it will do a checkout. I can see also those on when I run chef-client -l info. But only thing is its not there at the location. The location is /home/user_test/test/test.sh
The Output while chef-client -l info
- cookbook_file[/home/user_test/test/test.sh] action create[2016-04-19T21:55:31+05:30] INFO: Processing cookbook_file[/home/user_test/test/test.sh] action create (test_shell::default line 11)
(up to date)
- execute[test shell script] action run[2016-04-19T21:55:31+05:30] INFO: Processing execute[test shell script] action run (test_shell::default line 16)
[execute] Test Release version is release_25022
Cleaning up the workspace
checkout the release_25022 source
A test/pom.xml
A test/.settings
A test/.settings/org.eclipse.core.resources.prefs
A test/.settings/org.eclipse.wst.common.project.facet.core.xml
A test/.settings/org.eclipse.wst.validation.prefs
A test/.settings/org.eclipse.wst.common.component
A test/.settings/org.eclipse.jdt.core.prefs
A test/.settings/org.eclipse.m2e.core.prefs
A test/build.xml
A test/test
A test/test/load
A test/test/load/build.xml
A test/test/load/tests
A test/test/load/tests/FrameWork_TestPlan.jmx
A test/test/load/tests/config.csv
A test/test/load/build.properties
.
.
.
...... and so on
Checked out revision 354.
[2016-04-19T21:55:36+05:30] INFO: execute[test shell script] ran successfully
- execute sh /home/user_test/test/test.sh release_25022 release_25022
[2016-04-19T21:55:36+05:30] INFO: Chef Run complete in 6.653224538 seconds
Running handlers:
[2016-04-19T21:55:36+05:30] INFO: Running report handlers
Running handlers complete
[2016-04-19T21:55:36+05:30] INFO: Report handlers complete
Chef Client finished, 1/6 resources updated in 13 seconds
So this means there is no error on the cookbook or on the script right? When I run the script apart the cookbook, it does do everything and all the files are available.
It is resolved. Thank you… Just realized that I am using a variable basedir=. and chef thinks the . as path / instead of where the test.sh file is.
I also changed the basedir=. to basedir=/home/user_test/test and it still checks out to /app1 and /app2 instead of /home/user_test/test/app1 and /home/user_test/test/app2.
So I just changed the checkout folder as /home/user_test/test/app1 instead of just app1.