From 647ea948f6b8663ee90c4789c836a4f6ee0b3bae Mon Sep 17 00:00:00 2001 From: samukasmk Date: Mon, 24 Jun 2013 11:04:46 -0300 Subject: [PATCH 1/3] Error when using some urls with parameters and '&' character at bash, in url example (http://domain.com/service/local/artifact/maven/content?r=private&g=com.myapp&a=my-app-catalog&v=5.31.3&p=war), if we do not use accents ', at the time of passing the url as parameter the scripts (eg get_file.sh), the bash interprets '&' character as (end of command, send command to backgroud). I tried to use these accents in the declaration of the manifesto, by calling the class puppi::project::war, however the manifests of puppi write scripts to deploy wrong. --- manifests/project/war.pp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/manifests/project/war.pp b/manifests/project/war.pp index 60f3f99..683da5a 100644 --- a/manifests/project/war.pp +++ b/manifests/project/war.pp @@ -187,7 +187,7 @@ puppi::initialize { "${name}-Deploy_Files": priority => '40' , command => 'get_file.sh' , - arguments => "-s ${init_source} -d ${deploy_root}" , + arguments => "-s '${init_source}' -d '${deploy_root}'" , user => $user , project => $name , enable => $enable , @@ -211,7 +211,7 @@ puppi::deploy { "${name}-Retrieve_WAR": priority => '20' , command => 'get_file.sh' , - arguments => "-s ${source} -a ${real_always_deploy}" , + arguments => "-s '${source}' -a '${real_always_deploy}'" , user => 'root' , project => $name , enable => $enable , @@ -232,7 +232,7 @@ puppi::deploy { "${name}-Backup_existing_WAR": priority => '30' , command => 'archive.sh' , - arguments => "-b ${deploy_root} -t war -s move -m diff -o '${backup_rsync_options}' -n ${backup_retention}" , + arguments => "-b '${deploy_root}' -t war -s move -m diff -o '${backup_rsync_options}' -n '${backup_retention}'" , user => 'root' , project => $name , enable => $enable , @@ -243,7 +243,7 @@ puppi::deploy { "${name}-Check_undeploy": priority => '32' , command => 'checkwardir.sh' , - arguments => "-a ${deploy_root}/${war_file}" , + arguments => "-a '${deploy_root}/${war_file}'" , user => $user , project => $name , enable => $enable , @@ -287,7 +287,7 @@ puppi::deploy { "${name}-Deploy_WAR": priority => '40' , command => 'deploy_files.sh' , - arguments => "-d ${deploy_root} -c ${bool_clean_deploy}", + arguments => "-d '${deploy_root}' -c '${bool_clean_deploy}'", user => $user , project => $name , enable => $enable , @@ -330,7 +330,7 @@ puppi::deploy { "${name}-Check_deploy": priority => '45' , command => 'checkwardir.sh' , - arguments => "-p ${deploy_root}/${war_file}" , + arguments => "-p '${deploy_root}/${war_file}'" , user => $user , project => $name , enable => $enable , @@ -378,7 +378,7 @@ puppi::rollback { "${name}-Remove_existing_WAR": priority => '30' , command => 'delete.sh' , - arguments => "${deploy_root}/${war_file}" , + arguments => "'${deploy_root}/${war_file}'" , user => 'root' , project => $name , enable => $enable , @@ -388,7 +388,7 @@ puppi::rollback { "${name}-Check_undeploy": priority => '36' , command => 'checkwardir.sh' , - arguments => "-a ${deploy_root}/${war_file}" , + arguments => "-a '${deploy_root}/${war_file}'" , user => $user , project => $name , enable => $enable , @@ -431,7 +431,7 @@ puppi::rollback { "${name}-Recover_Files_To_Deploy": priority => '40' , command => 'archive.sh' , - arguments => "-r ${deploy_root} -t war -o '${backup_rsync_options}'" , + arguments => "-r '${deploy_root}' -t war -o '${backup_rsync_options}'" , user => $user , project => $name , enable => $enable , @@ -474,7 +474,7 @@ puppi::rollback { "${name}-Check_deploy": priority => '45' , command => 'checkwardir.sh' , - arguments => "-p ${deploy_root}/${war_file}" , + arguments => "-p '${deploy_root}/${war_file}'" , user => $user , project => $name , enable => $enable , From 67396c035924870d2e2d5721a81ca4248882f8c4 Mon Sep 17 00:00:00 2001 From: samukasmk Date: Mon, 24 Jun 2013 11:24:10 -0300 Subject: [PATCH 2/3] New Feature to set dest war file name, regardless the source file name contain variations --- files/scripts/get_file.sh | 20 ++++++++++++++++---- manifests/project/war.pp | 15 +++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/files/scripts/get_file.sh b/files/scripts/get_file.sh index 6173362..f0871ad 100644 --- a/files/scripts/get_file.sh +++ b/files/scripts/get_file.sh @@ -18,6 +18,7 @@ showhelp () { echo "-s - The URL of the file to get" echo "-t - The type of file that is retrieved: list|tarball|maven-metadata|dir" echo "-d - An alternative destination directory (default is automatically chosen)" + echo "-f - An alternative destination file name (default is automatically chosen)" echo "-a - If 'no' return a special error code (99) if the download checksum is the same of the one previously downloaded" echo "-u - in case of type http, specify a http_user for curl" echo "-p - in case of type http, specifiy http_user for curl" @@ -77,6 +78,9 @@ while [ $# -gt 0 ]; do # Enforces and overrides and alternative downloaddir downloaddir=$2 shift 2 ;; + -f) + destfilename=$2 + shift 2 ;; -a) alwaysdeploy=$2 shift 2 ;; @@ -115,11 +119,19 @@ case $type in save_runtime_config "downloadedfile=$downloaddir/$downloadfilename" ;; http|https) - if [ -z "$http_password" ] ; then - curl $ssl_arg -s -f -L "$url" -O + if [ ! -z "$destfilename" ] ; then + destfilename_arg="-o $destfilename" else - curl $ssl_arg -s -f -L --anyauth --user $http_user:$http_password "$url" -O - fi + destfilename_arg="-O" + fi + + if [ ! -z "$http_password" ] ; then + httpauth_arg="--anyauth --user $http_user:$http_password" + else + httpauth_arg="" + fi + + curl $ssl_arg -s -f -L $httpauth_arg "$url" $destfilename_arg check_retcode save_runtime_config "downloadedfile=$downloaddir/$downloadfilename" ;; diff --git a/manifests/project/war.pp b/manifests/project/war.pp index 683da5a..1a92fed 100644 --- a/manifests/project/war.pp +++ b/manifests/project/war.pp @@ -16,6 +16,11 @@ # [*deploy_root*] # The destination directory where the retrieved file(s) are deployed. # +# [*war_file*] +# (Optional) - The destination war file name where the retrieved file +# is deployed. In the case of a single war file that already has a version +# specifies the name and needs to be renamed. +# # [*init_source*] # (Optional) - The full URL to be used to retrieve, for the first time, # the project files. They are copied directly to the $deploy_root @@ -117,6 +122,7 @@ define puppi::project::war ( $source, $deploy_root, + $war_file = undef, $init_source = '', $user = 'root', $predeploy_customcommand = '', @@ -173,8 +179,9 @@ $bool_check_deploy = any2bool($check_deploy) $bool_auto_deploy = any2bool($auto_deploy) - $war_file = url_parse($source,'filename') - + if ($war_file == undef) { + $war_file = url_parse($source,'filename') + } ### CREATE PROJECT puppi::project { $name: @@ -211,7 +218,7 @@ puppi::deploy { "${name}-Retrieve_WAR": priority => '20' , command => 'get_file.sh' , - arguments => "-s '${source}' -a '${real_always_deploy}'" , + arguments => "-s '${source}' -a '${real_always_deploy}' -f '${war_file}'" , user => 'root' , project => $name , enable => $enable , @@ -232,7 +239,7 @@ puppi::deploy { "${name}-Backup_existing_WAR": priority => '30' , command => 'archive.sh' , - arguments => "-b '${deploy_root}' -t war -s move -m diff -o '${backup_rsync_options}' -n '${backup_retention}'" , + arguments => "-b '${deploy_root}' -t war -s copy -m diff -o '${backup_rsync_options}' -n '${backup_retention}'" , user => 'root' , project => $name , enable => $enable , From 657fe09216c5c577f139579364ac287217eaf49e Mon Sep 17 00:00:00 2001 From: samukasmk Date: Mon, 24 Jun 2013 11:32:48 -0300 Subject: [PATCH 3/3] All Solutions of @SamukaSmk, (1.ErrorUsingUrlsWithParamAnd&characterAtBash), (2.FeatureSetDestWarFileName), 3.FeaturePassingParametersInHTTPAauthInPuppiProjectWar) --- manifests/project/war.pp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/manifests/project/war.pp b/manifests/project/war.pp index 1a92fed..9d5e1ff 100644 --- a/manifests/project/war.pp +++ b/manifests/project/war.pp @@ -29,6 +29,12 @@ # [*user*] # (Optional) - The user to be used for deploy operations. # +# [*http_user*] +# (Optional) - The user to be used for download the war file(s). +# +# [*http_pass*] +# (Optional) - The password to be used for download the war file(s). +# # [*predeploy_customcommand*] # (Optional) - Full path with arguments of an eventual custom command to # execute before the deploy. The command is executed as $predeploy_user. @@ -125,6 +131,8 @@ $war_file = undef, $init_source = '', $user = 'root', + $http_user = undef, + $http_pass = undef, $predeploy_customcommand = '', $predeploy_user = '', $predeploy_priority = '39', @@ -218,7 +226,7 @@ puppi::deploy { "${name}-Retrieve_WAR": priority => '20' , command => 'get_file.sh' , - arguments => "-s '${source}' -a '${real_always_deploy}' -f '${war_file}'" , + arguments => "-s '${source}' -a '${real_always_deploy}' -f '${war_file}' -u '${http_user}' -p '${http_pass}'" , user => 'root' , project => $name , enable => $enable ,