Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #37 : archive install now checks if user/service are defined be… #38

Merged
merged 1 commit into from
Aug 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ This assumes that you with to install Grafana using the 'package' method. To est
install_method => 'docker',
}
```

##Usage

###Classes and Defined Types
Expand Down Expand Up @@ -167,6 +168,34 @@ The name of the service managed with the 'archive' and 'package' install methods

The version of Grafana to install and manage. Defaults to the latest version of Grafana available at the time of module release.

##Advanced usage:

The archive install method will create the user and a "command line" service by default.
There are no extra parameters to manage user/service for archive. However, both check to see if they are defined before defining. This way you can creat your own user and service with your own specifications. (sort of overriding)
The service can be a bit tricky, in this example below, the class sensu_install::grafana::service creates a startup script and a service{'grafana-server':}

Example:
```puppet
user { 'grafana':
ensure => present,
uid => '1234',
}
->
class { 'grafana':
install_method => 'archive',
}

include sensu_install::grafana::service

# run your service after install/config but before grafana::service
Class[::grafana::install]
->
Class[sensu_install::grafana::service]
->
Class[::grafana::service]

```

##Limitations

This module has been tested on Ubuntu 14.04, using each of the 'archive', docker' and 'package' installation methods. Other configurations should work with minimal, if any, additional effort.
Expand Down
10 changes: 6 additions & 4 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@
url => $::grafana::archive_source
}

user { 'grafana':
ensure => present,
home => $::grafana::install_dir,
require => Archive['grafana']
if !defined(User['grafana']){
user { 'grafana':
ensure => present,
home => $::grafana::install_dir,
require => Archive['grafana']
}
}

file { $::grafana::install_dir:
Expand Down
16 changes: 9 additions & 7 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@
$service_path = "${::grafana::install_dir}/bin/${::grafana::service_name}"
$service_config = "${::grafana::install_dir}/conf/custom.ini"

service { $::grafana::service_name:
ensure => running,
provider => base,
binary => "su - grafana -c '${service_path} -config=${service_config} -homepath=${::grafana::install_dir} web &'",
hasrestart => false,
hasstatus => false,
status => "ps -ef | grep ${::grafana::service_name} | grep -v grep"
if !defined(Service[$::grafana::service_name]){
service { $::grafana::service_name:
ensure => running,
provider => base,
binary => "su - grafana -c '${service_path} -config=${service_config} -homepath=${::grafana::install_dir} web &'",
hasrestart => false,
hasstatus => false,
status => "ps -ef | grep ${::grafana::service_name} | grep -v grep"
}
}
}
default: {
Expand Down
25 changes: 25 additions & 0 deletions spec/classes/grafana_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@
it { should contain_service('grafana-server').with_ensure('running').with_provider('base') }
it { should contain_service('grafana-server').with_hasrestart(false).with_hasstatus(false) }
end

context 'when user already defined' do
let(:pre_condition) {
'user{"grafana":
ensure => present,
}'
}
describe 'do NOT create grafana user' do
it { should_not contain_user('grafana').with_ensure('present').with_home(install_dir) }
end
end

context 'when service already defined' do
let(:pre_condition) {
'service{"grafana-server":
ensure => running,
hasrestart => true,
hasstatus => true,
}'
}
# let(:params) {{ :service_name => 'grafana-server'}}
describe 'do NOT run service' do
it { should_not contain_service('grafana-server').with_hasrestart(false).with_hasstatus(false) }
end
end
end

context 'invalid parameters' do
Expand Down