From 4999fa8d98931e927456af3dbc6d10ce259eef85 Mon Sep 17 00:00:00 2001 From: R-Rajkumar Date: Tue, 9 Sep 2014 21:59:01 +0530 Subject: [PATCH] re-organizing puppet modules --- tools/puppet3/manifests/nodes/default.pp | 1 + tools/puppet3/manifests/nodes/haproxy.pp | 5 +- .../_php.erb => manifests/nodes/jboss.pp} | 19 +- tools/puppet3/manifests/nodes/lb.pp | 5 +- tools/puppet3/manifests/nodes/mysql.pp | 7 +- tools/puppet3/manifests/nodes/nodejs.pp | 7 +- tools/puppet3/manifests/nodes/php.pp | 8 +- tools/puppet3/manifests/nodes/ruby.pp | 6 +- tools/puppet3/manifests/nodes/tomcat.pp | 5 +- tools/puppet3/manifests/nodes/wordpress.pp | 5 +- .../lib/puppet/parser/functions/difference.rb | 21 + tools/puppet3/modules/agent/manifests/init.pp | 50 +- .../modules/agent/manifests/push_templates.pp | 5 +- .../remove_templates.pp} | 8 +- .../extensions/artifacts-copy.sh.erb | 3 +- .../extensions/artifacts-updated.sh.erb | 6 - .../extensions/complete-tenant.sh.erb | 2 - .../extensions/complete-topology.sh.erb | 6 - .../extensions/member-activated.sh.erb | 279 +------ .../extensions/member-started.sh.erb | 17 +- .../extensions/member-suspended.sh.erb | 17 +- .../extensions/member-terminated.sh.erb | 15 - .../templates/extensions/start-servers.sh.erb | 285 +------ .../subscription-domain-added.sh.erb | 6 - .../subscription-domain-removed.sh.erb | 5 - tools/puppet3/modules/appserver/LICENSE | 13 + tools/puppet3/modules/appserver/Modulefile | 11 + tools/puppet3/modules/appserver/README | 11 + .../appserver/files/configs/README.txt | 5 + .../repository/components/lib/README.txt | 1 + .../appserver/files/patches/README.txt | 3 + .../repository/components/patches/README.txt | 1 + .../modules/appserver/lib/facter/java_home.rb | 5 + .../modules/appserver/manifests/clean.pp | 45 ++ .../modules/appserver/manifests/deploy.pp | 43 ++ .../modules/appserver/manifests/init.pp | 137 ++++ .../modules/appserver/manifests/initialize.pp | 59 ++ .../modules/appserver/manifests/params.pp | 74 ++ .../appserver/manifests/push_templates.pp | 26 + .../modules/appserver/manifests/start.pp | 28 + .../agent/extensions/artifacts-copy.sh.erb | 29 + .../agent/extensions/artifacts-updated.sh.erb | 28 + .../templates/agent/extensions/clean.sh.erb | 28 + .../agent/extensions/complete-tenant.sh.erb | 30 + .../agent/extensions/complete-topology.sh.erb | 34 + .../extensions/instance-activated.sh.erb | 28 + .../agent/extensions/instance-started.sh.erb | 27 + .../agent/extensions/member-activated.sh.erb | 303 ++++++++ .../agent/extensions/member-started.sh.erb | 43 ++ .../agent/extensions/member-suspended.sh.erb | 43 ++ .../agent/extensions/member-terminated.sh.erb | 43 ++ .../agent/extensions/mount-volumes.sh.erb | 87 +++ .../agent/extensions/start-servers.sh.erb | 308 ++++++++ .../subscription-domain-added.sh.erb | 35 + .../subscription-domain-removed.sh.erb | 34 + .../templates/conf/axis2/axis2.xml.erb | 713 ++++++++++++++++++ .../appserver/templates/conf/carbon.xml.erb | 626 +++++++++++++++ .../datasources/master-datasources.xml.erb | 72 ++ .../master-datasources/_remote.erb | 68 ++ .../templates/conf/log4j.properties.erb | 175 +++++ .../appserver/templates/conf/registry.xml.erb | 105 +++ .../templates/conf/registry/_remote.erb | 35 + .../conf/security/authenticators.xml.erb | 52 ++ .../conf/tomcat/catalina-server.xml.erb | 98 +++ .../appserver/templates/conf/user-mgt.xml.erb | 356 +++++++++ .../templates/conf/user-mgt/_roldap.erb | 32 + .../templates/conf/user-mgt/_rwldap.erb | 41 + .../puppet3/modules/haproxy/manifests/init.pp | 6 + tools/puppet3/modules/jboss/manifests/init.pp | 10 + .../agent/extensions/artifacts-updated.sh.erb | 30 + tools/puppet3/modules/lb/manifests/init.pp | 7 +- .../modules/lb/manifests/initialize.pp | 10 +- tools/puppet3/modules/mysql/manifests/init.pp | 10 + .../agent/extensions/instance-started.sh.erb} | 17 +- .../puppet3/modules/nodejs/manifests/init.pp | 11 + .../agent/extensions/start-servers.sh.erb} | 17 +- tools/puppet3/modules/php/manifests/init.pp | 11 + .../agent/extensions/artifacts-updated.sh.erb | 30 + tools/puppet3/modules/ruby/manifests/init.pp | 11 + .../agent/extensions/instance-started.sh.erb} | 18 +- .../puppet3/modules/tomcat/manifests/init.pp | 6 + .../modules/wordpress/manifests/init.pp | 5 + 82 files changed, 4228 insertions(+), 699 deletions(-) rename tools/puppet3/{modules/agent/templates/extensions/addons/_php.erb => manifests/nodes/jboss.pp} (62%) mode change 100755 => 100644 create mode 100755 tools/puppet3/modules/agent/lib/puppet/parser/functions/difference.rb rename tools/puppet3/modules/agent/{templates/extensions/addons/_jboss-as.erb => manifests/remove_templates.pp} (83%) mode change 100755 => 100644 create mode 100644 tools/puppet3/modules/appserver/LICENSE create mode 100644 tools/puppet3/modules/appserver/Modulefile create mode 100644 tools/puppet3/modules/appserver/README create mode 100644 tools/puppet3/modules/appserver/files/configs/README.txt create mode 100644 tools/puppet3/modules/appserver/files/configs/repository/components/lib/README.txt create mode 100644 tools/puppet3/modules/appserver/files/patches/README.txt create mode 100644 tools/puppet3/modules/appserver/files/patches/repository/components/patches/README.txt create mode 100644 tools/puppet3/modules/appserver/lib/facter/java_home.rb create mode 100644 tools/puppet3/modules/appserver/manifests/clean.pp create mode 100644 tools/puppet3/modules/appserver/manifests/deploy.pp create mode 100644 tools/puppet3/modules/appserver/manifests/init.pp create mode 100644 tools/puppet3/modules/appserver/manifests/initialize.pp create mode 100644 tools/puppet3/modules/appserver/manifests/params.pp create mode 100644 tools/puppet3/modules/appserver/manifests/push_templates.pp create mode 100644 tools/puppet3/modules/appserver/manifests/start.pp create mode 100644 tools/puppet3/modules/appserver/templates/agent/extensions/artifacts-copy.sh.erb create mode 100755 tools/puppet3/modules/appserver/templates/agent/extensions/artifacts-updated.sh.erb create mode 100755 tools/puppet3/modules/appserver/templates/agent/extensions/clean.sh.erb create mode 100644 tools/puppet3/modules/appserver/templates/agent/extensions/complete-tenant.sh.erb create mode 100644 tools/puppet3/modules/appserver/templates/agent/extensions/complete-topology.sh.erb create mode 100755 tools/puppet3/modules/appserver/templates/agent/extensions/instance-activated.sh.erb create mode 100755 tools/puppet3/modules/appserver/templates/agent/extensions/instance-started.sh.erb create mode 100644 tools/puppet3/modules/appserver/templates/agent/extensions/member-activated.sh.erb create mode 100644 tools/puppet3/modules/appserver/templates/agent/extensions/member-started.sh.erb create mode 100644 tools/puppet3/modules/appserver/templates/agent/extensions/member-suspended.sh.erb create mode 100644 tools/puppet3/modules/appserver/templates/agent/extensions/member-terminated.sh.erb create mode 100755 tools/puppet3/modules/appserver/templates/agent/extensions/mount-volumes.sh.erb create mode 100755 tools/puppet3/modules/appserver/templates/agent/extensions/start-servers.sh.erb create mode 100644 tools/puppet3/modules/appserver/templates/agent/extensions/subscription-domain-added.sh.erb create mode 100644 tools/puppet3/modules/appserver/templates/agent/extensions/subscription-domain-removed.sh.erb create mode 100644 tools/puppet3/modules/appserver/templates/conf/axis2/axis2.xml.erb create mode 100644 tools/puppet3/modules/appserver/templates/conf/carbon.xml.erb create mode 100644 tools/puppet3/modules/appserver/templates/conf/datasources/master-datasources.xml.erb create mode 100644 tools/puppet3/modules/appserver/templates/conf/datasources/master-datasources/_remote.erb create mode 100644 tools/puppet3/modules/appserver/templates/conf/log4j.properties.erb create mode 100644 tools/puppet3/modules/appserver/templates/conf/registry.xml.erb create mode 100644 tools/puppet3/modules/appserver/templates/conf/registry/_remote.erb create mode 100644 tools/puppet3/modules/appserver/templates/conf/security/authenticators.xml.erb create mode 100644 tools/puppet3/modules/appserver/templates/conf/tomcat/catalina-server.xml.erb create mode 100644 tools/puppet3/modules/appserver/templates/conf/user-mgt.xml.erb create mode 100644 tools/puppet3/modules/appserver/templates/conf/user-mgt/_roldap.erb create mode 100644 tools/puppet3/modules/appserver/templates/conf/user-mgt/_rwldap.erb create mode 100755 tools/puppet3/modules/jboss/templates/agent/extensions/artifacts-updated.sh.erb rename tools/puppet3/modules/{agent/templates/extensions/addons/_mysql.erb => mysql/templates/agent/extensions/instance-started.sh.erb} (72%) mode change 100644 => 100755 rename tools/puppet3/modules/{agent/templates/extensions/addons/_nodejs.erb => nodejs/templates/agent/extensions/start-servers.sh.erb} (67%) create mode 100755 tools/puppet3/modules/php/templates/agent/extensions/artifacts-updated.sh.erb rename tools/puppet3/modules/{agent/templates/extensions/addons/_ruby.erb => ruby/templates/agent/extensions/instance-started.sh.erb} (73%) mode change 100644 => 100755 diff --git a/tools/puppet3/manifests/nodes/default.pp b/tools/puppet3/manifests/nodes/default.pp index 1708013c40..4f420b2de8 100755 --- a/tools/puppet3/manifests/nodes/default.pp +++ b/tools/puppet3/manifests/nodes/default.pp @@ -17,6 +17,7 @@ # default (base) cartridge node node /default/ inherits base { + require java class {'agent':} diff --git a/tools/puppet3/manifests/nodes/haproxy.pp b/tools/puppet3/manifests/nodes/haproxy.pp index abce18b400..7229b52ce7 100755 --- a/tools/puppet3/manifests/nodes/haproxy.pp +++ b/tools/puppet3/manifests/nodes/haproxy.pp @@ -17,9 +17,6 @@ # haproxy extension loadbalancer cartridge node node /haproxy/ inherits base { - require java - class {'haproxy':} - class {'agent':} - Class['stratos_base'] -> Class['java'] -> Class['haproxy'] ~> Class['agent'] + class {'haproxy':} } diff --git a/tools/puppet3/modules/agent/templates/extensions/addons/_php.erb b/tools/puppet3/manifests/nodes/jboss.pp old mode 100755 new mode 100644 similarity index 62% rename from tools/puppet3/modules/agent/templates/extensions/addons/_php.erb rename to tools/puppet3/manifests/nodes/jboss.pp index adb80595e8..485d26a5e5 --- a/tools/puppet3/modules/agent/templates/extensions/addons/_php.erb +++ b/tools/puppet3/manifests/nodes/jboss.pp @@ -15,4 +15,21 @@ # specific language governing permissions and limitations # under the License. -chown -R www-data:www-data /var/www +# Jboss cartridge node +node /jboss/ inherits base { + + $product = 'jboss-as' + $version = '7.1.1.Final' + $docroot = "/mnt/${product}-${version}/standalone/deployments/" + $jboss_user = 'jbossas1' + $jboss_group = 'jboss' + + class {'jboss': + user => $jboss_user, + group => $jboss_group, + java_home => $java_home, + version => $version, + java_opts => "-Xms512m -Xmx3000m", + extra_jars => ['mysql-connector-java-5.1.29-bin.jar'] + } +} diff --git a/tools/puppet3/manifests/nodes/lb.pp b/tools/puppet3/manifests/nodes/lb.pp index 3faa7d9f49..d690effb7d 100755 --- a/tools/puppet3/manifests/nodes/lb.pp +++ b/tools/puppet3/manifests/nodes/lb.pp @@ -17,9 +17,6 @@ # loadbalancer cartridge node node /lb/ inherits base { - require java - class {'agent':} - class {'lb': maintenance_mode => 'norestart'} - Class['stratos_base'] -> Class['java'] -> Class['lb'] ~> Class['agent'] + class {'lb': maintenance_mode => 'norestart'} } diff --git a/tools/puppet3/manifests/nodes/mysql.pp b/tools/puppet3/manifests/nodes/mysql.pp index 9b62f7ebc0..9c9172784c 100755 --- a/tools/puppet3/manifests/nodes/mysql.pp +++ b/tools/puppet3/manifests/nodes/mysql.pp @@ -17,11 +17,6 @@ # mysql cartridge node node /mysql/ inherits base { - require java - class {'agent': - type => 'mysql', - } - class {'mysql':} - Class['stratos_base'] -> Class['java'] -> Class['mysql'] ~> Class['agent'] + class {'mysql':} } diff --git a/tools/puppet3/manifests/nodes/nodejs.pp b/tools/puppet3/manifests/nodes/nodejs.pp index e99cbc8f4e..50c8161988 100755 --- a/tools/puppet3/manifests/nodes/nodejs.pp +++ b/tools/puppet3/manifests/nodes/nodejs.pp @@ -17,11 +17,6 @@ # nodejs cartridge node node /nodejs/ inherits base { - require java - class {'agent': - type => 'nodejs', - } - class {'nodejs':} - Class['stratos_base'] -> Class['java'] -> Class['nodejs'] ~> Class['agent'] + class {'nodejs':} } diff --git a/tools/puppet3/manifests/nodes/php.pp b/tools/puppet3/manifests/nodes/php.pp index f16b9fd9bf..0d239e2f9d 100755 --- a/tools/puppet3/manifests/nodes/php.pp +++ b/tools/puppet3/manifests/nodes/php.pp @@ -17,16 +17,10 @@ # php cartridge node node /php/ inherits base { + $docroot = "/var/www/www" $syslog="/var/log/apache2/error.log" $samlalias="/var/www/" - require java - class {'agent': - type => 'php', - } class {'php':} - - #install stratos_base before java before php before agent - Class['stratos_base'] -> Class['java'] -> Class['php'] ~> Class['agent'] } diff --git a/tools/puppet3/manifests/nodes/ruby.pp b/tools/puppet3/manifests/nodes/ruby.pp index b4ade9881f..67dc7bd3b1 100755 --- a/tools/puppet3/manifests/nodes/ruby.pp +++ b/tools/puppet3/manifests/nodes/ruby.pp @@ -17,10 +17,6 @@ # ruby cartridge node node /ruby/ inherits base { - require java - class {'agent': - } - class {'ruby':} - Class['stratos_base'] -> Class['java'] -> Class['ruby'] ~> Class['agent'] + class {'ruby':} } diff --git a/tools/puppet3/manifests/nodes/tomcat.pp b/tools/puppet3/manifests/nodes/tomcat.pp index 8826d27b96..7e39204edb 100755 --- a/tools/puppet3/manifests/nodes/tomcat.pp +++ b/tools/puppet3/manifests/nodes/tomcat.pp @@ -17,12 +17,9 @@ # tomcat cartridge node node /tomcat/ inherits base { + $docroot = "/mnt/apache-tomcat-${tomcat_version}/webapps/" $samlalias="/mnt/apache-tomcat-${tomcat_version}/webapps/" - require java - class {'agent':} class {'tomcat':} - - Class['stratos_base'] -> Class['java'] -> Class['tomcat'] ~> Class['agent'] } diff --git a/tools/puppet3/manifests/nodes/wordpress.pp b/tools/puppet3/manifests/nodes/wordpress.pp index 7233842606..6f288862fb 100755 --- a/tools/puppet3/manifests/nodes/wordpress.pp +++ b/tools/puppet3/manifests/nodes/wordpress.pp @@ -17,10 +17,7 @@ #wordpress cartridge node node /wordpress/ inherits base { - require java - class {'agent':} + class {'wordpress':} class {'mysql':} - - Class['stratos_base'] -> Class['java'] -> Class['mysql'] -> Class['wordpress'] ~> Class['agent'] } diff --git a/tools/puppet3/modules/agent/lib/puppet/parser/functions/difference.rb b/tools/puppet3/modules/agent/lib/puppet/parser/functions/difference.rb new file mode 100755 index 0000000000..9be6e080f9 --- /dev/null +++ b/tools/puppet3/modules/agent/lib/puppet/parser/functions/difference.rb @@ -0,0 +1,21 @@ +# difference.rb +module Puppet::Parser::Functions + newfunction(:difference, :type => :rvalue +) do |arguments| + + # Two arguments are required + raise(Puppet::ParseError, "difference(): Wrong number of arguments " + + "given (#{arguments.size} for 2)") if arguments.size != 2 + + first = arguments[0] + second = arguments[1] + + unless first.is_a?(Array) && second.is_a?(Array) + raise(Puppet::ParseError, 'difference(): Requires 2 arrays') + end + + result = first - second + + return result + end +end diff --git a/tools/puppet3/modules/agent/manifests/init.pp b/tools/puppet3/modules/agent/manifests/init.pp index 2ab599c626..05d2b4c9c6 100644 --- a/tools/puppet3/modules/agent/manifests/init.pp +++ b/tools/puppet3/modules/agent/manifests/init.pp @@ -24,6 +24,9 @@ $enable_artifact_update = true, $auto_commit = false, $auto_checkout = true, + $module = 'undef', + $custom_templates = [], + $exclude_templates = [] ){ $deployment_code = 'cartridge-agent' @@ -33,9 +36,9 @@ tag($service_code) - $service_templates = [ + $default_templates = [ 'bin/stratos.sh', - 'conf/templates/jndi.properties.template', + 'conf/jndi.properties', 'conf/log4j.properties', 'extensions/clean.sh', 'extensions/instance-activated.sh', @@ -68,18 +71,53 @@ require => Agent::Initialize[$deployment_code]; } + # excluding templates which are not needed by a cartridge module from default_templates + $default_templates_excluded = difference($default_templates,$exclude_templates) + + # excluding custom_templates, if any,(which will be overrided by a cartridge module) from default_templates + $service_templates = $module ? { + 'undef' => $default_templates_excluded, + default => difference($default_templates_excluded,$custom_templates) + } + + # applying default extensions agent::push_templates { $service_templates: target => $carbon_home, + template_dir => "agent", require => Agent::Initialize[$deployment_code]; } + # applying custom extensions + unless $module == 'undef' { + agent::push_templates { + $custom_templates: + target => $carbon_home, + template_dir => "${module}/agent", + require => [Agent::Initialize[$deployment_code]] + } + } + + # removing default extensions which are shipped by agent.zip + agent::remove_templates { + $exclude_templates: + target => $carbon_home, + } + + $required_resources = $module ? { + 'undef' => [ + Exec['copy launch-params to carbon_home'], + Agent::Push_templates[$default_templates_excluded], + ], + default =>[ + Exec['copy launch-params to carbon_home'], + Agent::Push_templates[$default_templates_excluded], + Agent::Push_templates[$custom_templates] ] + } + agent::start { $deployment_code: owner => $owner, target => $carbon_home, - require => [ - Exec['copy launch-params to carbon_home'], - Agent::Push_templates[$service_templates], - ]; + require => $required_resources } } diff --git a/tools/puppet3/modules/agent/manifests/push_templates.pp b/tools/puppet3/modules/agent/manifests/push_templates.pp index e6d7a53ba4..035eb21e94 100755 --- a/tools/puppet3/modules/agent/manifests/push_templates.pp +++ b/tools/puppet3/modules/agent/manifests/push_templates.pp @@ -17,12 +17,13 @@ # Apply the templates -define agent::push_templates ($target) { +define agent::push_templates ($target,$template_dir) { file { "${target}/${name}": ensure => present, owner => $agent::owner, group => $agent::group, mode => '0755', - content => template("agent/${name}.erb"), + content => template("${template_dir}/${name}.erb"), } } + diff --git a/tools/puppet3/modules/agent/templates/extensions/addons/_jboss-as.erb b/tools/puppet3/modules/agent/manifests/remove_templates.pp old mode 100755 new mode 100644 similarity index 83% rename from tools/puppet3/modules/agent/templates/extensions/addons/_jboss-as.erb rename to tools/puppet3/modules/agent/manifests/remove_templates.pp index b6e23be641..5284e4405a --- a/tools/puppet3/modules/agent/templates/extensions/addons/_jboss-as.erb +++ b/tools/puppet3/modules/agent/manifests/remove_templates.pp @@ -15,4 +15,10 @@ # specific language governing permissions and limitations # under the License. -chown -R <%= @jboss_user %>:<%= @jboss_group %> <%= @docroot %> +# Removing default extensions shipped with agent + +define agent::remove_templates ($target) { + file { "${target}/${name}": + ensure => absent + } +} diff --git a/tools/puppet3/modules/agent/templates/extensions/artifacts-copy.sh.erb b/tools/puppet3/modules/agent/templates/extensions/artifacts-copy.sh.erb index 5cad830f6a..f25182fcaa 100644 --- a/tools/puppet3/modules/agent/templates/extensions/artifacts-copy.sh.erb +++ b/tools/puppet3/modules/agent/templates/extensions/artifacts-copy.sh.erb @@ -25,5 +25,4 @@ # log=/var/log/apache-stratos/cartridge-agent-extensions.log -cp -rf $1* $2 -echo "Artifacts Copied" | tee -a $log +echo `date`": Artifacts Copied: " | tee -a $log diff --git a/tools/puppet3/modules/agent/templates/extensions/artifacts-updated.sh.erb b/tools/puppet3/modules/agent/templates/extensions/artifacts-updated.sh.erb index 1735603c5a..15d5591cd6 100755 --- a/tools/puppet3/modules/agent/templates/extensions/artifacts-updated.sh.erb +++ b/tools/puppet3/modules/agent/templates/extensions/artifacts-updated.sh.erb @@ -26,9 +26,3 @@ log=/var/log/apache-stratos/cartridge-agent-extensions.log echo `date`": Artifacts Updated Event" | tee -a $log - -<%- if @type == 'php' -%> -<%= scope.function_template(['agent/extensions/addons/_php.erb']) -%> -<%- elsif @type == 'jboss-as' -%> -<%= scope.function_template(['agent/extensions/addons/_jboss-as.erb']) -%> -<%- end -%> diff --git a/tools/puppet3/modules/agent/templates/extensions/complete-tenant.sh.erb b/tools/puppet3/modules/agent/templates/extensions/complete-tenant.sh.erb index 2586474e5e..50e4506c17 100644 --- a/tools/puppet3/modules/agent/templates/extensions/complete-tenant.sh.erb +++ b/tools/puppet3/modules/agent/templates/extensions/complete-tenant.sh.erb @@ -26,5 +26,3 @@ log=/var/log/apache-stratos/cartridge-agent-extensions.log echo `date`": Complete Tenant Event: " | tee -a $log -echo "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log -echo "Tenant List: ${STRATOS_TENANT_LIST_JSON}" | tee -a $log diff --git a/tools/puppet3/modules/agent/templates/extensions/complete-topology.sh.erb b/tools/puppet3/modules/agent/templates/extensions/complete-topology.sh.erb index ea2e9416aa..a3311adc81 100644 --- a/tools/puppet3/modules/agent/templates/extensions/complete-topology.sh.erb +++ b/tools/puppet3/modules/agent/templates/extensions/complete-topology.sh.erb @@ -26,9 +26,3 @@ log=/var/log/apache-stratos/cartridge-agent-extensions.log echo `date`": Complete Topology Event: " | tee -a $log -echo "LB IP: ${STRATOS_LB_IP}" | tee -a $log -echo "LB PUBLIC IP: $STRATOS_LB_PUBLIC_IP}" | tee -a $log -echo "STRATOS_PARAM_FILE_PATH: ${STRATOS_PARAM_FILE_PATH}" -echo "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log -echo "Complete Topology: ${STRATOS_TOPOLOGY_JSON}" | tee -a $log -echo "Members in LB: ${STRATOS_MEMBERS_IN_LB_JSON}" | tee -a $log diff --git a/tools/puppet3/modules/agent/templates/extensions/member-activated.sh.erb b/tools/puppet3/modules/agent/templates/extensions/member-activated.sh.erb index f01d028cdc..f6e8201f4f 100644 --- a/tools/puppet3/modules/agent/templates/extensions/member-activated.sh.erb +++ b/tools/puppet3/modules/agent/templates/extensions/member-activated.sh.erb @@ -24,280 +24,5 @@ # -------------------------------------------------------------- # -# Execute error_handler function on script error -trap 'error_handler ${LINENO} $?' ERR - -log=/var/log/apache-stratos/cartridge-agent-extensions-member.activated.log -VERBOSE=1 -DATE=`which date` || print_error "date command not found" -ECHO=`which echo` || print_error "echo command not found" -GREP=`which grep` || print_error "grep command not found" -PS=`which ps` || print_error "ps command not found" -SED=`which sed` || print_error "sed command not found" - -function printParameters(){ - ${ECHO} -e "LB IP: ${STRATOS_LB_IP}" | tee -a $log - ${ECHO} -e "LB PUBLIC IP: ${STRATOS_LB_PUBLIC_IP}" | tee -a $log - ${ECHO} -e "STRATOS_PARAM_FILE_PATH: ${STRATOS_PARAM_FILE_PATH}" - ${ECHO} -e "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log - ${ECHO} -e "Complete Topology: ${STRATOS_TOPOLOGY_JSON}" | tee -a $log - ${ECHO} -e "Members in LB: ${STRATOS_MEMBERS_IN_LB_JSON}" | tee -a $log - ${ECHO} -e "APP_PATH: ${STRATOS_APP_PATH}" | tee -a $log -} - -function error_handler(){ - MYSELF="$0" # equals to script name - LASTLINE="$1" # argument 1: last line of error occurence - LASTERR="$2" # argument 2: error code of last command - echo "ERROR in ${MYSELF}: line ${LASTLINE}: exit status of last command: ${LASTERR}" - exit 1 -} - -function print_message(){ - if [ ${VERBOSE} -eq 1 ]; then - ${ECHO} -e "[INFO] " $1 | tee -a $log - fi -} - -function print_error(){ - ${ECHO} -e "[Error] " $1 | tee -a $log - exit 1 -} - -function verify_file_exists(){ - if [[ ! -f $1 ]] ; then - print_error "File not found: $1" - fi -} - -function update_hosts_file(){ - instance_hostname="<%= @stratos_instance_data_host_name %>" - (${GREP} -q "${instance_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${instance_hostname} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${instance_hostname}")) \ - || print_error "Failed to update '/etc/hosts' file. " - - map_to_lb="<%= @stratos_instance_data_map_to_lb %>" - arr=$(${ECHO} ${map_to_lb} | tr "," "\n") - - for map_hostname in $arr - do - (${GREP} -q "${map_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${map_hostname} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${map_hostname}")) \ - || print_error "Failed to update '/etc/hosts' file. " - done - - <%- if @stratos_instance_data_worker_host_name -%> - worker_hostname="<%= @stratos_instance_data_worker_host_name %>" - (${GREP} -q " ${worker_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${worker_hostname} # Stratos LB worker private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${worker_hostname}")) \ - || print_error "Failed to update '/etc/hosts' file. " - <%- end -%> - - if [[ "${STRATOS_SERVICE_NAME}" = "apistore" || "${STRATOS_SERVICE_NAME}" = "publisher" ]] ; then - gateway_host_name="<%= @stratos_instance_data_gateway_host_name %>" - gateway_mgt_host_name="<%= @stratos_instance_data_gateway_mgt_host_name %>" - keymanager_host_name="<%= @stratos_instance_data_keymanager_host_name %>" - - (${GREP} -q "${gateway_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${gateway_host_name} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${gateway_host_name}")) \ - || print_error "Failed to update '/etc/hosts' file. " - - (${GREP} -q "${gateway_mgt_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${gateway_mgt_host_name} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${gateway_mgt_host_name}")) \ - || print_error "Failed to update '/etc/hosts' file. " - - - (${GREP} -q "${keymanager_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${keymanager_host_name} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${keymanager_host_name}")) \ - || print_error "Failed to update '/etc/hosts' file. " - - elif [[ "${STRATOS_SERVICE_NAME}" = "gateway" || "${STRATOS_SERVICE_NAME}" = "gatewaymgt" ]] ; then - keymanager_hostname="<%= @stratos_instance_data_keymanager_host_name %>" - - (${GREP} -q "${keymanager_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${keymanager_hostname} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${keymanager_hostname}")) \ - || print_error "Failed to update '/etc/hosts' file. " - - fi -} - -function backup_file(){ - if [[ -f "$1.orig" ]]; - then - print_message "Restoring from the Original template file $1" - cp -f "$1.orig" "$1" - else - print_message "Creating a backup of the file $1" - cp -f "$1" "$1.orig" - fi -} - -function configure_manager_worker_wka_members(){ - - print_message "function configure_manager_worker_wka_members ..... " - - # generic worker manager seperation :D - if [[ -z ${STRATOS_WK_MANAGER_MEMBER_COUNT} || ${STRATOS_WK_MANAGER_MEMBER_COUNT} -eq 0 ]] ; then - print_message "manager WKA member count is zero or unavailable" - else - print_message "Configuring manager..." - print_message "configure_manager_worker_wka_members STRATOS_WK_MANAGER_MEMBER_COUNT ${STRATOS_WK_MANAGER_MEMBER_COUNT} ..... " - for i in `seq 0 $(( ${STRATOS_WK_MANAGER_MEMBER_COUNT} - 1 ))` - do - member_ip_name="STRATOS_WK_MANAGER_MEMBER_${i}_IP" - member_ip=${member_ip_name} - if [[ -z ${member_ip} ]] ; then - print_error "WKA is null for STRATOS_WK_MANAGER_MEMBER_${i}_IP" - fi - print_message "$i => ${member_ip}" - WKA_XML=$"${WKA_XML}${!member_ip}4000\n" - done - fi - - if [[ -z ${STRATOS_WK_WORKER_MEMBER_COUNT} || ${STRATOS_WK_WORKER_MEMBER_COUNT} -eq 0 ]] ; then - print_message "worker WKA member count is zero or unavailable" - else - print_message "Configuring worker..." - print_message "STRATOS_WK_WORKER_MEMBER_COUNT ${STRATOS_WK_WORKER_MEMBER_COUNT} ..... " - for i in `seq 0 $(( ${STRATOS_WK_WORKER_MEMBER_COUNT} - 1 ))` - do - member_ip_name="STRATOS_WK_WORKER_MEMBER_${i}_IP" - member_ip=${member_ip_name} - if [[ -z ${member_ip} ]] ; then - print_error "WKA is null for STRATOS_WK_WORKER_MEMBER_${i}_IP" - fi - print_message "$i => ${member_ip}" - WKA_XML=$"${WKA_XML}${!member_ip}4000\n" - done - fi - - print_message "${STRATOS_SERVICE_NAME} WKA_XML => ${WKA_XML}" - verify_file_exists ${AXIS2_XML_FILE} - ${SED} -i "s%${WKA_LINE}%${WKA_XML}%g" ${AXIS2_XML_FILE} && print_message "gateway WKA configuration successful" || print_error "Failed to configure well known members" - -} - - -function configure_wk_members(){ - - print_message "Performing clustering configuration for ${STRATOS_SERVICE_NAME}..." - - WKA_XML="" - KEYMGR_XML="" - WKA_LINE="@WELL_KNOWN_MEMBERS" - KEYMGR_LINE="@KEYMANAGER_SERVER_URL" - - AXIS2_XML_FILE=${STRATOS_APP_PATH}/repository/conf/axis2/axis2.xml - backup_file ${AXIS2_XML_FILE} - - - if [[ (! -z $STRATOS_SERVICE_GROUP) && "${STRATOS_SERVICE_GROUP}" = "apim" ]] ; then - print_message " STRATOS_SERVICE_GROUP_APIM ${STRATOS_SERVICE_GROUP} ..... " - API_MANAGER_XML_FILE=${STRATOS_APP_PATH}/repository/conf/api-manager.xml - backup_file ${API_MANAGER_XML_FILE} - - if [[ "${STRATOS_SERVICE_NAME}" = "apistore" || "${STRATOS_SERVICE_NAME}" = "publisher" ]] ; then - - print_message "Configuring axis2.xml for ${STRATOS_SERVICE_NAME}..." - WKA_XML=$"${WKA_XML}${STRATOS_WK_APISTORE_MEMBER_IP}4000\n" - WKA_XML=$"${WKA_XML}${STRATOS_WK_PUBLISHER_MEMBER_IP}4000\n" - print_message "${STRATOS_SERVICE_NAME} WKA_XML => ${WKA_XML}" - verify_file_exists ${AXIS2_XML_FILE} - ${SED} -i "s%${WKA_LINE}%${WKA_XML}%g" ${AXIS2_XML_FILE} && print_message "${STRATOS_SERVICE_NAME} WKA configuration successful" || print_error "Failed to configure well known members" - - elif [[ "${STRATOS_SERVICE_NAME}" = "keymanager" ]] ; then - - print_message "In keymanager...nothing to do" - - elif [[ "${STRATOS_SERVICE_NAME}" = "gateway" || "${STRATOS_SERVICE_NAME}" = "gatewaymgt" ]] ; then - - if [[ "${DEPLOYMENT}" = "manager" || "${DEPLOYMENT}" = "worker" ]] ; then - - configure_manager_worker_wka_members - fi - - fi - elif [[ "${DEPLOYMENT}" = "manager" || "${DEPLOYMENT}" = "worker" ]] ; then - print_message " Worker / Manager ..... ${DEPLOYMENT} " - configure_manager_worker_wka_members - else - print_message "Configuring ${STRATOS_SERVICE_NAME}..." - print_message "STRATOS_WK_MEMBER_COUNT ....... ${STRATOS_WK_MEMBER_COUNT} " - for i in `seq 0 $(( ${STRATOS_WK_MEMBER_COUNT} - 1 ))` - do - member_ip="STRATOS_WK_MEMBER_${i}_IP" - print_message " memberip ${member_ip} ....... " - if [[ -z ${!member_ip} ]] ; then - print_error "WKA is null for STRATOS_WK_MEMBER_${i}_IP" - fi - print_message "$i => ${!member_ip}" - WKA_XML=$"${WKA_XML}${!member_ip}4000\n" - done - - print_message "${STRATOS_SERVICE_NAME} WKA_XML => ${WKA_XML}" - verify_file_exists ${AXIS2_XML_FILE} - ${SED} -i "s%${WKA_LINE}%${WKA_XML}%g" ${AXIS2_XML_FILE} && print_message "${STRATOS_SERVICE_NAME} WKA configuration successful" || print_error "Failed to configure well known members" - fi -} - -function updateWKMembers() { - print_message "Update WKA Members...... " - # Check if APP_PATH exists - print_message "Stratos App path $STRATOS_APP_PATH ...... " - if [[ ! -d $STRATOS_APP_PATH ]] ; then - print_error "APP_PATH is not found at: ${STRATOS_APP_PATH}" - fi - - # Set JAVA_HOME if it is not already set - if [[ -z $JAVA_HOME ]] ; then - print_message "Setting JAVA_HOME to /opt/java" - export JAVA_HOME=/opt/java - fi - - print_message "Stopping wso2server.sh ...... " - # Kill Product server - $STRATOS_APP_PATH/bin/wso2server.sh stop > /dev/null 2>&1 & - sleep 10 - - # Check if clustering is enabled for this product - if [[ -z $STRATOS_CLUSTERING ]] ; then - ${ECHO} -e `date`": starting servers in stand-alone mode..." | tee -a $log - if [[ ${VERBOSE} -eq 1 ]]; then - printParameters - fi - - else - ${ECHO} -e `date`": starting servers in clustering mode..." | tee -a $log - if [[ ${VERBOSE} -eq 1 ]] ; then - printParameters - fi - # Do the WKA configuration to support clustering - configure_wk_members - fi - - #Backup hosts file - backup_file /etc/hosts - # Update the /etc/hosts file with LB instance IP - update_hosts_file - - # Run start server command - verify_file_exists $STRATOS_APP_PATH/bin/wso2server.sh - $STRATOS_APP_PATH/bin/wso2server.sh $* > /dev/null 2>&1 & - print_message "Executed run command: $STRATOS_APP_PATH/bin/wso2server.sh $*" - print_message "WK Members successfully updated." -} - -# ----------------------- -# Execution starts here -# ----------------------- - - print_message " Executing member activated extension " - print_message " Stratos UpdateWK_IP [$STRATOS_UPDATE_WK_IP] " -# Check if WK Update flag is set -if [[ $STRATOS_UPDATE_WK_IP = "true" ]]; then - print_message " Conditions successful for [$STRATOS_UPDATE_WK_IP] . Executing updateWKMembers " - updateWKMembers -fi - -${ECHO} -e `date`": member activated extension successfully completed." -# END +log=/var/log/apache-stratos/cartridge-agent-extensions.log +OUTPUT=`date`": Member Activated Event: " diff --git a/tools/puppet3/modules/agent/templates/extensions/member-started.sh.erb b/tools/puppet3/modules/agent/templates/extensions/member-started.sh.erb index 29f45c3d61..0b558b6eae 100644 --- a/tools/puppet3/modules/agent/templates/extensions/member-started.sh.erb +++ b/tools/puppet3/modules/agent/templates/extensions/member-started.sh.erb @@ -25,19 +25,4 @@ # log=/var/log/apache-stratos/cartridge-agent-extensions.log -OUTPUT=`date`": Member Started Event: " -OUTPUT="$OUTPUT MEMBER_ID: ${STRATOS_MEMBER_ID}, " -OUTPUT="$OUTPUT MEMBER_IP: ${STRATOS_MEMBER_IP}, " -OUTPUT="$OUTPUT CLUSTER_ID: ${STRATOS_CLUSTER_ID}, " -OUTPUT="$OUTPUT LB_CLUSTER_ID: ${STRATOS_LB_CLUSTER_ID}, " -OUTPUT="$OUTPUT NETWORK_PARTITION_ID: ${STRATOS_NETWORK_PARTITION_ID}, " -OUTPUT="$OUTPUT SERVICE_NAME: ${STRATOS_SERVICE_NAME}, " -OUTPUT="$OUTPUT PORTS: ${STRATOS_PORTS}," -OUTPUT="$OUTPUT STRATOS_LB_IP: ${STRATOS_LB_IP}," -OUTPUT="$OUTPUT STRATOS_LB_PUBLIC_IP: ${STRATOS_LB_PUBLIC_IP}," -OUTPUT="$OUTPUT APP_PATH: ${APP_PATH}," -OUTPUT="$OUTPUT STRATOS_PARAM_FILE_PATH: ${STRATOS_PARAM_FILE_PATH}" -echo $OUTPUT | tee -a $log -echo "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log -echo "Topology: ${STRATOS_TOPOLOGY_JSON}" | tee -a $log -echo "---------------" | tee -a $log +echo `date`": Member Started Event: " | tee -a $log diff --git a/tools/puppet3/modules/agent/templates/extensions/member-suspended.sh.erb b/tools/puppet3/modules/agent/templates/extensions/member-suspended.sh.erb index 866aa0d758..acf44b94b3 100644 --- a/tools/puppet3/modules/agent/templates/extensions/member-suspended.sh.erb +++ b/tools/puppet3/modules/agent/templates/extensions/member-suspended.sh.erb @@ -25,19 +25,4 @@ # log=/var/log/apache-stratos/cartridge-agent-extensions.log -OUTPUT=`date`": Member Suspended Event: " -OUTPUT="$OUTPUT MEMBER_ID: ${STRATOS_MEMBER_ID}, " -OUTPUT="$OUTPUT MEMBER_IP: ${STRATOS_MEMBER_IP}, " -OUTPUT="$OUTPUT CLUSTER_ID: ${STRATOS_CLUSTER_ID}, " -OUTPUT="$OUTPUT LB_CLUSTER_ID: ${STRATOS_LB_CLUSTER_ID}, " -OUTPUT="$OUTPUT NETWORK_PARTITION_ID: ${STRATOS_NETWORK_PARTITION_ID}, " -OUTPUT="$OUTPUT SERVICE_NAME: ${STRATOS_SERVICE_NAME}, " -OUTPUT="$OUTPUT PORTS: ${STRATOS_PORTS}," -OUTPUT="$OUTPUT STRATOS_LB_IP: ${STRATOS_LB_IP}," -OUTPUT="$OUTPUT STRATOS_LB_PUBLIC_IP: ${STRATOS_LB_PUBLIC_IP}," -OUTPUT="$OUTPUT APP_PATH: ${APP_PATH}," -OUTPUT="$OUTPUT STRATOS_PARAM_FILE_PATH: ${STRATOS_PARAM_FILE_PATH}" -echo $OUTPUT | tee -a $log -echo "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log -echo "Topology: ${STRATOS_TOPOLOGY_JSON}" | tee -a $log -echo "---------------" | tee -a $log +echo `date`": Member Suspended Event:" | tee -a $log diff --git a/tools/puppet3/modules/agent/templates/extensions/member-terminated.sh.erb b/tools/puppet3/modules/agent/templates/extensions/member-terminated.sh.erb index 89cedf6982..0e6962962d 100644 --- a/tools/puppet3/modules/agent/templates/extensions/member-terminated.sh.erb +++ b/tools/puppet3/modules/agent/templates/extensions/member-terminated.sh.erb @@ -26,18 +26,3 @@ log=/var/log/apache-stratos/cartridge-agent-extensions.log OUTPUT=`date`": Member Terminated Event: " -OUTPUT="$OUTPUT MEMBER_ID: ${STRATOS_MEMBER_ID}, " -OUTPUT="$OUTPUT MEMBER_IP: ${STRATOS_MEMBER_IP}, " -OUTPUT="$OUTPUT CLUSTER_ID: ${STRATOS_CLUSTER_ID}, " -OUTPUT="$OUTPUT LB_CLUSTER_ID: ${STRATOS_LB_CLUSTER_ID}, " -OUTPUT="$OUTPUT NETWORK_PARTITION_ID: ${STRATOS_NETWORK_PARTITION_ID}, " -OUTPUT="$OUTPUT SERVICE_NAME: ${STRATOS_SERVICE_NAME}, " -OUTPUT="$OUTPUT PORTS: ${STRATOS_PORTS}," -OUTPUT="$OUTPUT STRATOS_LB_IP: ${STRATOS_LB_IP}," -OUTPUT="$OUTPUT STRATOS_LB_PUBLIC_IP: ${STRATOS_LB_PUBLIC_IP}," -OUTPUT="$OUTPUT APP_PATH: ${APP_PATH}," -OUTPUT="$OUTPUT STRATOS_PARAM_FILE_PATH: ${STRATOS_PARAM_FILE_PATH}" -echo $OUTPUT | tee -a $log -echo "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log -echo "Topology: ${STRATOS_TOPOLOGY_JSON}" | tee -a $log -echo "---------------" | tee -a $log diff --git a/tools/puppet3/modules/agent/templates/extensions/start-servers.sh.erb b/tools/puppet3/modules/agent/templates/extensions/start-servers.sh.erb index 6e3490250a..bac3a577d4 100755 --- a/tools/puppet3/modules/agent/templates/extensions/start-servers.sh.erb +++ b/tools/puppet3/modules/agent/templates/extensions/start-servers.sh.erb @@ -23,286 +23,5 @@ # -------------------------------------------------------------- # -# Execute error_handler function on script error -trap 'error_handler ${LINENO} $?' ERR - -log=/var/log/apache-stratos/cartridge-agent-extensions-start.servers.log -VERBOSE=1 -DATE=`which date` || print_error "date command not found" -ECHO=`which echo` || print_error "echo command not found" -GREP=`which grep` || print_error "grep command not found" -PS=`which ps` || print_error "ps command not found" -SED=`which sed` || print_error "sed command not found" - -function printParameters(){ - ${ECHO} -e "LB IP: ${STRATOS_LB_IP}" | tee -a $log - ${ECHO} -e "LB PUBLIC IP: ${STRATOS_LB_PUBLIC_IP}" | tee -a $log - ${ECHO} -e "STRATOS_PARAM_FILE_PATH: ${STRATOS_PARAM_FILE_PATH}" - ${ECHO} -e "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log - ${ECHO} -e "Complete Topology: ${STRATOS_TOPOLOGY_JSON}" | tee -a $log - ${ECHO} -e "Members in LB: ${STRATOS_MEMBERS_IN_LB_JSON}" | tee -a $log - ${ECHO} -e "APP_PATH: ${STRATOS_APP_PATH}" | tee -a $log -} - -function error_handler(){ - MYSELF="$0" # equals to script name - LASTLINE="$1" # argument 1: last line of error occurence - LASTERR="$2" # argument 2: error code of last command - echo "ERROR in ${MYSELF}: line ${LASTLINE}: exit status of last command: ${LASTERR}" - exit 1 -} - -function print_message(){ - if [ ${VERBOSE} -eq 1 ]; then - ${ECHO} -e "[INFO] " $1 | tee -a $log - fi -} - -function print_error(){ - ${ECHO} -e "[Error] " $1 | tee -a $log - exit 1 -} - -function verify_file_exists(){ - if [[ ! -f $1 ]] ; then - print_error "File not found: $1" - fi -} - -function update_hosts_file(){ - instance_hostname="<%= @stratos_instance_data_host_name %>" - (${GREP} -q "${instance_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${instance_hostname} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${instance_hostname}")) \ - || print_error "Failed to update '/etc/hosts' file. " - - map_to_lb="<%= @stratos_instance_data_map_to_lb %>" - arr=$(${ECHO} ${map_to_lb} | tr "," "\n") - - for map_hostname in $arr - do - (${GREP} -q "${map_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${map_hostname} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${map_hostname}")) \ - || print_error "Failed to update '/etc/hosts' file. " - done - - map_to_ip="<%= @stratos_instance_data_map_to_ip %>" - arr=$(${ECHO} ${map_to_ip} | tr "," "\n") - - for mapping in $arr - do - - arrr=$(${ECHO} ${mapping} | tr "#" "\n") - map_hostname=${arrr[1]} - ip_to_map=${arrr[0]} - - (${GREP} -q "${map_hostname}" /etc/hosts || (${ECHO} "${ip_to_map} ${map_hostname} # Additional Mappings" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${ip_to_map} ${map_hostname}")) \ - || print_error "Failed to update '/etc/hosts' file. " - done - - - <%- if @stratos_instance_data_worker_host_name -%> - worker_hostname="<%= @stratos_instance_data_worker_host_name %>" - (${GREP} -q " ${worker_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${worker_hostname} # Stratos LB worker private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${worker_hostname}")) \ - || print_error "Failed to update '/etc/hosts' file. " - <%- end -%> - - if [[ "${STRATOS_SERVICE_NAME}" = "apistore" || "${STRATOS_SERVICE_NAME}" = "publisher" ]] ; then - gateway_host_name="<%= @stratos_instance_data_gateway_host_name %>" - gateway_mgt_host_name="<%= @stratos_instance_data_gateway_mgt_host_name %>" - keymanager_host_name="<%= @stratos_instance_data_keymanager_host_name %>" - - (${GREP} -q "${gateway_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${gateway_host_name} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${gateway_host_name}")) \ - || print_error "Failed to update '/etc/hosts' file. " - - (${GREP} -q "${gateway_mgt_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${gateway_mgt_host_name} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${gateway_mgt_host_name}")) \ - || print_error "Failed to update '/etc/hosts' file. " - - - (${GREP} -q "${keymanager_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${keymanager_host_name} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${keymanager_host_name}")) \ - || print_error "Failed to update '/etc/hosts' file. " - - elif [[ "${STRATOS_SERVICE_NAME}" = "gateway" || "${STRATOS_SERVICE_NAME}" = "gatewaymgt" ]] ; then - keymanager_hostname="<%= @stratos_instance_data_keymanager_host_name %>" - - (${GREP} -q "${keymanager_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${keymanager_hostname} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${keymanager_hostname}")) \ - || print_error "Failed to update '/etc/hosts' file. " - - elif [[ "${STRATOS_SERVICE_NAME}" = "keymanager" ]] ; then - gateway_host_name="<%= @stratos_instance_data_gateway_host_name %>" - - (${GREP} -q "${gateway_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${gateway_host_name} # Stratos LB instance private IP" >> /etc/hosts \ - && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${gateway_host_name}")) \ - || print_error "Failed to update '/etc/hosts' file. " - - - fi -} - -function backup_file(){ - if [[ -f "$1.orig" ]]; - then - print_message "Restoring from the Original template file $1" - cp -f "$1.orig" "$1" - else - print_message "Creating a backup of the file $1" - cp -f "$1" "$1.orig" - fi -} - -function configure_manager_worker_wka_members(){ - - # generic worker manager seperation :D - if [[ -z ${STRATOS_WK_MANAGER_MEMBER_COUNT} || ${STRATOS_WK_MANAGER_MEMBER_COUNT} -eq 0 ]] ; then - print_message "manager WKA member count is zero or unavailable" - else - print_message "Configuring manager..." - for i in `seq 0 $(( ${STRATOS_WK_MANAGER_MEMBER_COUNT} - 1 ))` - do - member_ip_name="STRATOS_WK_MANAGER_MEMBER_${i}_IP" - member_ip=${member_ip_name} - if [[ -z ${member_ip} ]] ; then - print_error "WKA is null for STRATOS_WK_MANAGER_MEMBER_${i}_IP" - fi - print_message "$i => ${member_ip}" - WKA_XML=$"${WKA_XML}${!member_ip}4000\n" - done - fi - - if [[ -z ${STRATOS_WK_WORKER_MEMBER_COUNT} || ${STRATOS_WK_WORKER_MEMBER_COUNT} -eq 0 ]] ; then - print_message "worker WKA member count is zero or unavailable" - else - print_message "Configuring worker..." - for i in `seq 0 $(( ${STRATOS_WK_WORKER_MEMBER_COUNT} - 1 ))` - do - member_ip_name="STRATOS_WK_WORKER_MEMBER_${i}_IP" - member_ip=${member_ip_name} - if [[ -z ${member_ip} ]] ; then - print_error "WKA is null for STRATOS_WK_WORKER_MEMBER_${i}_IP" - fi - print_message "$i => ${member_ip}" - WKA_XML=$"${WKA_XML}${!member_ip}4000\n" - done - fi - - print_message "${STRATOS_SERVICE_NAME} WKA_XML => ${WKA_XML}" - verify_file_exists ${AXIS2_XML_FILE} - ${SED} -i "s%${WKA_LINE}%${WKA_XML}%g" ${AXIS2_XML_FILE} && print_message "gateway WKA configuration successful" || print_error "Failed to configure well known members" - -} - - -function configure_wk_members(){ - - print_message "Performing clustering configuration for ${STRATOS_SERVICE_NAME}..." - - WKA_XML="" - KEYMGR_XML="" - WKA_LINE="@WELL_KNOWN_MEMBERS" - KEYMGR_LINE="@KEYMANAGER_SERVER_URL" - - AXIS2_XML_FILE=${STRATOS_APP_PATH}/repository/conf/axis2/axis2.xml - backup_file ${AXIS2_XML_FILE} - - - if [[ (! -z $STRATOS_SERVICE_GROUP) && "${STRATOS_SERVICE_GROUP}" = "apim" ]] ; then - API_MANAGER_XML_FILE=${STRATOS_APP_PATH}/repository/conf/api-manager.xml - backup_file ${API_MANAGER_XML_FILE} - - if [[ "${STRATOS_SERVICE_NAME}" = "apistore" || "${STRATOS_SERVICE_NAME}" = "publisher" ]] ; then - - print_message "Configuring axis2.xml for ${STRATOS_SERVICE_NAME}..." - WKA_XML=$"${WKA_XML}${STRATOS_WK_APISTORE_MEMBER_IP}4000\n" - WKA_XML=$"${WKA_XML}${STRATOS_WK_PUBLISHER_MEMBER_IP}4000\n" - print_message "${STRATOS_SERVICE_NAME} WKA_XML => ${WKA_XML}" - verify_file_exists ${AXIS2_XML_FILE} - ${SED} -i "s%${WKA_LINE}%${WKA_XML}%g" ${AXIS2_XML_FILE} && print_message "${STRATOS_SERVICE_NAME} WKA configuration successful" || print_error "Failed to configure well known members" - - elif [[ "${STRATOS_SERVICE_NAME}" = "keymanager" ]] ; then - - print_message "In keymanager...nothing to do" - - elif [[ "${STRATOS_SERVICE_NAME}" = "gateway" || "${STRATOS_SERVICE_NAME}" = "gatewaymgt" ]] ; then - - if [[ "${DEPLOYMENT}" = "manager" || "${DEPLOYMENT}" = "worker" ]] ; then - - configure_manager_worker_wka_members - fi - - fi - elif [[ "${DEPLOYMENT}" = "manager" || "${DEPLOYMENT}" = "worker" ]] ; then - - configure_manager_worker_wka_members - else - print_message "Configuring ${STRATOS_SERVICE_NAME}..." - for i in `seq 0 $(( ${STRATOS_WK_MEMBER_COUNT} - 1 ))` - do - member_ip="STRATOS_WK_MEMBER_${i}_IP" - if [[ -z ${!member_ip} ]] ; then - print_error "WKA is null for STRATOS_WK_MEMBER_${i}_IP" - fi - print_message "$i => ${!member_ip}" - WKA_XML=$"${WKA_XML}${!member_ip}4000\n" - done - - print_message "${STRATOS_SERVICE_NAME} WKA_XML => ${WKA_XML}" - verify_file_exists ${AXIS2_XML_FILE} - ${SED} -i "s%${WKA_LINE}%${WKA_XML}%g" ${AXIS2_XML_FILE} && print_message "${STRATOS_SERVICE_NAME} WKA configuration successful" || print_error "Failed to configure well known members" - fi -} - -# Check if APP_PATH exists -if [[ ! -d $STRATOS_APP_PATH ]] ; then - print_error "APP_PATH is not found at: ${STRATOS_APP_PATH}" -fi - -# Check if product server is already running -if [[ -f $STRATOS_APP_PATH/wso2carbon.pid ]] ; then - PID=`cat $STRATOS_APP_PATH/wso2carbon.pid` - if ${PS} -p $PID > /dev/null ; then - ${ECHO} -e `date`": process is already running...skipping start servers" - exit 0 - fi -fi - -# Set JAVA_HOME if it is not already set -if [[ -z $JAVA_HOME ]] ; then - print_message "Setting JAVA_HOME to /opt/java" - export JAVA_HOME=/opt/java -fi - -# Check if clustering is enabled for this product -if [[ -z $STRATOS_CLUSTERING ]] ; then - ${ECHO} -e `date`": starting servers in stand-alone mode..." | tee -a $log - if [[ ${VERBOSE} -eq 1 ]]; then - printParameters - fi - -else - ${ECHO} -e `date`": starting servers in clustering mode..." | tee -a $log - if [[ ${VERBOSE} -eq 1 ]] ; then - printParameters - fi - # Do the WKA configuration to support clustering - configure_wk_members -fi - -<%- if @using_dns == true -%> - #Update the DNS mapping -<%- else -%> - # Update the /etc/hosts file with LB instance IP - update_hosts_file -<%- end -%> - - -# Run start server command -verify_file_exists $STRATOS_APP_PATH/bin/wso2server.sh -$STRATOS_APP_PATH/bin/wso2server.sh $* > /dev/null 2>&1 & -print_message "Executed run command: $STRATOS_APP_PATH/bin/wso2server.sh $*" -${ECHO} -e `date`": start servers extension successfully completed." - +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo `date`": Starting servers" | tee -a $log diff --git a/tools/puppet3/modules/agent/templates/extensions/subscription-domain-added.sh.erb b/tools/puppet3/modules/agent/templates/extensions/subscription-domain-added.sh.erb index 9ef88a2134..a8b7459d34 100644 --- a/tools/puppet3/modules/agent/templates/extensions/subscription-domain-added.sh.erb +++ b/tools/puppet3/modules/agent/templates/extensions/subscription-domain-added.sh.erb @@ -26,10 +26,4 @@ log=/var/log/apache-stratos/cartridge-agent-extensions.log OUTPUT=`date`": Subscription Domain Added Event" -OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_SERVICE_NAME: ${STRATOS_SUBSCRIPTION_SERVICE_NAME}," -OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_DOMAIN_NAME: ${STRATOS_SUBSCRIPTION_DOMAIN_NAME}," -OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_TENANT_ID: ${STRATOS_SUBSCRIPTION_TENANT_ID}," -OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_TENANT_DOMAIN: $STRATOS_SUBSCRIPTION_TENANT_DOMAIN}," -OUTPUT="$OUTPUT APP_PATH: ${APP_PATH}," -OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_APPLICATION_CONTEXT: ${STRATOS_SUBSCRIPTION_APPLICATION_CONTEXT}" echo $OUTPUT | tee -a $log diff --git a/tools/puppet3/modules/agent/templates/extensions/subscription-domain-removed.sh.erb b/tools/puppet3/modules/agent/templates/extensions/subscription-domain-removed.sh.erb index ff7b56ba08..3612bb6aaf 100644 --- a/tools/puppet3/modules/agent/templates/extensions/subscription-domain-removed.sh.erb +++ b/tools/puppet3/modules/agent/templates/extensions/subscription-domain-removed.sh.erb @@ -26,9 +26,4 @@ log=/var/log/apache-stratos/cartridge-agent-extensions.log OUTPUT=`date`": Subscription Domain Removed Event" -OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_SERVICE_NAME: ${STRATOS_SUBSCRIPTION_SERVICE_NAME}," -OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_DOMAIN_NAME: ${STRATOS_SUBSCRIPTION_DOMAIN_NAME}," -OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_TENANT_ID: ${STRATOS_SUBSCRIPTION_TENANT_ID}," -OUTPUT="$OUTPUT APP_PATH: ${APP_PATH}," -OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_TENANT_DOMAIN: $STRATOS_SUBSCRIPTION_TENANT_DOMAIN}" echo $OUTPUT | tee -a $log diff --git a/tools/puppet3/modules/appserver/LICENSE b/tools/puppet3/modules/appserver/LICENSE new file mode 100644 index 0000000000..1efdbc615c --- /dev/null +++ b/tools/puppet3/modules/appserver/LICENSE @@ -0,0 +1,13 @@ +Copyright 2005-2013 WSO2, Inc. http://www.wso2.org + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/tools/puppet3/modules/appserver/Modulefile b/tools/puppet3/modules/appserver/Modulefile new file mode 100644 index 0000000000..bd7283859f --- /dev/null +++ b/tools/puppet3/modules/appserver/Modulefile @@ -0,0 +1,11 @@ +name 'wso2-appserver' +version '0.1.0' +source '' +author 'WSO2 Inc' +license 'Apache License Version 2.0' +summary 'WSO2 AS puppet module' +description 'WSO2 AS 5.2.1 version puppet module' +project_page '' + +## Add dependencies, if any: +# dependency 'username/name', '>= 1.2.0' diff --git a/tools/puppet3/modules/appserver/README b/tools/puppet3/modules/appserver/README new file mode 100644 index 0000000000..dba02ba72c --- /dev/null +++ b/tools/puppet3/modules/appserver/README @@ -0,0 +1,11 @@ +Requirements: + Java, unzip, wget, mysql-connector jar (If connecting to a mysql database) + +How to use: +1. Import wso2.pp to sites.pp file in Puppet master. +2. Change the variables in params.pp accordingly. +3. Create a directory inside files/configs/repository/components/lib and copy + the mysql connector jar file. +4. Download the WSO2 Appserver pack to a file server and add the URL to + $package_repo in wso2.pp +5. Add/Remove (comment/uncomment) service_templates from init.pp as required diff --git a/tools/puppet3/modules/appserver/files/configs/README.txt b/tools/puppet3/modules/appserver/files/configs/README.txt new file mode 100644 index 0000000000..d5ed7a9f41 --- /dev/null +++ b/tools/puppet3/modules/appserver/files/configs/README.txt @@ -0,0 +1,5 @@ +Copy configuration files here. + +The contents in this directory will be copied to CARBON_HOME. If you need to copy +your configuration files to CARBON_HOME/repository/conf you need to have the +same directory structure under this directory. diff --git a/tools/puppet3/modules/appserver/files/configs/repository/components/lib/README.txt b/tools/puppet3/modules/appserver/files/configs/repository/components/lib/README.txt new file mode 100644 index 0000000000..c83339abc2 --- /dev/null +++ b/tools/puppet3/modules/appserver/files/configs/repository/components/lib/README.txt @@ -0,0 +1 @@ +Copy mysql connect jar here diff --git a/tools/puppet3/modules/appserver/files/patches/README.txt b/tools/puppet3/modules/appserver/files/patches/README.txt new file mode 100644 index 0000000000..a6a2241b05 --- /dev/null +++ b/tools/puppet3/modules/appserver/files/patches/README.txt @@ -0,0 +1,3 @@ +The contents in this directory will be copied to CARBON_HOME. If you need to copy +your patches to CARBON_HOME/repository/components/patches you need to have the +same directory structure under this directory. diff --git a/tools/puppet3/modules/appserver/files/patches/repository/components/patches/README.txt b/tools/puppet3/modules/appserver/files/patches/repository/components/patches/README.txt new file mode 100644 index 0000000000..c2fadc5573 --- /dev/null +++ b/tools/puppet3/modules/appserver/files/patches/repository/components/patches/README.txt @@ -0,0 +1 @@ +Copy patches here diff --git a/tools/puppet3/modules/appserver/lib/facter/java_home.rb b/tools/puppet3/modules/appserver/lib/facter/java_home.rb new file mode 100644 index 0000000000..9aa9d56d36 --- /dev/null +++ b/tools/puppet3/modules/appserver/lib/facter/java_home.rb @@ -0,0 +1,5 @@ +Facter.add(:java_home) do + setcode do + java_home = ENV['JAVA_HOME'] + end +end diff --git a/tools/puppet3/modules/appserver/manifests/clean.pp b/tools/puppet3/modules/appserver/manifests/clean.pp new file mode 100644 index 0000000000..7c219b6932 --- /dev/null +++ b/tools/puppet3/modules/appserver/manifests/clean.pp @@ -0,0 +1,45 @@ +# ---------------------------------------------------------------------------- +# Copyright 2005-2013 WSO2, Inc. http://www.wso2.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------- +# +# Cleans the previous deployment. If the maintenance mode is set to true, this will only kill the running service. + +define appserver::clean ($mode, $target) { + if $mode == 'refresh' { + exec{ + "Remove_lock_file_${name}": + path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + onlyif => "test -f ${target}/wso2carbon.lck", + command => "rm ${target}/wso2carbon.lck"; + + "Stop_process_${name}": + path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/bin/', + command => "kill -9 `cat ${target}/wso2carbon.pid` ; /bin/echo Killed", + require => Exec["Remove_lock_file_${name}"]; + } + } + elsif $mode == 'new' { + exec { "Stop_process_and_remove_CARBON_HOME_${name}": + path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/bin/', + command => "kill -9 `cat ${target}/wso2carbon.pid` ; rm -rf ${target}"; + } + } + elsif $mode == 'zero' { + exec { "Stop_process_remove_CARBON_HOME_and_pack_${name}": + path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/bin/', + command => "kill -9 `cat ${target}/wso2carbon.pid` ; rm -rf ${target} ; rm -f ${::local_package_dir}/wso2${appserver::service_code}-${appserver::version}.zip"; + } + } +} diff --git a/tools/puppet3/modules/appserver/manifests/deploy.pp b/tools/puppet3/modules/appserver/manifests/deploy.pp new file mode 100644 index 0000000000..78889db007 --- /dev/null +++ b/tools/puppet3/modules/appserver/manifests/deploy.pp @@ -0,0 +1,43 @@ +# ---------------------------------------------------------------------------- +# Copyright 2005-2013 WSO2, Inc. http://www.wso2.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------- +# +# Executes the deployment by pushing all necessary configurations and patches + +define appserver::deploy ($security, $target, $owner, $group) { + file { "/tmp/${appserver::deployment_code}": + ensure => present, + owner => $owner, + group => $group, + sourceselect => all, + ignore => '.svn', + recurse => true, + source => [ + 'puppet:///modules/appserver/configs/', + 'puppet:///modules/appserver/patches/'] + } + + exec { + "Copy_${name}_modules_to_carbon_home": + path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/bin/', + command => "cp -r /tmp/${appserver::deployment_code}/* ${target}/; chown -R ${owner}:${owner} ${target}/; chmod -R 755 ${target}/", + require => File["/tmp/${appserver::deployment_code}"]; + + "Remove_${name}_temporory_modules_directory": + path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/bin/', + command => "rm -rf /tmp/${appserver::deployment_code}", + require => Exec["Copy_${name}_modules_to_carbon_home"]; + } +} diff --git a/tools/puppet3/modules/appserver/manifests/init.pp b/tools/puppet3/modules/appserver/manifests/init.pp new file mode 100644 index 0000000000..fe0ec4d6b3 --- /dev/null +++ b/tools/puppet3/modules/appserver/manifests/init.pp @@ -0,0 +1,137 @@ +# ---------------------------------------------------------------------------- +# Copyright 2005-2013 WSO2, Inc. http://www.wso2.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------- +# +# Class: appserver +# +# This class installs WSO2 Appserver +# +# Parameters: +# version => '5.2.1' +# offset => 1, +# hazelcast_port => 4100, +# config_db => 'as_config', +# maintenance_mode => 'zero', +# depsync => false, +# sub_cluster_domain => 'mgt', +# clustering => true, +# owner => 'root', +# group => 'root', +# target => '/mnt/${server_ip}/', +# members => {'elb2.wso2.com' => 4010, 'elb.wso2.com' => 4010 } +# +# Actions: +# - Install WSO2 Appserver +# +# Requires: +# +# Sample Usage: +# + +class appserver ( + $version = undef, + $sub_cluster_domain = undef, + $members = undef, + $offset = 0, + $hazelcast_port = 4000, + $config_db = 'governance', + $config_target_path = 'config/as', + $maintenance_mode = true, + $depsync = false, + $clustering = false, + $cloud = true, + $owner = 'root', + $group = 'root', + $target = "/mnt/${server_ip}", +) inherits params { + + $deployment_code = 'appserver' + $carbon_version = $version + $service_code = 'as' + $carbon_home = "${target}/wso2${service_code}-${carbon_version}" + + $service_templates = $sub_cluster_domain ? { + 'mgt' => [ + 'conf/axis2/axis2.xml', + 'conf/carbon.xml', +# 'conf/datasources/master-datasources.xml', +# 'conf/registry.xml', +# 'conf/tomcat/catalina-server.xml', +# 'conf/user-mgt.xml', + ], + 'worker' => [ + 'conf/axis2/axis2.xml', + 'conf/carbon.xml', +# 'conf/datasources/master-datasources.xml', +# 'conf/registry.xml', +# 'conf/tomcat/catalina-server.xml', +# 'conf/user-mgt.xml', + ], + default => [ + 'conf/axis2/axis2.xml', + 'conf/carbon.xml', + 'conf/datasources/master-datasources.xml', + 'conf/registry.xml', + 'conf/tomcat/catalina-server.xml', + 'conf/user-mgt.xml', + 'conf/log4j.properties', + 'conf/security/authenticators.xml', + ], + } + + tag($service_code) + + appserver::clean { $deployment_code: + mode => $maintenance_mode, + target => $carbon_home, + } + + appserver::initialize { $deployment_code: + repo => $package_repo, + version => $carbon_version, + service => $service_code, + local_dir => $local_package_dir, + target => $target, + mode => $maintenance_mode, + owner => $owner, + require => Appserver::Clean[$deployment_code], + } + + appserver::deploy { $deployment_code: + security => true, + owner => $owner, + group => $group, + target => $carbon_home, + require => Appserver::Initialize[$deployment_code], + } + + appserver::push_templates { + $service_templates: + target => $carbon_home, + directory => $deployment_code, + require => Appserver::Deploy[$deployment_code]; + } + +# appserver::start { $deployment_code: +# owner => $owner, +# target => $carbon_home, +# require => [ +# Appserver::Initialize[$deployment_code], +# Appserver::Deploy[$deployment_code], +# Push_templates[$service_templates], +# ], +# } + +} diff --git a/tools/puppet3/modules/appserver/manifests/initialize.pp b/tools/puppet3/modules/appserver/manifests/initialize.pp new file mode 100644 index 0000000000..939bfb6b43 --- /dev/null +++ b/tools/puppet3/modules/appserver/manifests/initialize.pp @@ -0,0 +1,59 @@ +# ---------------------------------------------------------------------------- +# Copyright 2005-2013 WSO2, Inc. http://www.wso2.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------- +# +# Initializing the deployment + +define appserver::initialize ($repo, $version, $service, $local_dir, $target, $mode, $owner,) { + + exec { + "creating_target_for_${name}": + path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + command => "mkdir -p ${target}"; + + "creating_local_package_repo_for_${name}": + path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/bin/', + unless => "test -d ${local_dir}", + command => "mkdir -p ${local_dir}"; + } + + file { + "/${local_dir}/wso2${service}-${version}.zip": + ensure => present, + source => ["puppet:///modules/appserver/wso2${service}-${version}.zip", "puppet:///packs/wso2${service}-${version}.zip"], + require => Exec["creating_local_package_repo_for_${name}", "creating_target_for_${name}"]; + } + + exec { + "extracting_wso2${service}-${version}.zip_for_${name}": + path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + cwd => $target, + unless => "test -d ${target}/wso2${service}-${version}/repository", + command => "unzip ${local_dir}/wso2${service}-${version}.zip", + logoutput => 'on_failure', + creates => "${target}/wso2${service}-${version}/repository", + timeout => 0, + require => File["/${local_dir}/wso2${service}-${version}.zip"]; + + "setting_permission_for_${name}": + path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + cwd => $target, + command => "chown -R ${owner}:${owner} ${target}/wso2${service}-${version} ; + chmod -R 755 ${target}/wso2${service}-${version}", + logoutput => 'on_failure', + timeout => 0, + require => Exec["extracting_wso2${service}-${version}.zip_for_${name}"]; + } +} diff --git a/tools/puppet3/modules/appserver/manifests/params.pp b/tools/puppet3/modules/appserver/manifests/params.pp new file mode 100644 index 0000000000..e9b2fd2097 --- /dev/null +++ b/tools/puppet3/modules/appserver/manifests/params.pp @@ -0,0 +1,74 @@ +# ---------------------------------------------------------------------------- +# Copyright 2005-2013 WSO2, Inc. http://www.wso2.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------- +# +# Class appserver::params +# +# This class manages appserver parameters +# +# Parameters: +# +# Usage: Uncomment the variable and assign a value to override the wso2.pp value +# +# + +class appserver::params { + #$package_repo = 'http://ec2-54-251-18-7.ap-southeast-1.compute.amazonaws.com' + $depsync_svn_repo = 'https://svn.appfactory.domain.com/wso2/repo/' + $local_package_dir = '/mnt/packs' + + # Service subdomains + $domain = 'wso2.com' + $as_subdomain = 'appserver' + $management_subdomain = 'management' + + $admin_username = 'ADMIN_USER' + $admin_password = 'ADMIN_PASSWORD' + + # MySQL server configuration details + #$mysql_server = 'ec2-54-254-43-232.ap-southeast-1.compute.amazonaws.com' + #$mysql_port = '3306' + #$max_connections = '100000' + #$max_active = '150' + #$max_wait = '360000' + + # Database details + $registry_user = 'DB_USER' + $registry_password = 'DB_PASSWORD' + $registry_database = 'REGISTRY_DB' + + $userstore_user = 'DB_USER' + $userstore_password = 'DB_PASSWORD' + $userstore_database = 'USERSTORE_DB' + + # Depsync settings + $svn_user = 'wso2' + $svn_password = 'wso2123' + + # Auto-scaler + $auto_scaler_epr = 'http://xxx:9863/services/AutoscalerService/' + + #LDAP settings + $ldap_connection_uri = 'ldap://localhost:10389' + $bind_dn = 'uid=admin,ou=system' + $bind_dn_password = 'adminpassword' + $user_search_base = 'ou=system' + $group_search_base = 'ou=system' + $sharedgroup_search_base = 'ou=SharedGroups,dc=wso2,dc=org' + + #Proxy ports + $http_proxy_port = '80' + $https_proxy_port = '443' +} diff --git a/tools/puppet3/modules/appserver/manifests/push_templates.pp b/tools/puppet3/modules/appserver/manifests/push_templates.pp new file mode 100644 index 0000000000..4351ce2cdc --- /dev/null +++ b/tools/puppet3/modules/appserver/manifests/push_templates.pp @@ -0,0 +1,26 @@ +# ---------------------------------------------------------------------------- +# Copyright 2005-2013 WSO2, Inc. http://www.wso2.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------- +# +# Apply the templates +define appserver::push_templates ($directory, $target) { + file { "${target}/repository/${name}": + ensure => present, + owner => $appserver::owner, + group => $appserver::group, + mode => '0755', + content => template("${directory}/${name}.erb"), + } +} diff --git a/tools/puppet3/modules/appserver/manifests/start.pp b/tools/puppet3/modules/appserver/manifests/start.pp new file mode 100644 index 0000000000..033a052ab9 --- /dev/null +++ b/tools/puppet3/modules/appserver/manifests/start.pp @@ -0,0 +1,28 @@ +# ---------------------------------------------------------------------------- +# Copyright 2005-2013 WSO2, Inc. http://www.wso2.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ---------------------------------------------------------------------------- +# +# Starts the service once the deployment is successful. + +define appserver::start ($target, $owner) { + exec { "strating_${name}": + user => $owner, + environment => "JAVA_HOME=$java_home", + path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/bin/', + unless => "test -f ${target}/wso2carbon.lck", + command => "touch ${target}/wso2carbon.lck; ${target}/bin/wso2server.sh > /dev/null 2>&1 &", + creates => "${target}/repository/wso2carbon.log", + } +} diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/artifacts-copy.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/artifacts-copy.sh.erb new file mode 100644 index 0000000000..5cad830f6a --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/artifacts-copy.sh.erb @@ -0,0 +1,29 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed once the update artifacts +# event is received and they are copied to the given path. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +cp -rf $1* $2 +echo "Artifacts Copied" | tee -a $log diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/artifacts-updated.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/artifacts-updated.sh.erb new file mode 100755 index 0000000000..15d5591cd6 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/artifacts-updated.sh.erb @@ -0,0 +1,28 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed once the update artifacts +# event is received and they are copied to the given path. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo `date`": Artifacts Updated Event" | tee -a $log diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/clean.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/clean.sh.erb new file mode 100755 index 0000000000..c62ad35145 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/clean.sh.erb @@ -0,0 +1,28 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed when stratos manager requests +# to clean up the instance before terminating it. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo `date`": Cleaning the cartridge" | tee -a $log diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/complete-tenant.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/complete-tenant.sh.erb new file mode 100644 index 0000000000..2586474e5e --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/complete-tenant.sh.erb @@ -0,0 +1,30 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed when complete tenant +# event is received. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo `date`": Complete Tenant Event: " | tee -a $log +echo "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log +echo "Tenant List: ${STRATOS_TENANT_LIST_JSON}" | tee -a $log diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/complete-topology.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/complete-topology.sh.erb new file mode 100644 index 0000000000..ea2e9416aa --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/complete-topology.sh.erb @@ -0,0 +1,34 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed when complete topology +# event is received. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo `date`": Complete Topology Event: " | tee -a $log +echo "LB IP: ${STRATOS_LB_IP}" | tee -a $log +echo "LB PUBLIC IP: $STRATOS_LB_PUBLIC_IP}" | tee -a $log +echo "STRATOS_PARAM_FILE_PATH: ${STRATOS_PARAM_FILE_PATH}" +echo "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log +echo "Complete Topology: ${STRATOS_TOPOLOGY_JSON}" | tee -a $log +echo "Members in LB: ${STRATOS_MEMBERS_IN_LB_JSON}" | tee -a $log diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/instance-activated.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/instance-activated.sh.erb new file mode 100755 index 0000000000..f5d60e8305 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/instance-activated.sh.erb @@ -0,0 +1,28 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed once the instance is +# activated and ready to serve incoming requests. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo `date`": Instance activated" | tee -a $log diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/instance-started.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/instance-started.sh.erb new file mode 100755 index 0000000000..7b5aa6aea4 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/instance-started.sh.erb @@ -0,0 +1,27 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed once the instance is started. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo `date`": Instance Started Event: " | tee -a $log diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/member-activated.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/member-activated.sh.erb new file mode 100644 index 0000000000..f01d028cdc --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/member-activated.sh.erb @@ -0,0 +1,303 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed when member activated +# event is received. +# -------------------------------------------------------------- +# + +# Execute error_handler function on script error +trap 'error_handler ${LINENO} $?' ERR + +log=/var/log/apache-stratos/cartridge-agent-extensions-member.activated.log +VERBOSE=1 +DATE=`which date` || print_error "date command not found" +ECHO=`which echo` || print_error "echo command not found" +GREP=`which grep` || print_error "grep command not found" +PS=`which ps` || print_error "ps command not found" +SED=`which sed` || print_error "sed command not found" + +function printParameters(){ + ${ECHO} -e "LB IP: ${STRATOS_LB_IP}" | tee -a $log + ${ECHO} -e "LB PUBLIC IP: ${STRATOS_LB_PUBLIC_IP}" | tee -a $log + ${ECHO} -e "STRATOS_PARAM_FILE_PATH: ${STRATOS_PARAM_FILE_PATH}" + ${ECHO} -e "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log + ${ECHO} -e "Complete Topology: ${STRATOS_TOPOLOGY_JSON}" | tee -a $log + ${ECHO} -e "Members in LB: ${STRATOS_MEMBERS_IN_LB_JSON}" | tee -a $log + ${ECHO} -e "APP_PATH: ${STRATOS_APP_PATH}" | tee -a $log +} + +function error_handler(){ + MYSELF="$0" # equals to script name + LASTLINE="$1" # argument 1: last line of error occurence + LASTERR="$2" # argument 2: error code of last command + echo "ERROR in ${MYSELF}: line ${LASTLINE}: exit status of last command: ${LASTERR}" + exit 1 +} + +function print_message(){ + if [ ${VERBOSE} -eq 1 ]; then + ${ECHO} -e "[INFO] " $1 | tee -a $log + fi +} + +function print_error(){ + ${ECHO} -e "[Error] " $1 | tee -a $log + exit 1 +} + +function verify_file_exists(){ + if [[ ! -f $1 ]] ; then + print_error "File not found: $1" + fi +} + +function update_hosts_file(){ + instance_hostname="<%= @stratos_instance_data_host_name %>" + (${GREP} -q "${instance_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${instance_hostname} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${instance_hostname}")) \ + || print_error "Failed to update '/etc/hosts' file. " + + map_to_lb="<%= @stratos_instance_data_map_to_lb %>" + arr=$(${ECHO} ${map_to_lb} | tr "," "\n") + + for map_hostname in $arr + do + (${GREP} -q "${map_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${map_hostname} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${map_hostname}")) \ + || print_error "Failed to update '/etc/hosts' file. " + done + + <%- if @stratos_instance_data_worker_host_name -%> + worker_hostname="<%= @stratos_instance_data_worker_host_name %>" + (${GREP} -q " ${worker_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${worker_hostname} # Stratos LB worker private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${worker_hostname}")) \ + || print_error "Failed to update '/etc/hosts' file. " + <%- end -%> + + if [[ "${STRATOS_SERVICE_NAME}" = "apistore" || "${STRATOS_SERVICE_NAME}" = "publisher" ]] ; then + gateway_host_name="<%= @stratos_instance_data_gateway_host_name %>" + gateway_mgt_host_name="<%= @stratos_instance_data_gateway_mgt_host_name %>" + keymanager_host_name="<%= @stratos_instance_data_keymanager_host_name %>" + + (${GREP} -q "${gateway_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${gateway_host_name} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${gateway_host_name}")) \ + || print_error "Failed to update '/etc/hosts' file. " + + (${GREP} -q "${gateway_mgt_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${gateway_mgt_host_name} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${gateway_mgt_host_name}")) \ + || print_error "Failed to update '/etc/hosts' file. " + + + (${GREP} -q "${keymanager_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${keymanager_host_name} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${keymanager_host_name}")) \ + || print_error "Failed to update '/etc/hosts' file. " + + elif [[ "${STRATOS_SERVICE_NAME}" = "gateway" || "${STRATOS_SERVICE_NAME}" = "gatewaymgt" ]] ; then + keymanager_hostname="<%= @stratos_instance_data_keymanager_host_name %>" + + (${GREP} -q "${keymanager_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${keymanager_hostname} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${keymanager_hostname}")) \ + || print_error "Failed to update '/etc/hosts' file. " + + fi +} + +function backup_file(){ + if [[ -f "$1.orig" ]]; + then + print_message "Restoring from the Original template file $1" + cp -f "$1.orig" "$1" + else + print_message "Creating a backup of the file $1" + cp -f "$1" "$1.orig" + fi +} + +function configure_manager_worker_wka_members(){ + + print_message "function configure_manager_worker_wka_members ..... " + + # generic worker manager seperation :D + if [[ -z ${STRATOS_WK_MANAGER_MEMBER_COUNT} || ${STRATOS_WK_MANAGER_MEMBER_COUNT} -eq 0 ]] ; then + print_message "manager WKA member count is zero or unavailable" + else + print_message "Configuring manager..." + print_message "configure_manager_worker_wka_members STRATOS_WK_MANAGER_MEMBER_COUNT ${STRATOS_WK_MANAGER_MEMBER_COUNT} ..... " + for i in `seq 0 $(( ${STRATOS_WK_MANAGER_MEMBER_COUNT} - 1 ))` + do + member_ip_name="STRATOS_WK_MANAGER_MEMBER_${i}_IP" + member_ip=${member_ip_name} + if [[ -z ${member_ip} ]] ; then + print_error "WKA is null for STRATOS_WK_MANAGER_MEMBER_${i}_IP" + fi + print_message "$i => ${member_ip}" + WKA_XML=$"${WKA_XML}${!member_ip}4000\n" + done + fi + + if [[ -z ${STRATOS_WK_WORKER_MEMBER_COUNT} || ${STRATOS_WK_WORKER_MEMBER_COUNT} -eq 0 ]] ; then + print_message "worker WKA member count is zero or unavailable" + else + print_message "Configuring worker..." + print_message "STRATOS_WK_WORKER_MEMBER_COUNT ${STRATOS_WK_WORKER_MEMBER_COUNT} ..... " + for i in `seq 0 $(( ${STRATOS_WK_WORKER_MEMBER_COUNT} - 1 ))` + do + member_ip_name="STRATOS_WK_WORKER_MEMBER_${i}_IP" + member_ip=${member_ip_name} + if [[ -z ${member_ip} ]] ; then + print_error "WKA is null for STRATOS_WK_WORKER_MEMBER_${i}_IP" + fi + print_message "$i => ${member_ip}" + WKA_XML=$"${WKA_XML}${!member_ip}4000\n" + done + fi + + print_message "${STRATOS_SERVICE_NAME} WKA_XML => ${WKA_XML}" + verify_file_exists ${AXIS2_XML_FILE} + ${SED} -i "s%${WKA_LINE}%${WKA_XML}%g" ${AXIS2_XML_FILE} && print_message "gateway WKA configuration successful" || print_error "Failed to configure well known members" + +} + + +function configure_wk_members(){ + + print_message "Performing clustering configuration for ${STRATOS_SERVICE_NAME}..." + + WKA_XML="" + KEYMGR_XML="" + WKA_LINE="@WELL_KNOWN_MEMBERS" + KEYMGR_LINE="@KEYMANAGER_SERVER_URL" + + AXIS2_XML_FILE=${STRATOS_APP_PATH}/repository/conf/axis2/axis2.xml + backup_file ${AXIS2_XML_FILE} + + + if [[ (! -z $STRATOS_SERVICE_GROUP) && "${STRATOS_SERVICE_GROUP}" = "apim" ]] ; then + print_message " STRATOS_SERVICE_GROUP_APIM ${STRATOS_SERVICE_GROUP} ..... " + API_MANAGER_XML_FILE=${STRATOS_APP_PATH}/repository/conf/api-manager.xml + backup_file ${API_MANAGER_XML_FILE} + + if [[ "${STRATOS_SERVICE_NAME}" = "apistore" || "${STRATOS_SERVICE_NAME}" = "publisher" ]] ; then + + print_message "Configuring axis2.xml for ${STRATOS_SERVICE_NAME}..." + WKA_XML=$"${WKA_XML}${STRATOS_WK_APISTORE_MEMBER_IP}4000\n" + WKA_XML=$"${WKA_XML}${STRATOS_WK_PUBLISHER_MEMBER_IP}4000\n" + print_message "${STRATOS_SERVICE_NAME} WKA_XML => ${WKA_XML}" + verify_file_exists ${AXIS2_XML_FILE} + ${SED} -i "s%${WKA_LINE}%${WKA_XML}%g" ${AXIS2_XML_FILE} && print_message "${STRATOS_SERVICE_NAME} WKA configuration successful" || print_error "Failed to configure well known members" + + elif [[ "${STRATOS_SERVICE_NAME}" = "keymanager" ]] ; then + + print_message "In keymanager...nothing to do" + + elif [[ "${STRATOS_SERVICE_NAME}" = "gateway" || "${STRATOS_SERVICE_NAME}" = "gatewaymgt" ]] ; then + + if [[ "${DEPLOYMENT}" = "manager" || "${DEPLOYMENT}" = "worker" ]] ; then + + configure_manager_worker_wka_members + fi + + fi + elif [[ "${DEPLOYMENT}" = "manager" || "${DEPLOYMENT}" = "worker" ]] ; then + print_message " Worker / Manager ..... ${DEPLOYMENT} " + configure_manager_worker_wka_members + else + print_message "Configuring ${STRATOS_SERVICE_NAME}..." + print_message "STRATOS_WK_MEMBER_COUNT ....... ${STRATOS_WK_MEMBER_COUNT} " + for i in `seq 0 $(( ${STRATOS_WK_MEMBER_COUNT} - 1 ))` + do + member_ip="STRATOS_WK_MEMBER_${i}_IP" + print_message " memberip ${member_ip} ....... " + if [[ -z ${!member_ip} ]] ; then + print_error "WKA is null for STRATOS_WK_MEMBER_${i}_IP" + fi + print_message "$i => ${!member_ip}" + WKA_XML=$"${WKA_XML}${!member_ip}4000\n" + done + + print_message "${STRATOS_SERVICE_NAME} WKA_XML => ${WKA_XML}" + verify_file_exists ${AXIS2_XML_FILE} + ${SED} -i "s%${WKA_LINE}%${WKA_XML}%g" ${AXIS2_XML_FILE} && print_message "${STRATOS_SERVICE_NAME} WKA configuration successful" || print_error "Failed to configure well known members" + fi +} + +function updateWKMembers() { + print_message "Update WKA Members...... " + # Check if APP_PATH exists + print_message "Stratos App path $STRATOS_APP_PATH ...... " + if [[ ! -d $STRATOS_APP_PATH ]] ; then + print_error "APP_PATH is not found at: ${STRATOS_APP_PATH}" + fi + + # Set JAVA_HOME if it is not already set + if [[ -z $JAVA_HOME ]] ; then + print_message "Setting JAVA_HOME to /opt/java" + export JAVA_HOME=/opt/java + fi + + print_message "Stopping wso2server.sh ...... " + # Kill Product server + $STRATOS_APP_PATH/bin/wso2server.sh stop > /dev/null 2>&1 & + sleep 10 + + # Check if clustering is enabled for this product + if [[ -z $STRATOS_CLUSTERING ]] ; then + ${ECHO} -e `date`": starting servers in stand-alone mode..." | tee -a $log + if [[ ${VERBOSE} -eq 1 ]]; then + printParameters + fi + + else + ${ECHO} -e `date`": starting servers in clustering mode..." | tee -a $log + if [[ ${VERBOSE} -eq 1 ]] ; then + printParameters + fi + # Do the WKA configuration to support clustering + configure_wk_members + fi + + #Backup hosts file + backup_file /etc/hosts + # Update the /etc/hosts file with LB instance IP + update_hosts_file + + # Run start server command + verify_file_exists $STRATOS_APP_PATH/bin/wso2server.sh + $STRATOS_APP_PATH/bin/wso2server.sh $* > /dev/null 2>&1 & + print_message "Executed run command: $STRATOS_APP_PATH/bin/wso2server.sh $*" + print_message "WK Members successfully updated." +} + +# ----------------------- +# Execution starts here +# ----------------------- + + print_message " Executing member activated extension " + print_message " Stratos UpdateWK_IP [$STRATOS_UPDATE_WK_IP] " +# Check if WK Update flag is set +if [[ $STRATOS_UPDATE_WK_IP = "true" ]]; then + print_message " Conditions successful for [$STRATOS_UPDATE_WK_IP] . Executing updateWKMembers " + updateWKMembers +fi + +${ECHO} -e `date`": member activated extension successfully completed." +# END diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/member-started.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/member-started.sh.erb new file mode 100644 index 0000000000..29f45c3d61 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/member-started.sh.erb @@ -0,0 +1,43 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed when member suspended +# event is received. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +OUTPUT=`date`": Member Started Event: " +OUTPUT="$OUTPUT MEMBER_ID: ${STRATOS_MEMBER_ID}, " +OUTPUT="$OUTPUT MEMBER_IP: ${STRATOS_MEMBER_IP}, " +OUTPUT="$OUTPUT CLUSTER_ID: ${STRATOS_CLUSTER_ID}, " +OUTPUT="$OUTPUT LB_CLUSTER_ID: ${STRATOS_LB_CLUSTER_ID}, " +OUTPUT="$OUTPUT NETWORK_PARTITION_ID: ${STRATOS_NETWORK_PARTITION_ID}, " +OUTPUT="$OUTPUT SERVICE_NAME: ${STRATOS_SERVICE_NAME}, " +OUTPUT="$OUTPUT PORTS: ${STRATOS_PORTS}," +OUTPUT="$OUTPUT STRATOS_LB_IP: ${STRATOS_LB_IP}," +OUTPUT="$OUTPUT STRATOS_LB_PUBLIC_IP: ${STRATOS_LB_PUBLIC_IP}," +OUTPUT="$OUTPUT APP_PATH: ${APP_PATH}," +OUTPUT="$OUTPUT STRATOS_PARAM_FILE_PATH: ${STRATOS_PARAM_FILE_PATH}" +echo $OUTPUT | tee -a $log +echo "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log +echo "Topology: ${STRATOS_TOPOLOGY_JSON}" | tee -a $log +echo "---------------" | tee -a $log diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/member-suspended.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/member-suspended.sh.erb new file mode 100644 index 0000000000..866aa0d758 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/member-suspended.sh.erb @@ -0,0 +1,43 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed when member suspended +# event is received. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +OUTPUT=`date`": Member Suspended Event: " +OUTPUT="$OUTPUT MEMBER_ID: ${STRATOS_MEMBER_ID}, " +OUTPUT="$OUTPUT MEMBER_IP: ${STRATOS_MEMBER_IP}, " +OUTPUT="$OUTPUT CLUSTER_ID: ${STRATOS_CLUSTER_ID}, " +OUTPUT="$OUTPUT LB_CLUSTER_ID: ${STRATOS_LB_CLUSTER_ID}, " +OUTPUT="$OUTPUT NETWORK_PARTITION_ID: ${STRATOS_NETWORK_PARTITION_ID}, " +OUTPUT="$OUTPUT SERVICE_NAME: ${STRATOS_SERVICE_NAME}, " +OUTPUT="$OUTPUT PORTS: ${STRATOS_PORTS}," +OUTPUT="$OUTPUT STRATOS_LB_IP: ${STRATOS_LB_IP}," +OUTPUT="$OUTPUT STRATOS_LB_PUBLIC_IP: ${STRATOS_LB_PUBLIC_IP}," +OUTPUT="$OUTPUT APP_PATH: ${APP_PATH}," +OUTPUT="$OUTPUT STRATOS_PARAM_FILE_PATH: ${STRATOS_PARAM_FILE_PATH}" +echo $OUTPUT | tee -a $log +echo "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log +echo "Topology: ${STRATOS_TOPOLOGY_JSON}" | tee -a $log +echo "---------------" | tee -a $log diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/member-terminated.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/member-terminated.sh.erb new file mode 100644 index 0000000000..89cedf6982 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/member-terminated.sh.erb @@ -0,0 +1,43 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed when member terminated +# event is received. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +OUTPUT=`date`": Member Terminated Event: " +OUTPUT="$OUTPUT MEMBER_ID: ${STRATOS_MEMBER_ID}, " +OUTPUT="$OUTPUT MEMBER_IP: ${STRATOS_MEMBER_IP}, " +OUTPUT="$OUTPUT CLUSTER_ID: ${STRATOS_CLUSTER_ID}, " +OUTPUT="$OUTPUT LB_CLUSTER_ID: ${STRATOS_LB_CLUSTER_ID}, " +OUTPUT="$OUTPUT NETWORK_PARTITION_ID: ${STRATOS_NETWORK_PARTITION_ID}, " +OUTPUT="$OUTPUT SERVICE_NAME: ${STRATOS_SERVICE_NAME}, " +OUTPUT="$OUTPUT PORTS: ${STRATOS_PORTS}," +OUTPUT="$OUTPUT STRATOS_LB_IP: ${STRATOS_LB_IP}," +OUTPUT="$OUTPUT STRATOS_LB_PUBLIC_IP: ${STRATOS_LB_PUBLIC_IP}," +OUTPUT="$OUTPUT APP_PATH: ${APP_PATH}," +OUTPUT="$OUTPUT STRATOS_PARAM_FILE_PATH: ${STRATOS_PARAM_FILE_PATH}" +echo $OUTPUT | tee -a $log +echo "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log +echo "Topology: ${STRATOS_TOPOLOGY_JSON}" | tee -a $log +echo "---------------" | tee -a $log diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/mount-volumes.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/mount-volumes.sh.erb new file mode 100755 index 0000000000..2e649bdf32 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/mount-volumes.sh.erb @@ -0,0 +1,87 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed to mount volumes +# to the instance. +# -------------------------------------------------------------- +# + + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo -e "Starting mounting volumes" 2>&1 | tee -a $log + +# $1 is passed from Cartridge Agent code. +echo -e "launh param file location $1" | tee -a $log +#source /opt/apache-stratos-cartridge-agent/launch.params +PERSISTENCE_MAPPING=$1 +echo -e "Persistance mappings : $PERSISTENCE_MAPPING" 2>&1 | tee -a $log + +mount_volume(){ + + device=$1; + mount_point=$2; + echo "device $device" + echo "point $mount_point" + # check if the volume has a file system + output=`sudo file -s $device`; + echo $output | tee -a $log + + # this is the pattern of the output of file -s if the volume does not have a file system + # refer to http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html + pattern="$device: data" + + if [[ $output == $pattern ]] + then + echo -e "Volume is not formatted. So formating the device $device \n" | tee -a $log + sudo mkfs -t ext4 $device + fi + + echo "Mounting the device $device to the mount point $mount_point \n" | tee -a $log + device_mounted=$(mount | grep "$device") + + if [ ! -d "$mount_point" ] + then + echo "creating the mount point directory $mount_point since it does not exist." | tee -a $log + sudo mkdir $mount_point + fi + + #mounting the device if it is not already mounted + if [ ! "$device_mounted" = "" ] + then + echo -e "Device $device is already mounted." | tee -a $log + else + sudo mount $device $mount_point + fi + +} + +IFS='|' read -ra ADDR <<< "${PERSISTENCE_MAPPING}" +echo "${ADDR[@]}" | tee -a $log + +for i in "${!ADDR[@]}"; do + # expected PERSISTANCE_MAPPING format is device1|mountPoint1|device2|mountpoint2... + # so that even indexes are devices and odd indexes are mount points.. + if (( $i % 2 == 0 )) + then + mount_volume ${ADDR[$i]} ${ADDR[$i + 1]} + fi +done + diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/start-servers.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/start-servers.sh.erb new file mode 100755 index 0000000000..6e3490250a --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/start-servers.sh.erb @@ -0,0 +1,308 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed to start the servers. +# -------------------------------------------------------------- +# + +# Execute error_handler function on script error +trap 'error_handler ${LINENO} $?' ERR + +log=/var/log/apache-stratos/cartridge-agent-extensions-start.servers.log +VERBOSE=1 +DATE=`which date` || print_error "date command not found" +ECHO=`which echo` || print_error "echo command not found" +GREP=`which grep` || print_error "grep command not found" +PS=`which ps` || print_error "ps command not found" +SED=`which sed` || print_error "sed command not found" + +function printParameters(){ + ${ECHO} -e "LB IP: ${STRATOS_LB_IP}" | tee -a $log + ${ECHO} -e "LB PUBLIC IP: ${STRATOS_LB_PUBLIC_IP}" | tee -a $log + ${ECHO} -e "STRATOS_PARAM_FILE_PATH: ${STRATOS_PARAM_FILE_PATH}" + ${ECHO} -e "Member List: ${STRATOS_MEMBER_LIST_JSON}" | tee -a $log + ${ECHO} -e "Complete Topology: ${STRATOS_TOPOLOGY_JSON}" | tee -a $log + ${ECHO} -e "Members in LB: ${STRATOS_MEMBERS_IN_LB_JSON}" | tee -a $log + ${ECHO} -e "APP_PATH: ${STRATOS_APP_PATH}" | tee -a $log +} + +function error_handler(){ + MYSELF="$0" # equals to script name + LASTLINE="$1" # argument 1: last line of error occurence + LASTERR="$2" # argument 2: error code of last command + echo "ERROR in ${MYSELF}: line ${LASTLINE}: exit status of last command: ${LASTERR}" + exit 1 +} + +function print_message(){ + if [ ${VERBOSE} -eq 1 ]; then + ${ECHO} -e "[INFO] " $1 | tee -a $log + fi +} + +function print_error(){ + ${ECHO} -e "[Error] " $1 | tee -a $log + exit 1 +} + +function verify_file_exists(){ + if [[ ! -f $1 ]] ; then + print_error "File not found: $1" + fi +} + +function update_hosts_file(){ + instance_hostname="<%= @stratos_instance_data_host_name %>" + (${GREP} -q "${instance_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${instance_hostname} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${instance_hostname}")) \ + || print_error "Failed to update '/etc/hosts' file. " + + map_to_lb="<%= @stratos_instance_data_map_to_lb %>" + arr=$(${ECHO} ${map_to_lb} | tr "," "\n") + + for map_hostname in $arr + do + (${GREP} -q "${map_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${map_hostname} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${map_hostname}")) \ + || print_error "Failed to update '/etc/hosts' file. " + done + + map_to_ip="<%= @stratos_instance_data_map_to_ip %>" + arr=$(${ECHO} ${map_to_ip} | tr "," "\n") + + for mapping in $arr + do + + arrr=$(${ECHO} ${mapping} | tr "#" "\n") + map_hostname=${arrr[1]} + ip_to_map=${arrr[0]} + + (${GREP} -q "${map_hostname}" /etc/hosts || (${ECHO} "${ip_to_map} ${map_hostname} # Additional Mappings" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${ip_to_map} ${map_hostname}")) \ + || print_error "Failed to update '/etc/hosts' file. " + done + + + <%- if @stratos_instance_data_worker_host_name -%> + worker_hostname="<%= @stratos_instance_data_worker_host_name %>" + (${GREP} -q " ${worker_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${worker_hostname} # Stratos LB worker private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${worker_hostname}")) \ + || print_error "Failed to update '/etc/hosts' file. " + <%- end -%> + + if [[ "${STRATOS_SERVICE_NAME}" = "apistore" || "${STRATOS_SERVICE_NAME}" = "publisher" ]] ; then + gateway_host_name="<%= @stratos_instance_data_gateway_host_name %>" + gateway_mgt_host_name="<%= @stratos_instance_data_gateway_mgt_host_name %>" + keymanager_host_name="<%= @stratos_instance_data_keymanager_host_name %>" + + (${GREP} -q "${gateway_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${gateway_host_name} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${gateway_host_name}")) \ + || print_error "Failed to update '/etc/hosts' file. " + + (${GREP} -q "${gateway_mgt_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${gateway_mgt_host_name} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${gateway_mgt_host_name}")) \ + || print_error "Failed to update '/etc/hosts' file. " + + + (${GREP} -q "${keymanager_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${keymanager_host_name} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${keymanager_host_name}")) \ + || print_error "Failed to update '/etc/hosts' file. " + + elif [[ "${STRATOS_SERVICE_NAME}" = "gateway" || "${STRATOS_SERVICE_NAME}" = "gatewaymgt" ]] ; then + keymanager_hostname="<%= @stratos_instance_data_keymanager_host_name %>" + + (${GREP} -q "${keymanager_hostname}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${keymanager_hostname} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${keymanager_hostname}")) \ + || print_error "Failed to update '/etc/hosts' file. " + + elif [[ "${STRATOS_SERVICE_NAME}" = "keymanager" ]] ; then + gateway_host_name="<%= @stratos_instance_data_gateway_host_name %>" + + (${GREP} -q "${gateway_host_name}" /etc/hosts || (${ECHO} "${STRATOS_LB_IP} ${gateway_host_name} # Stratos LB instance private IP" >> /etc/hosts \ + && print_message "Updated /etc/hosts file with: ${STRATOS_LB_IP} ${gateway_host_name}")) \ + || print_error "Failed to update '/etc/hosts' file. " + + + fi +} + +function backup_file(){ + if [[ -f "$1.orig" ]]; + then + print_message "Restoring from the Original template file $1" + cp -f "$1.orig" "$1" + else + print_message "Creating a backup of the file $1" + cp -f "$1" "$1.orig" + fi +} + +function configure_manager_worker_wka_members(){ + + # generic worker manager seperation :D + if [[ -z ${STRATOS_WK_MANAGER_MEMBER_COUNT} || ${STRATOS_WK_MANAGER_MEMBER_COUNT} -eq 0 ]] ; then + print_message "manager WKA member count is zero or unavailable" + else + print_message "Configuring manager..." + for i in `seq 0 $(( ${STRATOS_WK_MANAGER_MEMBER_COUNT} - 1 ))` + do + member_ip_name="STRATOS_WK_MANAGER_MEMBER_${i}_IP" + member_ip=${member_ip_name} + if [[ -z ${member_ip} ]] ; then + print_error "WKA is null for STRATOS_WK_MANAGER_MEMBER_${i}_IP" + fi + print_message "$i => ${member_ip}" + WKA_XML=$"${WKA_XML}${!member_ip}4000\n" + done + fi + + if [[ -z ${STRATOS_WK_WORKER_MEMBER_COUNT} || ${STRATOS_WK_WORKER_MEMBER_COUNT} -eq 0 ]] ; then + print_message "worker WKA member count is zero or unavailable" + else + print_message "Configuring worker..." + for i in `seq 0 $(( ${STRATOS_WK_WORKER_MEMBER_COUNT} - 1 ))` + do + member_ip_name="STRATOS_WK_WORKER_MEMBER_${i}_IP" + member_ip=${member_ip_name} + if [[ -z ${member_ip} ]] ; then + print_error "WKA is null for STRATOS_WK_WORKER_MEMBER_${i}_IP" + fi + print_message "$i => ${member_ip}" + WKA_XML=$"${WKA_XML}${!member_ip}4000\n" + done + fi + + print_message "${STRATOS_SERVICE_NAME} WKA_XML => ${WKA_XML}" + verify_file_exists ${AXIS2_XML_FILE} + ${SED} -i "s%${WKA_LINE}%${WKA_XML}%g" ${AXIS2_XML_FILE} && print_message "gateway WKA configuration successful" || print_error "Failed to configure well known members" + +} + + +function configure_wk_members(){ + + print_message "Performing clustering configuration for ${STRATOS_SERVICE_NAME}..." + + WKA_XML="" + KEYMGR_XML="" + WKA_LINE="@WELL_KNOWN_MEMBERS" + KEYMGR_LINE="@KEYMANAGER_SERVER_URL" + + AXIS2_XML_FILE=${STRATOS_APP_PATH}/repository/conf/axis2/axis2.xml + backup_file ${AXIS2_XML_FILE} + + + if [[ (! -z $STRATOS_SERVICE_GROUP) && "${STRATOS_SERVICE_GROUP}" = "apim" ]] ; then + API_MANAGER_XML_FILE=${STRATOS_APP_PATH}/repository/conf/api-manager.xml + backup_file ${API_MANAGER_XML_FILE} + + if [[ "${STRATOS_SERVICE_NAME}" = "apistore" || "${STRATOS_SERVICE_NAME}" = "publisher" ]] ; then + + print_message "Configuring axis2.xml for ${STRATOS_SERVICE_NAME}..." + WKA_XML=$"${WKA_XML}${STRATOS_WK_APISTORE_MEMBER_IP}4000\n" + WKA_XML=$"${WKA_XML}${STRATOS_WK_PUBLISHER_MEMBER_IP}4000\n" + print_message "${STRATOS_SERVICE_NAME} WKA_XML => ${WKA_XML}" + verify_file_exists ${AXIS2_XML_FILE} + ${SED} -i "s%${WKA_LINE}%${WKA_XML}%g" ${AXIS2_XML_FILE} && print_message "${STRATOS_SERVICE_NAME} WKA configuration successful" || print_error "Failed to configure well known members" + + elif [[ "${STRATOS_SERVICE_NAME}" = "keymanager" ]] ; then + + print_message "In keymanager...nothing to do" + + elif [[ "${STRATOS_SERVICE_NAME}" = "gateway" || "${STRATOS_SERVICE_NAME}" = "gatewaymgt" ]] ; then + + if [[ "${DEPLOYMENT}" = "manager" || "${DEPLOYMENT}" = "worker" ]] ; then + + configure_manager_worker_wka_members + fi + + fi + elif [[ "${DEPLOYMENT}" = "manager" || "${DEPLOYMENT}" = "worker" ]] ; then + + configure_manager_worker_wka_members + else + print_message "Configuring ${STRATOS_SERVICE_NAME}..." + for i in `seq 0 $(( ${STRATOS_WK_MEMBER_COUNT} - 1 ))` + do + member_ip="STRATOS_WK_MEMBER_${i}_IP" + if [[ -z ${!member_ip} ]] ; then + print_error "WKA is null for STRATOS_WK_MEMBER_${i}_IP" + fi + print_message "$i => ${!member_ip}" + WKA_XML=$"${WKA_XML}${!member_ip}4000\n" + done + + print_message "${STRATOS_SERVICE_NAME} WKA_XML => ${WKA_XML}" + verify_file_exists ${AXIS2_XML_FILE} + ${SED} -i "s%${WKA_LINE}%${WKA_XML}%g" ${AXIS2_XML_FILE} && print_message "${STRATOS_SERVICE_NAME} WKA configuration successful" || print_error "Failed to configure well known members" + fi +} + +# Check if APP_PATH exists +if [[ ! -d $STRATOS_APP_PATH ]] ; then + print_error "APP_PATH is not found at: ${STRATOS_APP_PATH}" +fi + +# Check if product server is already running +if [[ -f $STRATOS_APP_PATH/wso2carbon.pid ]] ; then + PID=`cat $STRATOS_APP_PATH/wso2carbon.pid` + if ${PS} -p $PID > /dev/null ; then + ${ECHO} -e `date`": process is already running...skipping start servers" + exit 0 + fi +fi + +# Set JAVA_HOME if it is not already set +if [[ -z $JAVA_HOME ]] ; then + print_message "Setting JAVA_HOME to /opt/java" + export JAVA_HOME=/opt/java +fi + +# Check if clustering is enabled for this product +if [[ -z $STRATOS_CLUSTERING ]] ; then + ${ECHO} -e `date`": starting servers in stand-alone mode..." | tee -a $log + if [[ ${VERBOSE} -eq 1 ]]; then + printParameters + fi + +else + ${ECHO} -e `date`": starting servers in clustering mode..." | tee -a $log + if [[ ${VERBOSE} -eq 1 ]] ; then + printParameters + fi + # Do the WKA configuration to support clustering + configure_wk_members +fi + +<%- if @using_dns == true -%> + #Update the DNS mapping +<%- else -%> + # Update the /etc/hosts file with LB instance IP + update_hosts_file +<%- end -%> + + +# Run start server command +verify_file_exists $STRATOS_APP_PATH/bin/wso2server.sh +$STRATOS_APP_PATH/bin/wso2server.sh $* > /dev/null 2>&1 & +print_message "Executed run command: $STRATOS_APP_PATH/bin/wso2server.sh $*" +${ECHO} -e `date`": start servers extension successfully completed." + diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/subscription-domain-added.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/subscription-domain-added.sh.erb new file mode 100644 index 0000000000..9ef88a2134 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/subscription-domain-added.sh.erb @@ -0,0 +1,35 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed when subscription domain +# added event is received. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +OUTPUT=`date`": Subscription Domain Added Event" +OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_SERVICE_NAME: ${STRATOS_SUBSCRIPTION_SERVICE_NAME}," +OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_DOMAIN_NAME: ${STRATOS_SUBSCRIPTION_DOMAIN_NAME}," +OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_TENANT_ID: ${STRATOS_SUBSCRIPTION_TENANT_ID}," +OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_TENANT_DOMAIN: $STRATOS_SUBSCRIPTION_TENANT_DOMAIN}," +OUTPUT="$OUTPUT APP_PATH: ${APP_PATH}," +OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_APPLICATION_CONTEXT: ${STRATOS_SUBSCRIPTION_APPLICATION_CONTEXT}" +echo $OUTPUT | tee -a $log diff --git a/tools/puppet3/modules/appserver/templates/agent/extensions/subscription-domain-removed.sh.erb b/tools/puppet3/modules/appserver/templates/agent/extensions/subscription-domain-removed.sh.erb new file mode 100644 index 0000000000..ff7b56ba08 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/agent/extensions/subscription-domain-removed.sh.erb @@ -0,0 +1,34 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed when subscription domain +# removed event is received. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +OUTPUT=`date`": Subscription Domain Removed Event" +OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_SERVICE_NAME: ${STRATOS_SUBSCRIPTION_SERVICE_NAME}," +OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_DOMAIN_NAME: ${STRATOS_SUBSCRIPTION_DOMAIN_NAME}," +OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_TENANT_ID: ${STRATOS_SUBSCRIPTION_TENANT_ID}," +OUTPUT="$OUTPUT APP_PATH: ${APP_PATH}," +OUTPUT="$OUTPUT STRATOS_SUBSCRIPTION_TENANT_DOMAIN: $STRATOS_SUBSCRIPTION_TENANT_DOMAIN}" +echo $OUTPUT | tee -a $log diff --git a/tools/puppet3/modules/appserver/templates/conf/axis2/axis2.xml.erb b/tools/puppet3/modules/appserver/templates/conf/axis2/axis2.xml.erb new file mode 100644 index 0000000000..15c9f688c1 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/conf/axis2/axis2.xml.erb @@ -0,0 +1,713 @@ + + + + + + + + + + + + + true + true + optional + true + work/mtom + 4000 + + true + + + true + + + + false + + inmemory + + + + + + + services + + + axis2services + + + axis2modules + + + Application Server-5.2.1 + + + Application Server-5.2.1 + + + + + + + false + + + + + + false + + + true + + + + ./repository/deployment/server/synapse-configs + + + + . + + + . + + + WSO2 Carbon Server + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 9763 + + + + + + + + + + + + 9443 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + HTTP/1.1 + chunked + + true + + + HTTP/1.1 + chunked + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + wka + + + + + wso2.<%= @as_subdomain %>.domain + + + + + + 45564 + + 100 + + 60 + + + + + + <%= @ipaddress %> + + + + + + <%= @hazelcast_port %> + + + + + + + + + <%- if @sub_cluster_domain -%> + + <%- end -%> + + + + + + + <%- if @clustering == true -%> + <%- if @members -%> + <%- @members.each_pair do |hostname,port| -%> + + <%= hostname %> + <%= port %> + + <%- end -%> + <%- else -%> +@WELL_KNOWN_MEMBERS + <%- end -%> + <%- end -%> + + + + + + + + + diff --git a/tools/puppet3/modules/appserver/templates/conf/carbon.xml.erb b/tools/puppet3/modules/appserver/templates/conf/carbon.xml.erb new file mode 100644 index 0000000000..68d8e6fa57 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/conf/carbon.xml.erb @@ -0,0 +1,626 @@ + + + + + + + + + Application Server + + + AS + + + 5.2.1 + + + + <%- if @stratos_instance_data_deployment -%> + <%- if @stratos_instance_data_deployment = 'manager' -%> + <%- if @stratos_instance_data_worker_host_name -%> + <%= @stratos_instance_data_worker_host_name %> + <%- else -%> + <%= @stratos_instance_data_host_name %> + <%- end -%> + <%- else -%> + <%= @stratos_instance_data_host_name %> + <%- end -%> + <%- else -%> + <%= @stratos_instance_data_host_name %> + <%- end -%> + + <%= @stratos_instance_data_host_name %> + + + local:/${carbon.context}/services/ + + + + + + + ApplicationServer + + + + + + + org.wso2.carbon + + + / + + + + + + 15 + + + + + + + + + <%= @offset %> + + + + + 9999 + + 11111 + + + + + + 10389 + + 8000 + + + + + + 5672 + + 8672 + + + + + + 10500 + + + + + + + org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory + + + + + + + + + java + + + + + + + + + + <%= @cloud %> + + + false + + + 600 + + + + false + false + + + + + + ${carbon.home}/repository/deployment/server/ + + + 15 + + + ${carbon.home}/repository/conf/axis2/axis2.xml + + + 30000 + + + ${carbon.home}/repository/deployment/client/ + + ${carbon.home}/repository/conf/axis2/axis2_client.xml + + true + + + + + + + + + + admin + Default Administrator Role + + + user + Default User Role + + + + + + + + + + + + ${carbon.home}/repository/resources/security/wso2carbon.jks + + JKS + + wso2carbon + + wso2carbon + + wso2carbon + + + + + + ${carbon.home}/repository/resources/security/client-truststore.jks + + JKS + + wso2carbon + + + + + + + + + + + + + + + + + + + UserManager + + + false + + + + + + + ${carbon.home}/tmp/work + + + + + + true + + + 10 + + + 30 + + + + + + 100 + + + + keystore + certificate + * + + org.wso2.carbon.ui.transports.fileupload.AnyFileUploadExecutor + + + + + jarZip + + org.wso2.carbon.ui.transports.fileupload.JarZipUploadExecutor + + + + dbs + + org.wso2.carbon.ui.transports.fileupload.DBSFileUploadExecutor + + + + tools + + org.wso2.carbon.ui.transports.fileupload.ToolsFileUploadExecutor + + + + toolsAny + + org.wso2.carbon.ui.transports.fileupload.ToolsAnyFileUploadExecutor + + + + + + + info + org.wso2.carbon.core.transports.util.InfoProcessor + + + wsdl + org.wso2.carbon.core.transports.util.Wsdl11Processor + + + wsdl2 + org.wso2.carbon.core.transports.util.Wsdl20Processor + + + xsd + org.wso2.carbon.core.transports.util.XsdProcessor + + + + + + <%= @depsync %> + <%- if @sub_cluster_domain == 'mgt' -%> + true + true + <%- else -%> + false + true + <%- end -%> + svn + <%= @depsync_svn_repo %>/appserver + <%= @svn_user %> + <%= @svn_password %> + true + + + + + + + + + + + + + + + ${require.carbon.servlet} + + + + + true + + + + + + + default repository + http://dist.wso2.org/p2/carbon/releases/4.2.0 + + + + + + + + true + + + + + + true + + diff --git a/tools/puppet3/modules/appserver/templates/conf/datasources/master-datasources.xml.erb b/tools/puppet3/modules/appserver/templates/conf/datasources/master-datasources.xml.erb new file mode 100644 index 0000000000..0fce2f63a1 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/conf/datasources/master-datasources.xml.erb @@ -0,0 +1,72 @@ + + + + org.wso2.carbon.ndatasource.rdbms.RDBMSDataSourceReader + + + + + + WSO2_CARBON_DB + The datasource used for registry and user manager + + jdbc/WSO2CarbonDB + + + + jdbc:h2:<%= @carbon_home %>/repository/database/WSO2CARBON_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000 + wso2carbon + wso2carbon + org.h2.Driver + 50 + 60000 + true + SELECT 1 + 30000 + + + + + <%- if @cloud == true or @clustering == true -%> + <%= scope.function_template(['appserver/conf/datasources/master-datasources/_remote.erb']) -%> + <%- end -%> + + + + + + + + diff --git a/tools/puppet3/modules/appserver/templates/conf/datasources/master-datasources/_remote.erb b/tools/puppet3/modules/appserver/templates/conf/datasources/master-datasources/_remote.erb new file mode 100644 index 0000000000..27fa824d3c --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/conf/datasources/master-datasources/_remote.erb @@ -0,0 +1,68 @@ + + WSO2_GOVERNANCE_DB + The datasource used for governance MySQL database + + jdbc/<%= @registry_database %> + + + + jdbc:mysql://<%= @mysql_server %>:<%= @mysql_port %>/<%= @registry_database %>?autoReconnect=true + <%= @registry_user %> + <%= @registry_password %> + com.mysql.jdbc.Driver + <%= @max_active %> + <%= @max_wait %> + 5 + true + SELECT 1 + 30000 + + + + + + WSO2_USERSTORE_DB + The datasource used for userstore MySQL database + + jdbc/<%= @userstore_database %> + + + + jdbc:mysql://<%= @mysql_server %>:<%= @mysql_port %>/<%= @userstore_database %>?autoReconnect=true + <%= @userstore_user %> + <%= @userstore_password %> + com.mysql.jdbc.Driver + <%= @max_active %> + <%= @max_wait %> + 5 + true + SELECT 1 + 30000 + + + + + + + + WSO2_APPSERVER_CONFIG_DB + The datasource used for APPSERVER_CONFIG MySQL database + + jdbc/<%= @config_db -%> + + + + jdbc:mysql://<%= @mysql_server %>:<%= @mysql_port %>/<%= @config_db %>?autoReconnect=true + <%= @registry_user %> + <%= @registry_password %> + com.mysql.jdbc.Driver + <%= @max_active %> + <%= @max_wait %> + 5 + true + SELECT 1 + 30000 + + + + diff --git a/tools/puppet3/modules/appserver/templates/conf/log4j.properties.erb b/tools/puppet3/modules/appserver/templates/conf/log4j.properties.erb new file mode 100644 index 0000000000..a5192d0a12 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/conf/log4j.properties.erb @@ -0,0 +1,175 @@ +# +# Copyright 2009 WSO2, Inc. (http://wso2.com) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# This is the log4j configuration file used by WSO2 Carbon +# +# IMPORTANT : Please do not remove or change the names of any +# of the Appenders defined here. The layout pattern & log file +# can be changed using the WSO2 Carbon Management Console, and those +# settings will override the settings in this file. +# + +<%- if @enable_log_publisher == 'true' -%> +log4j.rootLogger=INFO, CARBON_CONSOLE, CARBON_LOGFILE, CARBON_MEMORY, LOGEVENT +<% else %> +log4j.rootLogger=INFO, CARBON_CONSOLE, CARBON_LOGFILE, CARBON_MEMORY +<%- end -%> + +log4j.logger.AUDIT_LOG=INFO, AUDIT_LOGFILE +log4j.logger.org.apache.axis2.wsdl.codegen.writer.PrettyPrinter=ERROR, CARBON_LOGFILE, CARBON_MEMORY +log4j.logger.org.apache.axis2.clustering=INFO, CARBON_CONSOLE, CARBON_LOGFILE +log4j.logger.org.apache=INFO, CARBON_LOGFILE, CARBON_MEMORY +log4j.logger.org.apache.catalina=WARN +log4j.logger.org.apache.tomcat=WARN +log4j.logger.org.wso2.carbon.apacheds=WARN +log4j.logger.org.apache.directory.server.ldap=WARN +log4j.logger.org.apache.directory.server.core.event=WARN +log4j.logger.com.atomikos=INFO,ATOMIKOS +log4j.logger.org.quartz=WARN +log4j.logger.org.apache.jackrabbit.webdav=WARN +log4j.logger.org.apache.juddi=ERROR +log4j.logger.org.apache.commons.digester.Digester=WARN +log4j.logger.org.apache.jasper.compiler.TldLocationsCache=WARN +log4j.logger.org.apache.qpid=WARN +log4j.logger.org.apache.qpid.server.Main=INFO +log4j.logger.qpid.message=WARN +log4j.logger.qpid.message.broker.listening=INFO +log4j.logger.org.apache.tiles=WARN +log4j.logger.org.apache.commons.httpclient=ERROR +log4j.logger.org.apache.coyote=WARN +log4j.logger.org.apache.solr=ERROR +log4j.logger.org.infinispan=WARN +log4j.logger.org.jgroups=ERROR +log4j.logger.me.prettyprint.cassandra.hector.TimingLogger=ERROR +log4j.logger.org.wso2=INFO +log4j.logger.org.apache.axis2.enterprise=FATAL, CARBON_LOGFILE, CARBON_MEMORY +log4j.logger.org.opensaml.xml=WARN, CARBON_LOGFILE, CARBON_MEMORY +log4j.logger.org.apache.directory.shared.ldap=WARN, CARBON_LOGFILE, CARBON_MEMORY +log4j.logger.org.apache.directory.server.ldap.handlers=WARN, CARBON_LOGFILE, CARBON_MEMORY +#Following are to remove false error messages from startup (IS) +log4j.logger.org.apache.directory.shared.ldap.entry.DefaultServerAttribute=FATAL, CARBON_LOGFILE, CARBON_MEMORY +log4j.logger.org.apache.directory.server.core.DefaultDirectoryService=ERROR, CARBON_LOGFILE, CARBON_MEMORY +log4j.logger.org.apache.directory.shared.ldap.ldif.LdifReader=ERROR, CARBON_LOGFILE, CARBON_MEMORY +log4j.logger.org.apache.directory.server.ldap.LdapProtocolHandler=ERROR, CARBON_LOGFILE, CARBON_MEMORY +log4j.logger.org.apache.directory.server.core=ERROR, CARBON_LOGFILE, CARBON_MEMORY +#Hive Related Log configurations +log4j.logger.DataNucleus=ERROR +log4j.logger.Datastore=ERROR +log4j.logger.Datastore.Schema=ERROR +log4j.logger.JPOX.Datastore=ERROR +log4j.logger.JPOX.Plugin=ERROR +log4j.logger.JPOX.MetaData=ERROR +log4j.logger.JPOX.Query=ERROR +log4j.logger.JPOX.General=ERROR +log4j.logger.JPOX.Enhancer=ERROR +log4j.logger.org.apache.hadoop.hive=WARN +log4j.logger.hive=WARN +log4j.logger.ExecMapper=WARN +log4j.logger.ExecReducer=WARN +log4j.logger.net.sf.ehcache.config.ConfigurationFactory=ERROR + +log4j.logger.trace.messages=TRACE,CARBON_TRACE_LOGFILE + +log4j.additivity.org.apache.axis2.clustering=false +log4j.additivity.com.atomikos=false +log4j.additivity.org.apache=false + +# CARBON_CONSOLE is set to be a ConsoleAppender using a PatternLayout. +log4j.appender.CARBON_CONSOLE=org.wso2.carbon.logging.appenders.CarbonConsoleAppender +log4j.appender.CARBON_CONSOLE.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout +# ConversionPattern will be overridden by the configuration setting in the DB +log4j.appender.CARBON_CONSOLE.layout.ConversionPattern=[%d] %P%5p {%c} - %x %m%n +log4j.appender.CARBON_CONSOLE.layout.TenantPattern=%U%@%D[%T] +log4j.appender.CARBON_CONSOLE.threshold=DEBUG + +# The memory appender for logging +log4j.appender.CARBON_MEMORY=org.wso2.carbon.logging.appender.CarbonMemoryAppender +log4j.appender.CARBON_MEMORY.bufferSize=2000 +log4j.appender.CARBON_MEMORY.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout +# ConversionPattern will be overridden by the configuration setting in the DB +log4j.appender.CARBON_MEMORY.layout.ConversionPattern=TID: [%T] [%S] [%d] %P%5p {%c} - %x %m {%c}%n +log4j.appender.CARBON_MEMORY.layout.TenantPattern=%U%@%D [%T] [%S] +log4j.appender.CARBON_MEMORY.columnList=%T,%S,%A,%d,%c,%p,%m,%H,%I,%Stacktrace +log4j.appender.CARBON_MEMORY.threshold=DEBUG + +# CARBON_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout. +log4j.appender.CARBON_LOGFILE=org.wso2.carbon.logging.appenders.CarbonDailyRollingFileAppender +# Log file will be overridden by the configuration setting in the DB +# This path should be relative to WSO2 Carbon Home +log4j.appender.CARBON_LOGFILE.File=${carbon.home}/repository/logs/${instance.log}/wso2carbon${instance.log}.log +log4j.appender.CARBON_LOGFILE.Append=true +log4j.appender.CARBON_LOGFILE.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout +# ConversionPattern will be overridden by the configuration setting in the DB +log4j.appender.CARBON_LOGFILE.layout.ConversionPattern=TID: [%T] [%S] [%d] %P%5p {%c} - %x %m {%c}%n +log4j.appender.CARBON_LOGFILE.layout.TenantPattern=%U%@%D [%T] [%S] +log4j.appender.CARBON_LOGFILE.threshold=DEBUG + +log4j.appender.CARBON_SYS_LOG = org.apache.log4j.net.SyslogAppender +log4j.appender.CARBON_SYS_LOG.layout=org.apache.log4j.PatternLayout +log4j.appender.CARBON_SYS_LOG.layout.ConversionPattern=[%d] %5p {%c} - %x %m {%c}%n +log4j.appender.CARBON_SYS_LOG.SyslogHost=localhost +log4j.appender.CARBON_SYS_LOG.Facility=USER +log4j.appender.CARBON_SYS_LOG.threshold=DEBUG + +<%- if @enable_log_publisher == 'true' -%> + +# LOGEVENT is set to be a LogEventAppender using a PatternLayout to send logs to LOGEVENT +log4j.appender.LOGEVENT=org.wso2.carbon.logging.appender.LogEventAppender +log4j.appender.LOGEVENT.url=tcp://<%= @bam_ip %>:<%= @bam_port %> +log4j.appender.LOGEVENT.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout +log4j.appender.LOGEVENT.columnList=%T,%S,%A,%d,%c,%p,%m,%I,%Stacktrace +log4j.appender.LOGEVENT.userName=admin +log4j.appender.LOGEVENT.password=admin +log4j.appender.LOGEVENT.processingLimit=1000 +log4j.appender.LOGEVENT.maxTolerableConsecutiveFailure=20 + +<%- end -%> + +# Appender config to CARBON_TRACE_LOGFILE +log4j.appender.CARBON_TRACE_LOGFILE=org.apache.log4j.DailyRollingFileAppender +log4j.appender.CARBON_TRACE_LOGFILE.File=${carbon.home}/repository/logs/${instance.log}/wso2carbon-trace-messages${instance.log}.log +log4j.appender.CARBON_TRACE_LOGFILE.Append=true +log4j.appender.CARBON_TRACE_LOGFILE.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout +log4j.appender.CARBON_TRACE_LOGFILE.layout.ConversionPattern=[%d] %P%5p {%c} - %x %m {%c}%n +log4j.appender.CARBON_TRACE_LOGFILE.layout.TenantPattern=%U%@%D [%T] [%S] +log4j.appender.CARBON_TRACE_LOGFILE.threshold=TRACE +log4j.additivity.trace.messages=false + +# Appender config to AUDIT_LOGFILE +log4j.appender.AUDIT_LOGFILE=org.apache.log4j.DailyRollingFileAppender +log4j.appender.AUDIT_LOGFILE.File=${carbon.home}/repository/logs/audit.log +log4j.appender.AUDIT_LOGFILE.Append=true +log4j.appender.AUDIT_LOGFILE.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout +log4j.appender.AUDIT_LOGFILE.layout.ConversionPattern=[%d] %P%5p - %x %m %n +log4j.appender.AUDIT_LOGFILE.layout.TenantPattern=%U%@%D [%T] [%S] +log4j.appender.AUDIT_LOGFILE.threshold=INFO +log4j.additivity.AUDIT_LOG=false + +# Appender config to send Atomikos transaction logs to new log file tm.out. +log4j.appender.ATOMIKOS = org.apache.log4j.RollingFileAppender +log4j.appender.ATOMIKOS.File = repository/logs/tm.out +log4j.appender.ATOMIKOS.Append = true +log4j.appender.ATOMIKOS.layout = org.apache.log4j.PatternLayout +log4j.appender.ATOMIKOS.layout.ConversionPattern=%p %t %c - %m%n + +# This file is used to override the default logger settings, and is used to remove unwanted logs from Shindig appearing on the console. + +# Specification of Handler used by Console Logger +handlers=java.util.logging.ConsoleHandler + +# Replacing default INFO level with SEVERE +java.util.logging.ConsoleHandler.level=SEVERE diff --git a/tools/puppet3/modules/appserver/templates/conf/registry.xml.erb b/tools/puppet3/modules/appserver/templates/conf/registry.xml.erb new file mode 100644 index 0000000000..395d43afbf --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/conf/registry.xml.erb @@ -0,0 +1,105 @@ + + + + + + + + wso2registry + false + true + / + + + jdbc/WSO2CarbonDB + + + <%- if @cloud == true or @clustering == true -%> + <%= scope.function_template(['appserver/conf/registry/_remote.erb']) -%> + <%- end -%> + + + + + + + + + + + true + + + + true + true + true + true + + + diff --git a/tools/puppet3/modules/appserver/templates/conf/registry/_remote.erb b/tools/puppet3/modules/appserver/templates/conf/registry/_remote.erb new file mode 100644 index 0000000000..582b0f9181 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/conf/registry/_remote.erb @@ -0,0 +1,35 @@ + + jdbc/<%= @registry_database %> + + + + governance + governance + false + / + true + <%= @registry_user %>@jdbc:mysql://<%= @mysql_server %>:<%= @mysql_port %>/<%= @registry_database %> + + + + governance + /_system/governance + + + + jdbc/<%= @config_db %> + + + + config + config + false + / + true + <%= @registry_user %>@jdbc:mysql://<%= @mysql_server %>:<%= @mysql_port %>/<%= @config_db %> + + + + config + /_system/<%= @config_target_path %> + diff --git a/tools/puppet3/modules/appserver/templates/conf/security/authenticators.xml.erb b/tools/puppet3/modules/appserver/templates/conf/security/authenticators.xml.erb new file mode 100644 index 0000000000..8e691d0e7e --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/conf/security/authenticators.xml.erb @@ -0,0 +1,52 @@ + + + + + + + + + + 5 + + + + + 10 + + /carbon/admin/login.jsp + ApplicationServer + https://IDP_URL:9445/samlsso + urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified + + + + + + + + + diff --git a/tools/puppet3/modules/appserver/templates/conf/tomcat/catalina-server.xml.erb b/tools/puppet3/modules/appserver/templates/conf/tomcat/catalina-server.xml.erb new file mode 100644 index 0000000000..4ed8eff112 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/conf/tomcat/catalina-server.xml.erb @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/puppet3/modules/appserver/templates/conf/user-mgt.xml.erb b/tools/puppet3/modules/appserver/templates/conf/user-mgt.xml.erb new file mode 100644 index 0000000000..a760b69343 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/conf/user-mgt.xml.erb @@ -0,0 +1,356 @@ + + + + + + true + admin + + <%= @admin_username %> + <%= @admin_password %> + + everyone + <%- if @cloud == true or @clustering == true -%> + jdbc/<%= @userstore_database %> + <%- else -%> + jdbc/WSO2CarbonDB + <%- end -%> + + + + + + + org.wso2.carbon.user.core.tenant.JDBCTenantManager + false + 100 + false + default + SHA-256 + true + true + true + false + ^[\S]{5,30}$ + ^[\S]{5,30}$ + ^[^~!#$;%^*+={}\\|\\\\<>,\'\"]{3,30}$ + ^[\S]{3,30}$ + ^[^~!#$;%^*+={}\\|\\\\<>,\'\"]{3,30}$ + ^[\S]{3,30}$ + true + 100 + 100 + false + false + <%- if @usermgt -%> + true + <%- end -%> + + + <%- if @usermgt == 'readonly_ldap' -%> + <%= scope.function_template(['appserver/conf/user-mgt/_roldap.erb']) -%> + <%- elsif @usermgt == 'readwrite_ldap' -%> + <%= scope.function_template(['appserver/conf/user-mgt/_rwldap.erb']) -%> + <%- end -%> + + + + + + + + + + + + + + + + + + /permission + true + + + + + diff --git a/tools/puppet3/modules/appserver/templates/conf/user-mgt/_roldap.erb b/tools/puppet3/modules/appserver/templates/conf/user-mgt/_roldap.erb new file mode 100644 index 0000000000..d199df7f85 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/conf/user-mgt/_roldap.erb @@ -0,0 +1,32 @@ + + org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager + true + false + 100 + <%= @ldap_connection_uri %> + <%= @bind_dn %> + <%= @bind_dn_password %> + SHA + <%= @user_search_base %> + (objectClass=person) + (&(objectClass=person)(uid=?)) + uid + true + <%= @group_search_base %> + (objectClass=groupOfNames) + (&(objectClass=groupOfNames)(cn=?)) + cn + cn + <%= @sharedgroup_search_base %> + (objectClass=groupOfNames) + (objectClass=organizationalUnit) + ou + organizationalUnit + member + true + true + 100 + 100 + false + + diff --git a/tools/puppet3/modules/appserver/templates/conf/user-mgt/_rwldap.erb b/tools/puppet3/modules/appserver/templates/conf/user-mgt/_rwldap.erb new file mode 100644 index 0000000000..b480984019 --- /dev/null +++ b/tools/puppet3/modules/appserver/templates/conf/user-mgt/_rwldap.erb @@ -0,0 +1,41 @@ + + org.wso2.carbon.user.core.tenant.CommonHybridLDAPTenantManager + <%= @ldap_connection_uri %> + false + <%= @bind_dn %> + <%= @bind_dn_password %> + SHA + (objectClass=person) + inetOrgPerson + <%= @user_search_base %> + (&(objectClass=person)(uid=?)) + uid + [a-zA-Z0-9._-|//]{3,30}$ + ^[\S]{3,30}$ + ^[\S]{3,30}$ + [a-zA-Z0-9._-|//]{3,30}$ + ^[\S]{5,30}$ + true + true + false + <%= @group_search_base %> + (objectClass=groupOfNames) + groupOfNames + (&(objectClass=groupOfNames)(cn=?)) + cn + cn + <%= @sharedgroup_search_base %> + groupOfNames + (objectClass=groupOfNames) + (&(objectClass=groupOfNames)(cn=?)) + (objectClass=organizationalUnit) + ou + organizationalUnit + member + true + true + 100 + 100 + false + + diff --git a/tools/puppet3/modules/haproxy/manifests/init.pp b/tools/puppet3/modules/haproxy/manifests/init.pp index f8ce3ed2ac..dfbc4f9e6a 100755 --- a/tools/puppet3/modules/haproxy/manifests/init.pp +++ b/tools/puppet3/modules/haproxy/manifests/init.pp @@ -35,6 +35,9 @@ tag($service_code) + require java + class {'agent':} + $service_templates = [ 'bin/haproxy-extension.sh', 'conf/jndi.properties', @@ -67,4 +70,7 @@ Haproxy::Push_templates[$service_templates], ]; } + + # install stratos_base before java before haproxy before agent + Class['stratos_base'] -> Class['java'] -> Class['agent'] -> Class['haproxy'] } diff --git a/tools/puppet3/modules/jboss/manifests/init.pp b/tools/puppet3/modules/jboss/manifests/init.pp index 57c3a6bef2..5ec75d420a 100644 --- a/tools/puppet3/modules/jboss/manifests/init.pp +++ b/tools/puppet3/modules/jboss/manifests/init.pp @@ -33,6 +33,14 @@ $extra_jars = [] ) { + require java + + $custom_agent_templates = ['extensions/artifacts-updated.sh'] + class {'agent': + custom_templates => $custom_agent_templates, + module=>'jboss' + } + include '::jboss::config' # Application Server @@ -46,4 +54,6 @@ java_opts => $java_opts, } + #install stratos_base before java before jboss before agent + Class['stratos_base'] -> Class['java'] -> Class['agent'] -> Class['jboss'] } diff --git a/tools/puppet3/modules/jboss/templates/agent/extensions/artifacts-updated.sh.erb b/tools/puppet3/modules/jboss/templates/agent/extensions/artifacts-updated.sh.erb new file mode 100755 index 0000000000..66355151b5 --- /dev/null +++ b/tools/puppet3/modules/jboss/templates/agent/extensions/artifacts-updated.sh.erb @@ -0,0 +1,30 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed once the update artifacts +# event is received and they are copied to the given path. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo `date`": Artifacts Updated Event" | tee -a $log + +chown -R <%= @jboss_user %>:<%= @jboss_group %> <%= @docroot %> diff --git a/tools/puppet3/modules/lb/manifests/init.pp b/tools/puppet3/modules/lb/manifests/init.pp index 3a9a866b3f..1025c3f0a4 100755 --- a/tools/puppet3/modules/lb/manifests/init.pp +++ b/tools/puppet3/modules/lb/manifests/init.pp @@ -39,12 +39,14 @@ $target = '/mnt', ) inherits params { - $deployment_code = 'lb' $carbon_version = $version $service_code = 'load-balancer' $carbon_home = "${target}/apache-stratos-${service_code}-${carbon_version}" + require java + class {'agent':} + $service_templates = [ 'conf/axis2/axis2.xml', 'conf/loadbalancer.conf', @@ -106,4 +108,7 @@ Lb::Importssl[$deployment_code] ], } + + # install stratos_base before java before lb before agent + Class['stratos_base'] -> Class['java'] -> Class['agent'] -> Class['lb'] } diff --git a/tools/puppet3/modules/lb/manifests/initialize.pp b/tools/puppet3/modules/lb/manifests/initialize.pp index 63c8bb6a82..4331516bba 100755 --- a/tools/puppet3/modules/lb/manifests/initialize.pp +++ b/tools/puppet3/modules/lb/manifests/initialize.pp @@ -19,11 +19,11 @@ define lb::initialize ($repo, $version, $service, $local_dir, $target, $mode, $owner,) { - file { - "/${local_dir}/apache-stratos-${service}-${version}.zip": - ensure => present, - source => "puppet:///modules/lb/apache-stratos-${service}-${version}.zip"; - } +# file { +# "/${local_dir}/apache-stratos-${service}-${version}.zip": +# ensure => present, +# source => "puppet:///modules/lb/apache-stratos-${service}-${version}.zip"; +# } exec { "creating_target_for_${name}": diff --git a/tools/puppet3/modules/mysql/manifests/init.pp b/tools/puppet3/modules/mysql/manifests/init.pp index 070862be34..175ba92ffa 100644 --- a/tools/puppet3/modules/mysql/manifests/init.pp +++ b/tools/puppet3/modules/mysql/manifests/init.pp @@ -17,6 +17,14 @@ class mysql{ + require java + + $custom_agent_templates = ['extensions/instance-started.sh'] + class {'agent': + custom_templates => $custom_agent_templates, + module=>'mysql' + } + if $stratos_mysql_password { $root_password = $stratos_mysql_password } @@ -96,4 +104,6 @@ require => File['/etc/apache2/sites-enabled/000-default']; } + # install stratos_base before java before mysql before agent + Class['stratos_base'] -> Class['java'] -> Class['agent'] -> Class['mysql'] } diff --git a/tools/puppet3/modules/agent/templates/extensions/addons/_mysql.erb b/tools/puppet3/modules/mysql/templates/agent/extensions/instance-started.sh.erb old mode 100644 new mode 100755 similarity index 72% rename from tools/puppet3/modules/agent/templates/extensions/addons/_mysql.erb rename to tools/puppet3/modules/mysql/templates/agent/extensions/instance-started.sh.erb index 88f8891249..1babac506a --- a/tools/puppet3/modules/agent/templates/extensions/addons/_mysql.erb +++ b/tools/puppet3/modules/mysql/templates/agent/extensions/instance-started.sh.erb @@ -1,3 +1,6 @@ +#!/bin/bash +# -------------------------------------------------------------- +# # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information @@ -5,15 +8,23 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# +# +# http://www.apache.org/licenses/LICENSE-2.0 +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed once the instance is started. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo `date`": Instance Started Event: " | tee -a $log export PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin' diff --git a/tools/puppet3/modules/nodejs/manifests/init.pp b/tools/puppet3/modules/nodejs/manifests/init.pp index 7292a46408..e31dbd8301 100644 --- a/tools/puppet3/modules/nodejs/manifests/init.pp +++ b/tools/puppet3/modules/nodejs/manifests/init.pp @@ -17,6 +17,14 @@ class nodejs { + require java + + $custom_agent_templates = ['extensions/start-servers.sh'] + class {'agent': + custom_templates => $custom_agent_templates, + module=>'nodejs' + } + $target = '/mnt' if $stratos_app_path { @@ -65,5 +73,8 @@ try_sleep => 2, require => Exec['Install libraries']; } + + # install stratos_base before java before nodejs before agent + Class['stratos_base'] -> Class['java'] -> Class['agent'] -> Class['nodejs'] } diff --git a/tools/puppet3/modules/agent/templates/extensions/addons/_nodejs.erb b/tools/puppet3/modules/nodejs/templates/agent/extensions/start-servers.sh.erb similarity index 67% rename from tools/puppet3/modules/agent/templates/extensions/addons/_nodejs.erb rename to tools/puppet3/modules/nodejs/templates/agent/extensions/start-servers.sh.erb index 463eb533b2..52c6c9a51a 100755 --- a/tools/puppet3/modules/agent/templates/extensions/addons/_nodejs.erb +++ b/tools/puppet3/modules/nodejs/templates/agent/extensions/start-servers.sh.erb @@ -1,3 +1,6 @@ +#!/bin/bash +# -------------------------------------------------------------- +# # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information @@ -5,15 +8,23 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# +# +# http://www.apache.org/licenses/LICENSE-2.0 +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed to start the servers. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo "Starting servers" | tee -a $log export PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin" NODEJS_HOME=<%= @stratos_app_path %> diff --git a/tools/puppet3/modules/php/manifests/init.pp b/tools/puppet3/modules/php/manifests/init.pp index e33953b55d..2078388724 100755 --- a/tools/puppet3/modules/php/manifests/init.pp +++ b/tools/puppet3/modules/php/manifests/init.pp @@ -21,6 +21,15 @@ class php () { + + require java + + $custom_agent_templates = ['extensions/artifacts-updated.sh'] + class {'agent': + custom_templates => $custom_agent_templates, + module=>'php' + } + $packages = [ 'build-essential', 'mysql-client', @@ -131,4 +140,6 @@ ]; } + #install stratos_base before java before php before agent + Class['stratos_base'] -> Class['java'] -> Class['agent'] -> Class['php'] } diff --git a/tools/puppet3/modules/php/templates/agent/extensions/artifacts-updated.sh.erb b/tools/puppet3/modules/php/templates/agent/extensions/artifacts-updated.sh.erb new file mode 100755 index 0000000000..4a94c2abec --- /dev/null +++ b/tools/puppet3/modules/php/templates/agent/extensions/artifacts-updated.sh.erb @@ -0,0 +1,30 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed once the update artifacts +# event is received and they are copied to the given path. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo `date`": Artifacts Updated Event" | tee -a $log + +chown -R www-data:www-data /var/www diff --git a/tools/puppet3/modules/ruby/manifests/init.pp b/tools/puppet3/modules/ruby/manifests/init.pp index 9b671064a1..8d54995854 100644 --- a/tools/puppet3/modules/ruby/manifests/init.pp +++ b/tools/puppet3/modules/ruby/manifests/init.pp @@ -17,6 +17,14 @@ class ruby( $target = '/mnt' ) { + require java + + $custom_agent_templates = ['extensions/instance-started.sh'] + class {'agent': + custom_templates => $custom_agent_templates, + module=>'ruby' + } + if $stratos_app_path { $ruby_home = $stratos_app_path } @@ -57,4 +65,7 @@ command => "/bin/bash /mnt/ruby-start.sh", require => File['/mnt/ruby-start.sh']; } + + # install stratos_base before java before ruby before agent + Class['stratos_base'] -> Class['java'] -> Class['agent'] -> Class['ruby'] } diff --git a/tools/puppet3/modules/agent/templates/extensions/addons/_ruby.erb b/tools/puppet3/modules/ruby/templates/agent/extensions/instance-started.sh.erb old mode 100644 new mode 100755 similarity index 73% rename from tools/puppet3/modules/agent/templates/extensions/addons/_ruby.erb rename to tools/puppet3/modules/ruby/templates/agent/extensions/instance-started.sh.erb index 9117ddeb3e..79028352e3 --- a/tools/puppet3/modules/agent/templates/extensions/addons/_ruby.erb +++ b/tools/puppet3/modules/ruby/templates/agent/extensions/instance-started.sh.erb @@ -1,3 +1,6 @@ +#!/bin/bash +# -------------------------------------------------------------- +# # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information @@ -5,15 +8,23 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# +# +# http://www.apache.org/licenses/LICENSE-2.0 +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +# +# -------------------------------------------------------------- +# This extension script will be executed once the instance is started. +# -------------------------------------------------------------- +# + +log=/var/log/apache-stratos/cartridge-agent-extensions.log +echo `date`": Instance Started Event: " | tee -a $log export PATH="/usr/local/rvm/gems/ruby-2.1.0/bin:/usr/local/rvm/gems/ruby-2.1.0@global/bin:/usr/local/rvm/rubies/ruby-2.1.0/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/rvm/bin:/root/bin" @@ -32,3 +43,4 @@ cd $RUBY_HOME bundle install #rails server > /dev/null 2>&1 & rails server > /tmp/ruby.log 2>&1 & + diff --git a/tools/puppet3/modules/tomcat/manifests/init.pp b/tools/puppet3/modules/tomcat/manifests/init.pp index 45f92b372c..7ef64dd5bb 100644 --- a/tools/puppet3/modules/tomcat/manifests/init.pp +++ b/tools/puppet3/modules/tomcat/manifests/init.pp @@ -21,6 +21,9 @@ $target = '/mnt', ){ + require java + class {'agent':} + $package_name = "apache-tomcat-${tomcat_version}" $service_code = 'apache-tomcat' $tomcat_home = "${target}/${package_name}" @@ -76,5 +79,8 @@ logoutput => 'on_failure', require => Exec['Set tomcat home permission']; } + + # install stratos_base before java before tomcat before agent + Class['stratos_base'] -> Class['java'] -> Class['agent'] -> Class['tomcat'] } diff --git a/tools/puppet3/modules/wordpress/manifests/init.pp b/tools/puppet3/modules/wordpress/manifests/init.pp index 78328f622b..20fae4eb1e 100644 --- a/tools/puppet3/modules/wordpress/manifests/init.pp +++ b/tools/puppet3/modules/wordpress/manifests/init.pp @@ -22,6 +22,9 @@ $wp_password = 'wordpress' ) { + require java + class {'agent':} + $packages = [ 'httpd', 'openssl.x86_64', @@ -84,4 +87,6 @@ require => Exec['Create wordpress database']; } + # install stratos_base before java before mysql before wordpress before agent + Class['stratos_base'] -> Class['java'] -> Class['agent'] -> Class['mysql'] -> Class['wordpress'] }