Skip to content

Commit

Permalink
Adds systemd support
Browse files Browse the repository at this point in the history
  • Loading branch information
croomes committed Aug 10, 2014
1 parent 748a08b commit 24931c8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 11 deletions.
6 changes: 2 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Installs the consul daemon (via url or package)
* Optionally installs a user to run it under
* Installs a configuration file (/etc/consul/config.json)
* Manages the consul service via upstart
* Manages the consul service via upstart, sysv, or systemd

##Usage

Expand All @@ -31,9 +31,7 @@ class { 'consul':

##Limitations

This module requires upstart to manage the service. Patches welcome! (with tests)

Also it depends on the JSON gem, or a modern ruby.
Depends on the JSON gem, or a modern ruby.

##Development
Open an [issue](https://github.com/solarkennedy/puppet-consul/issues) or
Expand Down
12 changes: 10 additions & 2 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,20 @@
content => template('consul/consul.upstart.erb'),
}
}
'redhat' : {
'systemd' : {
file { '/lib/systemd/system/consul.service':
mode => '0644',
owner => 'root',
group => 'root',
content => template('consul/consul.systemd.erb'),
}
}
'sysv' : {
file { '/etc/init.d/consul':
mode => '0555',
owner => 'root',
group => 'root',
content => template('consul/consul.redhat.erb')
content => template('consul/consul.sysv.erb')
}
}
'debian' : {
Expand Down
10 changes: 8 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
/(10|12|14)\.04/ => 'upstart',
default => undef
},
/CentOS|RedHat/ => $::operatingsystemmajrelease ? {
/(4|5|6)/ => 'sysv',
default => 'systemd',
},
'Fedora' => $::operatingsystemmajrelease ? {
/(12|13|14)/ => 'sysv',
default => 'systemd',
},
'Debian' => 'debian',
'CentOS' => 'redhat',
'RedHat' => 'redhat',
default => undef
}
}
27 changes: 24 additions & 3 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,36 @@
it { should contain_file('/etc/init/consul.conf').with_content(/sudo -u custom_consul_user -g custom_consul_group/) }
end

context "On a redhat-based OS" do
context "On a redhat 6 based OS" do
let(:facts) {{
:operatingsystem => 'CentOS'
:operatingsystem => 'CentOS',
:operatingsystemmajrelease => 6,
}}

it { should contain_class('consul').with_init_style('redhat') }
it { should contain_class('consul').with_init_style('sysv') }
it { should contain_file('/etc/init.d/consul').with_content(/daemon --user=consul/) }
end

context "On a redhat 7 based OS" do
let(:facts) {{
:operatingsystem => 'CentOS',
:operatingsystemmajrelease => 7,
}}

it { should contain_class('consul').with_init_style('systemd') }
it { should contain_file('/lib/systemd/system/consul.service').with_content(/consul agent/) }
end

context "On a fedora 20 based OS" do
let(:facts) {{
:operatingsystem => 'Fedora',
:operatingsystemmajrelease => 20,
}}

it { should contain_class('consul').with_init_style('systemd') }
it { should contain_file('/lib/systemd/system/consul.service').with_content(/consul agent/) }
end

context "On hardy" do
let(:facts) {{
:operatingsystem => 'Ubuntu',
Expand Down
17 changes: 17 additions & 0 deletions templates/consul.systemd.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Consul Agent
Wants=basic.target
After=basic.target network.target

[Service]
User=<%= scope.lookupvar('consul::user') %>
Group=<%= scope.lookupvar('consul::group') %>
ExecStart=<%= scope.lookupvar('consul::bin_dir') %>/consul agent \
-config-dir <%= scope.lookupvar('consul::config_dir') %> <%= scope.lookupvar('consul::extra_options') %>
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

This comment has been minimized.

Copy link
@amiryal

amiryal Dec 4, 2016

Contributor

Why so long? And if it’s in reference to some work by Adams – why so arbitrary?

I would like my Consul agents to respawn as soon as possible. The default is 100ms; why was it overridden?

This comment has been minimized.

Copy link
@solarkennedy

solarkennedy Dec 4, 2016

Contributor

You are right this seems silly long. I've set it to 5s.
If you have some good data on what this should be please make a PR.


[Install]
WantedBy=multi-user.target
File renamed without changes.

0 comments on commit 24931c8

Please sign in to comment.