added deployment_scripts folder

This commit is contained in:
dirk 2016-05-25 11:43:02 +02:00
parent a1585f27ff
commit b68d3e51e2
21 changed files with 672 additions and 0 deletions

View File

@ -0,0 +1,5 @@
$dynatrace = hiera('dynatrace')
if $dynatrace['enabled'] {
class { 'ruxit_agent': }
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>apl_ruxit_agent</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.puppetlabs.geppetto.pp.dsl.ui.puppetNature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,26 @@
Copyright (c) 2008-2015, Dynatrace LLC
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the dynaTraceRuxit software nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

View File

@ -0,0 +1,116 @@
## Overview
This module downloads and installs the [ruxit](http://www.ruxit.com/) unified agent on windows and linux systems.
### Sample Usage
#### Example 1
```puppet
class { 'ruxit_agent':
user => 'test',
group => 'test',
ruxit_tenant => 'yxcvbnm',
ruxit_token => 'TOKEN',
}
```
This example will download the current stable release agent to a directory owned by user/group test and connect it to the given ruxit tenant. [Tenant id](#ruxit_tenant) and [tenant token](#ruxit_token) are required in order to connect the ruxit agent to your account.
#### Example 2
```puppet
class { 'ruxit_agent': }
```
or
```puppet
include ruxit_agent
```
This example will install the corresponding version if all non-optional parameters can be resolved via hiera. It will fail otherwise!
##License
This module is provided under BSD-3-Clause license. Please check out the details in the LICENSE.txt
##Reference
###Classes
###ruxit_agent:
Main class, includes everything else
###Parameters
The following parameters are available in the `ruxit_agent` class:
####`user`
The owner of files.
!! This user is not created by this module. Please make sure it exists. !!
####`group`
The group for the owner of files.
####`ruxit_tenant`
Your ruxit tenant ID is the unique identifier of your ruxit environment. You can find it easily by looking at the URL in your browser when you are logged into your Ruxit home page.
<code>https://{tenant}.live.ruxit.com</code>
The subdomain {tenant} represents your tenant id.
####`ruxit_token`
The token for your ruxit tenant. You can get your token by following these steps
1. go to your ruxit environment: https://{tenant}.live.ruxit.com
2. Click the burger menu in the right upper corner and select **Monitor another host**
3. You will see the "Download Ruxit Agent" wizard; click **Linux** (even if you need Windows)
4. You will see the **wget** command line. The token is the last part of the path after **/latest/**
<code>wget -O ruxit-Agent-Linux-1.XX.0.2015XXXX-XXXXXX.sh https://{tenant}.live.ruxit.com/installer/agent/unix/latest/{this-is-the-token}</code>
5. copy it and use it in your puppet config
####`ruxit_server`
The ruxit server to connect to. This defaults to the https://{tenant}.live.ruxit.com
####`version`
If set the defined version of the ruxit agent will be installed.
If set to an empty string the latest version for the channel will be installed.
Defaults to '' -> latest
####`channel`
Define the install/update channel you want to use. This is for ruxit internal purposes only right now.
* dev -> development branch (highly unstable)
* sprint -> development branch (unstable)
* unstable -> release branch (unstable)
* stable -> release branch (stable)
defaults to stable
####`log_keep_days`
Sets the number of days you want to keep logs.
defaults to 14 days
####`service_restarts`
String array with services that should be restarted after install/upgrade.
defaults to an empty array -> no additional service restarts
###Resources
####`cleanup_log`
A resource cleaning all files in a given directory that were not modified in the given time frame.
####`install_ruxit_agent`
Installs the agent from and to the paths defined in the main class.
####`linux_restart_service`
A resource that triggers restarts of init.d based services.
####`restart_services_hook`
This resource is called after the installation of the ruxit agent to restart services that should be instrumented.
You can define the services as a parameter of the main class: service_restarts
####`windows_restart_service`
A resource wrapper for service stop and start.
####`windows_restart_service`
A resource starting a given windows service.
####`windows_restart_service`
A resource stopping a given windows service.
## Supported OSes
This module is designed for Windows and Linux systems.
If it does not work for your environment please get in touch via the project site.

View File

@ -0,0 +1,2 @@
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'

View File

@ -0,0 +1,68 @@
# Get the installed version for the ruxit agent.
#
# The binaries.json file contains the valid version since spring 51, older versions report all the same version
# The registry aproach for windows can not be used as the registry shows another version than the binary.json *sigh*
require 'json'
require 'facter'
require 'puppet'
Facter.add(:ruxit_installed_version) do
setcode do
version = nil
file = nil
os_key = nil
if Facter.value('kernel').eql? 'windows'
if Facter.value('architecture').eql? 'x64'
file = 'C:/Program Files (x86)/ruxit/agent/conf/binaries.json'
os_key = 'windows-x86-32'
else
file = 'C:/Program Files/ruxit/agent/conf/binaries.json'
os_key = 'windows-x86-64'
end
else
file = '/opt/ruxit/agent/conf/binaries.json'
if Facter.value('architecture').eql? 'x64'
os_key = 'linux-x86-64'
else
os_key = 'linux-x86-32'
end
end
if nil != file
begin
if File.exists?(file)
if File.stat(file).size < (1024 * 15) # don't read files larger than 15KB
begin
file_content = File.read(file)
rescue IOError => e
raise "IO error: #{e.inspect}"
end
hash = JSON.parse(file_content)
if hash != nil
# check the installer version for the java installer
if hash.keys.include? 'os'
version = hash['os']['main'][os_key]['installer-version']
else
raise 'JSON does not contain expected values'
end # hash.keys.include 'os'
else
raise 'parsing failed'
end # hash != nil
else
raise "#{file} too big for parsing"
end # check file size
else
raise "#{file} not available"
end # file exists
rescue StandardError => ex
Puppet.debug("Unable to determine installed ruxit agent version - #{ex}")
end
end # kernel check
# fallback so we don't have to check for undefined values in puppet
if nil == version
version = '0.0.0.0'
end
Puppet.info("Installed ruxit agent version -> '#{version}'")
version
end
end

View File

@ -0,0 +1,21 @@
# Fact that gets the latest dev version of ruxit agent
require 'facter'
require 'puppet'
require 'net/http'
require 'uri'
Facter.add(:ruxit_latest_version_dev) do
setcode do
version = '0.0.0.0'
begin
uri = URI('http://download-dev.ruxitlabs.com/agent/unstable/latest')
res = Net::HTTP.get_response(uri)
version = res.body if res.is_a?(Net::HTTPSuccess)
rescue StandardError => e
Puppet.crit("Exception in ruxit_latest_version_dev -> \n#{e.inspect}")
end
Puppet.debug("Latest ruxit agent DEV version -> '#{version}'")
version
end
end

View File

@ -0,0 +1,20 @@
# Fact that gets the latest sprint version of ruxit agent
require 'facter'
require 'puppet'
require 'net/http'
require 'uri'
Facter.add(:ruxit_latest_version_sprint) do
setcode do
version = '0.0.0.0'
begin
uri = URI('http://download-sprint.ruxitlabs.com/agent/unstable/latest')
res = Net::HTTP.get_response(uri)
version = res.body if res.is_a?(Net::HTTPSuccess)
rescue StandardError => e
Puppet.crit("Exception in ruxit_latest_version_sprint -> \n#{e.inspect}")
end
Puppet.debug("Latest ruxit agent SPRINT version -> '#{version}'")
version
end
end

View File

@ -0,0 +1,20 @@
# Fact that gets the latest stable version of ruxit agent
require 'facter'
require 'puppet'
require 'net/http'
require 'uri'
Facter.add(:ruxit_latest_version_stable) do
setcode do
version = '0.0.0.0'
begin
uri = URI('http://download.ruxit.com/agent/latest')
res = Net::HTTP.get_response(uri)
version = res.body if res.is_a?(Net::HTTPSuccess)
rescue StandardError => e
Puppet.crit("Exception in ruxit_latest_version_stable -> \n#{e.inspect}")
end
Puppet.info("Latest ruxit agent STABLE version -> '#{version}'")
version
end
end

View File

@ -0,0 +1,20 @@
# Fact that gets the latest unstable version of ruxit agent
require 'facter'
require 'puppet'
require 'net/http'
require 'uri'
Facter.add(:ruxit_latest_version_unstable) do
setcode do
version = '0.0.0.0'
begin
uri = URI('http://download.ruxit.com/agent/unstable/latest')
res = Net::HTTP.get_response(uri)
version = res.body if res.is_a?(Net::HTTPSuccess)
rescue StandardError => e
Puppet.crit("Exception in ruxit_latest_version_unstable -> \n#{e.inspect}")
end
Puppet.debug("Latest ruxit agent UNSTABLE version -> '#{version}'")
version
end
end

View File

@ -0,0 +1,119 @@
# Class: ruxit_agent
#
# This module installs the ruxit agent on the host.
# You can define which update channel you want to use and as well define a specific version you want
# to install. If no channel/ version is given as parameter this module will install the latest stable
# ruxit agent version.
#
# Parameters:
# * $user => the owner of files
# * $group => the group of the owner
# * $ruxit_tenant => your ruxit tenant
# * $ruxit_token => the token for your tenant
# * $ruxit_server => the ruxit server to connect to => defaults to https://{tenant}.live.ruxit.com
# * $version => a defined version to install => defaults to latest
# * $channel => define the channel you want to use => defaults to stable
# * $log_keep_days => set the number of days you want to keep logs => defaults to 14
# * $service_restarts => string array with services that should be restarted after install/upgrade
# defaults to an empty array -> no additional service restarts
#
class ruxit_agent (
$user,
$group,
$ruxit_tenant,
$ruxit_token,
$ruxit_server = '',
$version = '',
$channel = 'stable',
$log_keep_days = '14',
$service_restarts = []
) {
if $ruxit_server == '' {
$ruxit_host = "https://${ruxit_tenant}.live.ruxit.com"
} else {
$ruxit_host = $ruxit_server
}
# os specific definitions
if $::kernel =~ /Linux/ {
$usr_home = "/home/${user}"
$install_dir = "${usr_home}/ruxit-agent"
$installer_pre = 'ruxit-Agent-Linux-'
$installer_ext = '.sh'
$install_script = 'install.sh'
} elsif $::kernel =~ /windows/ {
$usr_home = "C:\\Users\\${user}"
$install_dir = "${usr_home}\\ruxit-agent"
$installer_pre = 'ruxit-Agent-Windows-'
$installer_ext = '.msi'
$install_script = 'install.bat'
}
# required version and source selection
case $channel {
/dev/ : {
# use the development channel
$src = 'http://download-dev.ruxitlabs.com/agent/unstable'
$latest_version = $::ruxit_latest_version_dev
}
/sprint/ : {
# use the sprint channel
$src = 'http://download-sprint.ruxitlabs.com/agent/unstable'
$latest_version = $::ruxit_latest_version_sprint
}
/unstable/ : {
# use the release unstable channel
$src = 'http://download.ruxit.com/agent/unstable'
$latest_version = $::ruxit_latest_version_unstable
}
default : {
# use the release stable channel as default
$src = 'http://download.ruxit.com/agent'
$latest_version = $::ruxit_latest_version_stable
}
}
$ruxit_required_version = empty($version) ? {
true => $latest_version,
default => $version
}
$script_mode = '0777'
# trigger log cleanup on every run -> has a schedule defined
ruxit_agent::resources::cleanup_log { 'cleanup_ruxit_logs': days_to_keep => $log_keep_days }
# Only do the install steps if there is no ruxit agent installed
if (!empty($ruxit_required_version) and $ruxit_required_version != '0.0.0.0' and $::ruxit_installed_version == '0.0.0.0') {
$installer = "${installer_pre}${ruxit_required_version}${installer_ext}"
# create the download directory
file { $install_dir:
ensure => directory,
owner => $::usr,
}
# get the install script from template
# We could call the installer directly as well but this additional step gives
# us an installer script on every host that can easily be retriggered for debug.
file { $install_script:
ensure => present,
path => "${install_dir}/${install_script}",
owner => $user,
group => $group,
mode => $script_mode,
require => File[$install_dir],
content => template("ruxit_agent/${install_script}"),
}
# download the installer for the required version
download { 'ruxit_installer_download':
uri => "${src}/${installer}",
dest => "${install_dir}/${installer}",
require => File[$install_dir]
}
->
ruxit_agent::resources::install_ruxit_agent { $ruxit_required_version: }
->
ruxit_agent::resources::restart_services_hook { $service_restarts: }
}
# end install
}

View File

@ -0,0 +1,30 @@
# Delete logfiles
# Parameter:
# * $days_to_keep: how many days should be kept
#
define ruxit_agent::resources::cleanup_log ($days_to_keep) {
if $::kernel == 'windows' {
$path = 'C:\\Program Files (x86)\\ruxit\\log'
} elsif $::kernel == 'Linux' {
$path = '/opt/ruxit/log'
}
validate_re($days_to_keep, '^\d+$')
ensure_resource('schedule', 'log_cleanup_schedule', {period => daily,repeat => 1})
if $::kernel == 'windows' {
exec { "exec_log_cleanup_win_${name}":
command => "forfiles -p \"${path}\" -s -m *.* -d -${days_to_keep} -c \"cmd /c del @path\"",
path => $::path,
returns => [0, 1],
schedule => 'log_cleanup_schedule'
}
} elsif $::kernel == 'Linux' {
exec { "exec_log_cleanup_lnx_${name}":
command => "/usr/bin/find ${path} -type f -mtime +${days_to_keep} -exec rm {} \\;",
path => '/usr/bin',
returns => [0, 1],
schedule => 'log_cleanup_schedule'
}
}
}

View File

@ -0,0 +1,32 @@
# install ruxit agent binary
define ruxit_agent::resources::install_ruxit_agent {
if $::kernel =~ /Linux/ {
$install_dest_dir = '/opt/ruxit/agent'
} else {
$install_dest_dir = 'C:\\Program Files (x86)\\ruxit\\agent'
}
exec { 'install_ruxit_agent':
command => "${ruxit_agent::install_dir}/${ruxit_agent::install_script}",
cwd => $ruxit_agent::install_dir,
timeout => 600,
logoutput => true,
require => [
File[$ruxit_agent::install_dir],
File[$ruxit_agent::install_script],
Download['ruxit_installer_download']
]
}
# restart the agent
if $::kernel =~ /Linux/ {
ruxit_agent::resources::linux_restartservice_initd{ 'ruxitagent' :
subscribe => Exec['install_ruxit_agent']
}
} else {
ruxit_agent::resources::windows_restartservice{ 'ruxit Agent' :
subscribe => Exec['install_ruxit_agent']
}
}
}

View File

@ -0,0 +1,14 @@
# Start a linux system service init /etc/init.d
define ruxit_agent::resources::linux_restartservice_initd () {
$init_file = "/etc/init.d/${name}"
exec{ "check_init_d_file_exists_${init_file}" :
command => "/usr/bin/test -f ${init_file}",
logoutput => false,
}
->
exec{ "restart-${name}":
command => "${init_file} restart",
}
}

View File

@ -0,0 +1,12 @@
# The restart_service_hook takes a service name and restarts it after an
# installation or upgrade of the ruxit agent.
# If this resource is called with an array it will be executed for every entry.
#
define ruxit_agent::resources::restart_services_hook {
# restart the service
if $::kernel =~ /Linux/ {
ruxit_agent::resources::linux_restartservice_initd{ $name : }
} else {
ruxit_agent::resources::windows_restartservice{ $name : }
}
}

View File

@ -0,0 +1,12 @@
# Restart Windows service
# Parameter:
# * name: Service name that should be restarted
define ruxit_agent::resources::windows_restartservice () {
ruxit_agent::resources::windows_stopservice{"restart_stop_${name}":
service_name => $name
}
->
ruxit_agent::resources::windows_startservice{"restart_start_${name}":
service_name => $name
}
}

View File

@ -0,0 +1,12 @@
# start Windows service
# Parameter:
# * $service_name: Service name that should be started
define ruxit_agent::resources::windows_startservice ($service_name) {
$cmd = 'C:\\Windows\\System32\\cmd.exe'
exec { "start_${name}":
command => "${cmd} /c sc start \"${service_name}\"",
unless => "${cmd} /c sc query \"${service_name}\" | find \"RUNNING\"",
returns => ['0', '1056'],
path => $::path
}
}

View File

@ -0,0 +1,26 @@
# Stop Windows service
# Parameter:
# * $service_name: Service name that should be stopped
# * $refreshonly: refresh only
define ruxit_agent::resources::windows_stopservice (
$service_name,
$refreshonly = false)
{
$cmd = 'C:\\Windows\\System32\\cmd.exe'
exec { "stop_${name}":
command => "${cmd} /c sc stop \"${service_name}\"",
onlyif => "${cmd} /c sc query \"${service_name}\" | find \"RUNNING\"",
refreshonly => $refreshonly,
path => $::path,
notify => Exec["wait_for_stop_${name}"]
}
exec { "wait_for_stop_${name}":
command => "${cmd} /c sc query \"${service_name}\" | find \"STOPPED\"",
unless => "${cmd} /c sc query \"${service_name}\" | find \"The specified service does not exist as an installed service.\"",
path => $::path,
tries => 10,
try_sleep => 6,
refreshonly => true
}
}

View File

@ -0,0 +1,28 @@
{
"author": "ruxitlabs",
"dependencies": [
{ "version_requirement":">=4.3.0","name":"puppetlabs/stdlib"},
{ "version_requirement":">=0.1.6","name":"sledge/http_download" }
],
"license": "BSD-3-Clause",
"name": "ruxit-ruxit_agent",
"operatingsystem_support": [{
"operatingsystem": "Windows"
},{
"operatingsystem": "RedHat"
},{
"operatingsystem": "Ubuntu"
},{
"operatingsystem": "Debian"
},{
"operatingsystem": "CentOS"
}
],
"project_page": "https://github.com/ruxit/puppet/tree/master/ruxit_agent",
"issues_url": "https://support.ruxit.com",
"source": "https://github.com/ruxit/puppet/tree/master/ruxit_agent",
"requirements": [],
"summary": "This downloads and installs the ruxit agent",
"tags": [ "install", "upgrade", "ruxit", "agent" ],
"version": "1.0.3"
}

View File

@ -0,0 +1,43 @@
@echo off
set INSTALLER_DIR=<%= @install_dir %>
set INSTALLER=<%= @installer %>
set SERVER=<%= @ruxit_host %>
set TENANT=<%= @ruxit_tenant %>
set TOKEN=<%= @ruxit_token %>
set PROCESSHOOKING=1
set INSTALL_CMD=msiexec /quiet /i
set STATUSFILE=%appdata%\ruxit\installation.status
%INSTALL_CMD% %INSTALLER_DIR%\%INSTALLER% SERVER=%SERVER% TENANT=%TENANT% PROCESSHOOKING=%PROCESSHOOKING% TENANT_TOKEN=%TOKEN%
rem The status file is created by the installer. In case there was an agent installed earlier it could still be
rem there so we wait until the installer had the chance to remove it.
IF EXIST "%STATUSFILE%" (
ping -n 30 127.0.0.1 > NUL
)
rem At the end of the installation the status file will be written with the exit code for the installation.
Set COUNT=0
:waitloop
IF EXIST "%STATUSFILE%" GOTO waitloopend
ping -n 5 127.0.0.1 >NUL
Set /A COUNT+=1
IF %COUNT% gtr 60 GOTO timeout
goto waitloop
:waitloopend
set /p STATUSCODE=<%= '<%STATUSFILE%' %>
if %STATUSCODE% EQU 0 (
ECHO "Install of ruxit agent succeeded!"
EXIT 0
) ELSE (
ECHO "Error while installing ruxit Agent!"
EXIT 1
)
:timeout
ECHO Timeout while installing ruxit Agent!
EXIT 2

View File

@ -0,0 +1,28 @@
#!/bin/bash
#
# Installs the ruxit linux agent
#
INSTALLER_DIR=<%= @install_dir %>
INSTALLER=<%= @installer %>
SERVER=<%= @ruxit_host %>
TENANT=<%= @ruxit_tenant %>
TOKEN=<%= @ruxit_token %>
PROCESSHOOKING=1
CHMOD=`/usr/bin/which chmod`
CHOWN=`/usr/bin/which chown`
#fix permissions
$CHMOD 774 $INSTALLER_DIR/$INSTALLER
$CHOWN -R <%= @user %>:<%= @group %> $INSTALLER_DIR
$INSTALLER_DIR/$INSTALLER SERVER=$SERVER TENANT=$TENANT PROCESSHOOKING=$PROCESSHOOKING TENANT_TOKEN=$TOKEN
if [ $? -ne 0 ]; then
echo "Error while installing ruxit agent!"
exit 1
else
echo "Install of ruxit agent succeeded!"
fi
exit 0