dev/provisioning/modules/puppi/manifests/project/service.pp
changeset 28 b0b56e0f8c7f
equal deleted inserted replaced
27:a2342f26c9de 28:b0b56e0f8c7f
       
     1 # = Define puppi::project::service
       
     2 #
       
     3 # This is a shortcut define to build a case-limit puppi project
       
     4 # that just manages services and custom commands without deploying
       
     5 # any file. It doesn't require any parameter but you should at least
       
     6 # provide one among predeploy_customcommand, postdeploy_customcommand,
       
     7 # init_script, disable_services to make something useful.
       
     8 # The rollback option is kept for coherency with the standard puppi
       
     9 # deploy approach, but actually should not be used since there is no
       
    10 # data to rollback.
       
    11 #
       
    12 # == Variables:
       
    13 #
       
    14 # [*user*]
       
    15 #   (Optional) - The user to be used for deploy operations.
       
    16 #
       
    17 # [*predeploy_customcommand*]
       
    18 #   (Optional) -  Full path with arguments of an eventual custom command to
       
    19 #   execute before the deploy. The command is executed as $predeploy_user.
       
    20 #
       
    21 # [*predeploy_user*]
       
    22 #   (Optional) - The user to be used to execute the $predeploy_customcommand.
       
    23 #   By default is the same of $user.
       
    24 #
       
    25 # [*predeploy_priority*]
       
    26 #   (Optional) - The priority (execution sequence number) that defines when,
       
    27 #   during the deploy procedure, the $predeploy_customcommand is executed
       
    28 #   Default: 39 (immediately before the copy of files on the deploy root).
       
    29 #
       
    30 # [*postdeploy_customcommand*]
       
    31 #   (Optional) -  Full path with arguments of an eventual custom command to
       
    32 #   execute after the deploy. The command is executed as $postdeploy_user.
       
    33 #
       
    34 # [*postdeploy_user*]
       
    35 #   (Optional) - The user to be used to execute the $postdeploy_customcommand.
       
    36 #   By default is the same of $user.
       
    37 #
       
    38 # [*postdeploy_priority*]
       
    39 #   (Optional) - The priority (execution sequence number) that defines when,
       
    40 #   during the deploy procedure, the $postdeploy_customcommand is executed
       
    41 #   Default: 41 (immediately after the copy of files on the deploy root).
       
    42 #
       
    43 # [*init_script*]
       
    44 #   (Optional - Obsolete) - The name (ex: tomcat) of the init script of your
       
    45 #   Application server. If you define it, the AS is stopped and then started
       
    46 #   during deploy. This option is deprecated, you can use $disable_services
       
    47 #   for the same functionality
       
    48 #
       
    49 # [*disable_services*]
       
    50 #   (Optional) - The names (space separated) of the services you might want to
       
    51 #   stop during deploy. By default is blank. Example: "apache puppet monit".
       
    52 #
       
    53 # [*firewall_src_ip*]
       
    54 #   (Optional) - The IP address of a loadbalancer you might want to block out
       
    55 #   during a deploy.
       
    56 #
       
    57 # [*firewall_dst_port*]
       
    58 #   (Optional) - The local port to block from the loadbalancer during deploy
       
    59 #   (Default all).
       
    60 #
       
    61 # [*firewall_delay*]
       
    62 #   (Optional) - A delay time in seconds to wait after the block of
       
    63 #   $firewall_src_ip. Should be at least as long as the loadbalancer check
       
    64 #   interval for the services stopped during deploy (Default: 1).
       
    65 #
       
    66 # [*report_email*]
       
    67 #   (Optional) - The (space separated) email(s) to notify of deploy/rollback
       
    68 #   operations. If none is specified, no email is sent.
       
    69 #
       
    70 # [*run_checks*]
       
    71 #   (Optional) - If you want to run local puppi checks before and after the
       
    72 #   deploy procedure. Default: "true".
       
    73 #
       
    74 # [*auto_deploy*]
       
    75 #   (Optional) - If you want to automatically run this puppi deploy when
       
    76 #   Puppet runs. Default: 'false'
       
    77 #
       
    78 define puppi::project::service (
       
    79   $user                     = 'root',
       
    80   $predeploy_customcommand  = '',
       
    81   $predeploy_user           = '',
       
    82   $predeploy_priority       = '39',
       
    83   $postdeploy_customcommand = '',
       
    84   $postdeploy_user          = '',
       
    85   $postdeploy_priority      = '41',
       
    86   $init_script              = '',
       
    87   $disable_services         = '',
       
    88   $firewall_src_ip          = '',
       
    89   $firewall_dst_port        = '0',
       
    90   $firewall_delay           = '1',
       
    91   $report_email             = '',
       
    92   $run_checks               = true,
       
    93   $auto_deploy              = false,
       
    94   $enable                   = true ) {
       
    95 
       
    96   require puppi
       
    97   require puppi::params
       
    98 
       
    99   # Set default values
       
   100   $predeploy_real_user = $predeploy_user ? {
       
   101     ''      => $user,
       
   102     default => $predeploy_user,
       
   103   }
       
   104 
       
   105   $postdeploy_real_user = $postdeploy_user ? {
       
   106     ''      => $user,
       
   107     default => $postdeploy_user,
       
   108   }
       
   109 
       
   110   $bool_run_checks = any2bool($run_checks)
       
   111   $bool_auto_deploy = any2bool($auto_deploy)
       
   112 
       
   113 ### CREATE PROJECT
       
   114     puppi::project { $name:
       
   115       enable => $enable ,
       
   116     }
       
   117 
       
   118 
       
   119 ### DEPLOY SEQUENCE
       
   120   if ($bool_run_checks == true) {
       
   121     puppi::deploy { "${name}-Run_PRE-Checks":
       
   122       priority  => '10' ,
       
   123       command   => 'check_project.sh' ,
       
   124       arguments => $name ,
       
   125       user      => 'root' ,
       
   126       project   => $name ,
       
   127       enable    => $enable ,
       
   128     }
       
   129   }
       
   130 
       
   131   if ($firewall_src_ip != '') {
       
   132     puppi::deploy { "${name}-Load_Balancer_Block":
       
   133       priority  => '25' ,
       
   134       command   => 'firewall.sh' ,
       
   135       arguments => "${firewall_src_ip} ${firewall_dst_port} on ${firewall_delay}" ,
       
   136       user      => 'root',
       
   137       project   => $name ,
       
   138       enable    => $enable ,
       
   139     }
       
   140   }
       
   141 
       
   142   if ($disable_services != '') {
       
   143     puppi::deploy { "${name}-Disable_extra_services":
       
   144       priority  => '36' ,
       
   145       command   => 'service.sh' ,
       
   146       arguments => "stop ${disable_services}" ,
       
   147       user      => 'root',
       
   148       project   => $name ,
       
   149       enable    => $enable ,
       
   150     }
       
   151   }
       
   152 
       
   153   if ($init_script != '') {
       
   154     puppi::deploy { "${name}-Service_stop":
       
   155       priority  => '38' ,
       
   156       command   => 'service.sh' ,
       
   157       arguments => "stop ${init_script}" ,
       
   158       user      => 'root',
       
   159       project   => $name ,
       
   160       enable    => $enable ,
       
   161     }
       
   162   }
       
   163 
       
   164   if ($predeploy_customcommand != '') {
       
   165     puppi::deploy { "${name}-Run_Custom_PreDeploy_Script":
       
   166       priority  => $predeploy_priority ,
       
   167       command   => 'execute.sh' ,
       
   168       arguments => $predeploy_customcommand ,
       
   169       user      => $predeploy_real_user ,
       
   170       project   => $name ,
       
   171       enable    => $enable ,
       
   172     }
       
   173   }
       
   174 
       
   175 
       
   176   if ($postdeploy_customcommand != '') {
       
   177     puppi::deploy { "${name}-Run_Custom_PostDeploy_Script":
       
   178       priority  => $postdeploy_priority ,
       
   179       command   => 'execute.sh' ,
       
   180       arguments => $postdeploy_customcommand ,
       
   181       user      => $postdeploy_real_user ,
       
   182       project   => $name ,
       
   183       enable    => $enable ,
       
   184     }
       
   185   }
       
   186 
       
   187   if ($init_script != '') {
       
   188     puppi::deploy { "${name}-Service_start":
       
   189       priority  => '42' ,
       
   190       command   => 'service.sh' ,
       
   191       arguments => "start ${init_script}" ,
       
   192       user      => 'root',
       
   193       project   => $name ,
       
   194       enable    => $enable ,
       
   195     }
       
   196   }
       
   197 
       
   198   if ($disable_services != '') {
       
   199     puppi::deploy { "${name}-Enable_extra_services":
       
   200       priority  => '44' ,
       
   201       command   => 'service.sh' ,
       
   202       arguments => "start ${disable_services}" ,
       
   203       user      => 'root',
       
   204       project   => $name ,
       
   205       enable    => $enable ,
       
   206     }
       
   207   }
       
   208 
       
   209   if ($firewall_src_ip != '') {
       
   210     puppi::deploy { "${name}-Load_Balancer_Unblock":
       
   211       priority  => '46' ,
       
   212       command   => 'firewall.sh' ,
       
   213       arguments => "${firewall_src_ip} ${firewall_dst_port} off 0" ,
       
   214       user      => 'root',
       
   215       project   => $name ,
       
   216       enable    => $enable ,
       
   217     }
       
   218   }
       
   219 
       
   220   if ($bool_run_checks == true) {
       
   221     puppi::deploy { "${name}-Run_POST-Checks":
       
   222       priority  => '80' ,
       
   223       command   => 'check_project.sh' ,
       
   224       arguments => $name ,
       
   225       user      => 'root' ,
       
   226       project   => $name ,
       
   227       enable    => $enable ,
       
   228     }
       
   229   }
       
   230 
       
   231 
       
   232 ### ROLLBACK PROCEDURE
       
   233 
       
   234   if ($firewall_src_ip != '') {
       
   235     puppi::rollback { "${name}-Load_Balancer_Block":
       
   236       priority  => '25' ,
       
   237       command   => 'firewall.sh' ,
       
   238       arguments => "${firewall_src_ip} ${firewall_dst_port} on ${firewall_delay}" ,
       
   239       user      => 'root',
       
   240       project   => $name ,
       
   241       enable    => $enable ,
       
   242     }
       
   243   }
       
   244 
       
   245   if ($disable_services != '') {
       
   246     puppi::rollback { "${name}-Disable_extra_services":
       
   247       priority  => '37' ,
       
   248       command   => 'service.sh' ,
       
   249       arguments => "stop ${disable_services}" ,
       
   250       user      => 'root',
       
   251       project   => $name ,
       
   252       enable    => $enable ,
       
   253     }
       
   254   }
       
   255 
       
   256   if ($init_script != '') {
       
   257     puppi::rollback { "${name}-Service_stop":
       
   258       priority  => '38' ,
       
   259       command   => 'service.sh' ,
       
   260       arguments => "stop ${init_script}" ,
       
   261       user      => 'root',
       
   262       project   => $name ,
       
   263       enable    => $enable ,
       
   264     }
       
   265   }
       
   266 
       
   267   if ($predeploy_customcommand != '') {
       
   268     puppi::rollback { "${name}-Run_Custom_PreDeploy_Script":
       
   269       priority  => $predeploy_priority ,
       
   270       command   => 'execute.sh' ,
       
   271       arguments => $predeploy_customcommand ,
       
   272       user      => $predeploy_real_user ,
       
   273       project   => $name ,
       
   274       enable    => $enable ,
       
   275     }
       
   276   }
       
   277 
       
   278   if ($postdeploy_customcommand != '') {
       
   279     puppi::rollback { "${name}-Run_Custom_PostDeploy_Script":
       
   280       priority  => $postdeploy_priority ,
       
   281       command   => 'execute.sh' ,
       
   282       arguments => $postdeploy_customcommand ,
       
   283       user      => $postdeploy_real_user ,
       
   284       project   => $name ,
       
   285       enable    => $enable ,
       
   286     }
       
   287   }
       
   288 
       
   289   if ($init_script != '') {
       
   290     puppi::rollback { "${name}-Service_start":
       
   291       priority  => '42' ,
       
   292       command   => 'service.sh' ,
       
   293       arguments => "start ${init_script}" ,
       
   294       user      => 'root',
       
   295       project   => $name ,
       
   296       enable    => $enable ,
       
   297     }
       
   298   }
       
   299 
       
   300   if ($disable_services != '') {
       
   301     puppi::rollback { "${name}-Enable_extra_services":
       
   302       priority  => '44' ,
       
   303       command   => 'service.sh' ,
       
   304       arguments => "start ${disable_services}" ,
       
   305       user      => 'root',
       
   306       project   => $name ,
       
   307       enable    => $enable ,
       
   308     }
       
   309   }
       
   310 
       
   311   if ($firewall_src_ip != '') {
       
   312     puppi::rollback { "${name}-Load_Balancer_Unblock":
       
   313       priority  => '46' ,
       
   314       command   => 'firewall.sh' ,
       
   315       arguments => "${firewall_src_ip} ${firewall_dst_port} off 0" ,
       
   316       user      => 'root',
       
   317       project   => $name ,
       
   318       enable    => $enable ,
       
   319     }
       
   320   }
       
   321 
       
   322   if ($bool_run_checks == true) {
       
   323     puppi::rollback { "${name}-Run_POST-Checks":
       
   324       priority  => '80' ,
       
   325       command   => 'check_project.sh' ,
       
   326       arguments => $name ,
       
   327       user      => 'root' ,
       
   328       project   => $name ,
       
   329       enable    => $enable ,
       
   330     }
       
   331   }
       
   332 
       
   333 
       
   334 ### REPORTING
       
   335 
       
   336   if ($report_email != '') {
       
   337     puppi::report { "${name}-Mail_Notification":
       
   338       priority  => '20' ,
       
   339       command   => 'report_mail.sh' ,
       
   340       arguments => $report_email ,
       
   341       user      => 'root',
       
   342       project   => $name ,
       
   343       enable    => $enable ,
       
   344     }
       
   345   }
       
   346 
       
   347 ### AUTO DEPLOY DURING PUPPET RUN
       
   348   if ($bool_auto_deploy == true) {
       
   349     puppi::run { $name: }
       
   350   }
       
   351 
       
   352 }