├── manifests ├── standalone.pp ├── config.pp ├── params.pp ├── package.pp ├── service.pp └── init.pp └── files └── etc └── init.d └── kibana /manifests/standalone.pp: -------------------------------------------------------------------------------- 1 | # == Class: kibana::standalone 2 | # 3 | # This class is able to install or remove kibana on a node. 4 | # It manages the status of the related service. 5 | # 6 | # 7 | # 8 | # === Parameters 9 | # 10 | # 11 | # 12 | # === Examples 13 | # 14 | # 15 | # 16 | # === Authors 17 | # 18 | # * Richard Pijnenburg 19 | # 20 | class kibana::standalone( ) 21 | inherits kibana::params { 22 | 23 | if $kibana::standalone == true { 24 | 25 | file { '/etc/init.d/kibana': 26 | ensure => present, 27 | owner => 'root', 28 | group => 'root', 29 | mode => '0755', 30 | source => "puppet:///modules/${module_name}/etc/init.d/kibana" 31 | } 32 | 33 | } 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /manifests/config.pp: -------------------------------------------------------------------------------- 1 | # == Class: kibana::config 2 | # 3 | # This class exists to coordinate all configuration related actions, 4 | # functionality and logical units in a central place. 5 | # 6 | # 7 | # === Parameters 8 | # 9 | # This class does not provide any parameters. 10 | # 11 | # 12 | # === Examples 13 | # 14 | # This class may be imported by other classes to use its functionality: 15 | # class { 'kibana::config': } 16 | # 17 | # It is not intended to be used directly by external resources like node 18 | # definitions or other modules. 19 | # 20 | # 21 | # === Authors 22 | # 23 | # * Richard Pijnenburg 24 | # 25 | class kibana::config { 26 | 27 | #### Configuration 28 | 29 | if $kibana::config_file != false { 30 | 31 | file { 'kibana_config': 32 | ensure => 'present', 33 | path => '/usr/local/kibana/KibanaConfig.rb', 34 | mode => '0644', 35 | owner => 'root', 36 | group => 'root', 37 | source => "puppet:///${kibana::config_file}", 38 | notify => Service['kibana'], 39 | } 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /files/etc/init.d/kibana: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Init script for Kibana 4 | # 5 | # chkconfig: - 85 15 6 | # description: Init script for kibana 7 | 8 | ### BEGIN INIT INFO 9 | # Provides: Kibana 10 | # Required-Start: $local_fs $network $remote_fs 11 | # Required-Stop: $local_fs $network $remote_fs 12 | # Default-Start: 2 3 4 5 13 | # Default-Stop: 0 1 6 14 | # Short-Description: start and stop Kibana 15 | # Description: Kibana is a webfront end for Elasticsearch 16 | ### END INIT INFO 17 | 18 | 19 | # Source function library. 20 | . /etc/rc.d/init.d/functions 21 | 22 | 23 | DAEMON='/usr/local/kibana/kibana-daemon.rb' 24 | 25 | start() { 26 | echo -n $"Starting Kibana: " 27 | 28 | ruby $DAEMON start 29 | RETVAL=$? 30 | 31 | if [ $RETVAL = 0 ]; then 32 | echo_success 33 | else 34 | echo_failure 35 | fi 36 | 37 | echo 38 | return $RETVAL 39 | } 40 | 41 | stop() { 42 | echo -n $"Stopping Kibana: " 43 | ruby $DAEMON stop 44 | RETVAL=$? 45 | if [ $RETVAL = 0 ]; then 46 | echo_success 47 | else 48 | echo_failure 49 | fi 50 | 51 | rm -rf /usr/local/kibana/tmp/kibana.rb.pid 52 | 53 | echo 54 | return $RETVAL 55 | } 56 | 57 | restart () { 58 | stop 59 | start 60 | } 61 | 62 | status () { 63 | ruby $DAEMON status 64 | RETVAL=$? 65 | return $RETVAL 66 | } 67 | 68 | force_reload () { 69 | restart 70 | } 71 | 72 | # See how we were called. 73 | case "$1" in 74 | start) 75 | start 76 | ;; 77 | stop) 78 | stop 79 | ;; 80 | restart) 81 | restart 82 | ;; 83 | status) 84 | status 85 | ;; 86 | force-reload) 87 | force_reload 88 | ;; 89 | *) 90 | echo "Usage: $0 {start|stop|restart|status|force-reload}" 91 | exit 2 92 | esac 93 | 94 | exit $? 95 | -------------------------------------------------------------------------------- /manifests/params.pp: -------------------------------------------------------------------------------- 1 | # == Class: kibana::params 2 | # 3 | # This class exists to 4 | # 1. Declutter the default value assignment for class parameters. 5 | # 2. Manage internally used module variables in a central place. 6 | # 7 | # Therefore, many operating system dependent differences (names, paths, ...) 8 | # are addressed in here. 9 | # 10 | # 11 | # === Parameters 12 | # 13 | # This class does not provide any parameters. 14 | # 15 | # 16 | # === Examples 17 | # 18 | # This class is not intended to be used directly. 19 | # 20 | # 21 | # === Links 22 | # 23 | # * {Puppet Docs: Using Parameterized Classes}[http://j.mp/nVpyWY] 24 | # 25 | # 26 | # === Authors 27 | # 28 | # * Richard Pijnenburg 29 | # 30 | class kibana::params { 31 | 32 | #### Default values for the parameters of the main module class, init.pp 33 | 34 | # ensure 35 | $ensure = 'present' 36 | 37 | # autoupgrade 38 | $autoupgrade = false 39 | 40 | # service status 41 | $status = 'enabled' 42 | 43 | #### Internal module values 44 | 45 | # packages 46 | case $::operatingsystem { 47 | 'CentOS', 'Fedora', 'Scientific': { 48 | # main application 49 | $package = [ 'kibana' ] 50 | } 51 | 'Debian', 'Ubuntu': { 52 | # main application 53 | $package = [ 'kibana' ] 54 | } 55 | default: { 56 | fail("\"${module_name}\" provides no package default value 57 | for \"${::operatingsystem}\"") 58 | } 59 | } 60 | 61 | # service parameters 62 | case $::operatingsystem { 63 | 'CentOS', 'Fedora', 'Scientific': { 64 | $service_name = 'kibana' 65 | $service_hasrestart = true 66 | $service_hasstatus = true 67 | $service_pattern = $service_name 68 | } 69 | 'Debian', 'Ubuntu': { 70 | $service_name = 'kibana' 71 | $service_hasrestart = true 72 | $service_hasstatus = true 73 | $service_pattern = $service_name 74 | } 75 | default: { 76 | fail("\"${module_name}\" provides no service parameters 77 | for \"${::operatingsystem}\"") 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /manifests/package.pp: -------------------------------------------------------------------------------- 1 | # == Class: kibana::package 2 | # 3 | # This class exists to coordinate all software package management related 4 | # actions, functionality and logical units in a central place. 5 | # 6 | # 7 | # === Parameters 8 | # 9 | # This class does not provide any parameters. 10 | # 11 | # 12 | # === Examples 13 | # 14 | # This class may be imported by other classes to use its functionality: 15 | # class { 'kibana::package': } 16 | # 17 | # It is not intended to be used directly by external resources like node 18 | # definitions or other modules. 19 | # 20 | # 21 | # === Authors 22 | # 23 | # * Richard Pijnenburg 24 | # 25 | class kibana::package { 26 | 27 | #### Package management 28 | 29 | # set params: in operation 30 | if $kibana::ensure == 'present' { 31 | 32 | # Check if we want to install a specific version or not 33 | if $kibana::version == false { 34 | 35 | $package_ensure = $kibana::autoupgrade ? { 36 | true => 'latest', 37 | false => 'present', 38 | } 39 | 40 | } else { 41 | 42 | # install specific version 43 | $package_ensure = $kibana::version 44 | 45 | } 46 | 47 | # set params: removal 48 | } else { 49 | $package_ensure = 'purged' 50 | } 51 | 52 | if $kibana::pkg_source { 53 | 54 | $filenameArray = split($kibana::pkg_source, '/') 55 | $basefilename = $filenameArray[-1] 56 | 57 | $extArray = split($basefilename, '\.') 58 | $ext = $extArray[-1] 59 | 60 | $tmpSource = "/tmp/${basefilename}" 61 | 62 | file { $tmpSource: 63 | source => $kibana::pkg_source, 64 | owner => 'root', 65 | group => 'root', 66 | backup => false 67 | } 68 | 69 | case $ext { 70 | 'deb': { $pkg_provider = 'dpkg' } 71 | 'rpm': { $pkg_provider = 'rpm' } 72 | default: { fail("Unknown file extention \"${ext}\"") } 73 | } 74 | } else { 75 | $tmpSource = undef 76 | $pkg_provider = undef 77 | } 78 | 79 | # action 80 | package { $kibana::params::package: 81 | ensure => $package_ensure, 82 | source => $tmpSource, 83 | provider => $pkg_provider 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /manifests/service.pp: -------------------------------------------------------------------------------- 1 | # == Class: kibana::service 2 | # 3 | # This class exists to coordinate all service management related actions, 4 | # functionality and logical units in a central place. 5 | # 6 | # Note: "service" is the Puppet term and type for background processes 7 | # in general and is used in a platform-independent way. E.g. "service" means 8 | # "daemon" in relation to Unix-like systems. 9 | # 10 | # 11 | # === Parameters 12 | # 13 | # This class does not provide any parameters. 14 | # 15 | # 16 | # === Examples 17 | # 18 | # This class may be imported by other classes to use its functionality: 19 | # class { 'kibana::service': } 20 | # 21 | # It is not intended to be used directly by external resources like node 22 | # definitions or other modules. 23 | # 24 | # 25 | # === Authors 26 | # 27 | # * Richard Pijnenburg 28 | # 29 | class kibana::service { 30 | 31 | #### Service management 32 | 33 | # Only when we are running stand-alone we will configure the service 34 | if $kibana::standalone == true { 35 | 36 | # set params: in operation 37 | if $kibana::ensure == 'present' { 38 | 39 | case $kibana::status { 40 | # make sure service is currently running, start it on boot 41 | 'enabled': { 42 | $service_ensure = 'running' 43 | $service_enable = true 44 | } 45 | # make sure service is currently stopped, do not start it on boot 46 | 'disabled': { 47 | $service_ensure = 'stopped' 48 | $service_enable = false 49 | } 50 | # make sure service is currently running, do not start it on boot 51 | 'running': { 52 | $service_ensure = 'running' 53 | $service_enable = false 54 | } 55 | # do not start service on boot, do not care whether currently running or not 56 | 'unmanaged': { 57 | $service_ensure = undef 58 | $service_enable = false 59 | } 60 | # unknown status 61 | # note: don't forget to update the parameter check in init.pp if you 62 | # add a new or change an existing status. 63 | default: { 64 | fail("\"${kibana::status}\" is an unknown service status value") 65 | } 66 | } 67 | 68 | # set params: removal 69 | } else { 70 | 71 | # make sure the service is stopped and disabled (the removal itself will be 72 | # done by package.pp) 73 | $service_ensure = 'stopped' 74 | $service_enable = false 75 | 76 | } 77 | 78 | # action 79 | service { 'kibana': 80 | ensure => $service_ensure, 81 | enable => $service_enable, 82 | name => $kibana::params::service_name, 83 | hasstatus => $kibana::params::service_hasstatus, 84 | hasrestart => $kibana::params::service_hasrestart, 85 | pattern => $kibana::params::service_pattern, 86 | } 87 | 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /manifests/init.pp: -------------------------------------------------------------------------------- 1 | # == Class: kibana::standalone 2 | # 3 | # This class is able to install or remove kibana on a node. 4 | # It manages the status of the related service. 5 | # 6 | # === Parameters 7 | # 8 | # [*ensure*] 9 | # String. Controls if the managed resources shall be present or 10 | # absent. If set to absent: 11 | # * The managed software packages are being uninstalled. 12 | # * Any traces of the packages will be purged as good as possible. This may 13 | # include existing configuration files. The exact behavior is provider 14 | # dependent. Q.v.: 15 | # * Puppet type reference: {package, "purgeable"}[http://j.mp/xbxmNP] 16 | # * {Puppet's package provider source code}[http://j.mp/wtVCaL] 17 | # * System modifications (if any) will be reverted as good as possible 18 | # (e.g. removal of created users, services, changed log settings, ...). 19 | # * This is thus destructive and should be used with care. 20 | # Defaults to present. 21 | # 22 | # [*autoupgrade*] 23 | # Boolean. If set to true, any managed package gets upgraded 24 | # on each Puppet run when the package provider is able to find a newer 25 | # version than the present one. The exact behavior is provider dependent. 26 | # Q.v.: 27 | # * Puppet type reference: {package, "upgradeable"}[http://j.mp/xbxmNP] 28 | # * {Puppet's package provider source code}[http://j.mp/wtVCaL] 29 | # Defaults to false. 30 | # 31 | # [*status*] 32 | # String to define the status of the service. Possible values: 33 | # * enabled: Service is running and will be started at boot time. 34 | # * disabled: Service is stopped and will not be started at boot 35 | # time. 36 | # * running: Service is running but will not be started at boot time. 37 | # You can use this to start a service on the first Puppet run instead of 38 | # the system startup. 39 | # * unmanaged: Service will not be started at boot time and Puppet 40 | # does not care whether the service is running or not. For example, this may 41 | # be useful if a cluster management software is used to decide when to start 42 | # the service plus assuring it is running on the desired node. 43 | # Defaults to enabled. The singular form ("service") is used for the 44 | # sake of convenience. Of course, the defined status affects all services if 45 | # more than one is managed (see service.pp to check if this is the 46 | # case). 47 | # 48 | # [*version*] 49 | # String to set the specific version you want to install. 50 | # Defaults to false. 51 | # 52 | # The default values for the parameters are set in kibana::params. Have 53 | # a look at the corresponding params.pp manifest file if you need more 54 | # technical information about them. 55 | # 56 | # 57 | # === Examples 58 | # 59 | # * Installation, make sure service is running and will be started at boot time: 60 | # class { 'kibana': } 61 | # 62 | # * Removal/decommissioning: 63 | # class { 'kibana': 64 | # ensure => 'absent', 65 | # } 66 | # 67 | # * Install everything but disable service(s) afterwards 68 | # class { 'kibana': 69 | # status => 'disabled', 70 | # } 71 | # 72 | # 73 | # === Authors 74 | # 75 | # * Richard Pijnenburg 76 | # 77 | class kibana( 78 | $ensure = $kibana::params::ensure, 79 | $autoupgrade = $kibana::params::autoupgrade, 80 | $status = $kibana::params::status, 81 | $pkg_source = undef, 82 | $version = false, 83 | $standalone = true, 84 | $config_file = false 85 | ) inherits kibana::params { 86 | 87 | #### Validate parameters 88 | 89 | # ensure 90 | if ! ($ensure in [ 'present', 'absent' ]) { 91 | fail("\"${ensure}\" is not a valid ensure parameter value") 92 | } 93 | 94 | # autoupgrade 95 | validate_bool($autoupgrade) 96 | 97 | # service status 98 | if ! ($status in [ 'enabled', 'disabled', 'running', 'unmanaged' ]) { 99 | fail("\"${status}\" is not a valid status parameter value") 100 | } 101 | 102 | 103 | 104 | #### Manage actions 105 | 106 | # package(s) 107 | class { 'kibana::package': } 108 | 109 | # configuration 110 | class { 'kibana::config': } 111 | 112 | # service(s) 113 | class { 'kibana::service': } 114 | 115 | # Standalone 116 | class { 'kibana::standalone': } 117 | 118 | 119 | #### Manage relationships 120 | 121 | if $ensure == 'present' { 122 | # we need the software before configuring it 123 | Class['kibana::package'] -> Class['kibana::config'] 124 | Class['kibana::package'] -> Class['kibana::standalone'] 125 | 126 | # Get the init file bfore handling the service 127 | Class['kibana::standalone'] -> Class['kibana::service'] 128 | 129 | # we need the software and a working configuration before running a service 130 | Class['kibana::package'] -> Class['kibana::service'] 131 | Class['kibana::config'] -> Class['kibana::service'] 132 | 133 | } else { 134 | 135 | # make sure all services are getting stopped before software removal 136 | Class['kibana::service'] -> Class['kibana::package'] 137 | } 138 | 139 | } 140 | --------------------------------------------------------------------------------