Skip to content

Commit

Permalink
Merge pull request #38 from ernestas-poskus/features/drop_sysvinit_su…
Browse files Browse the repository at this point in the history
…pport

Drop sysvinit support
  • Loading branch information
ernestas-poskus authored Jun 27, 2018
2 parents c926676 + 83774ef commit 73b3469
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 47 deletions.
6 changes: 0 additions & 6 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ platforms:
image: ernestasposkus/centos7
run_command: '/usr/lib/systemd/systemd'
run_options: '--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro'
- name: centos-6
driver_plugin: docker
driver:
image: ernestasposkus/centos6
run_command: '/sbin/init'
run_options: ''
- name: ubuntu-1604
driver_plugin: docker
driver:
Expand Down
2 changes: 1 addition & 1 deletion Berksfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ source 'https://supermarket.chef.io'
metadata

cookbook 'poise', '~> 2.8.1'
cookbook 'poise-service', '~> 1.5.2'
cookbook 'systemd', '~> 3.2.3'

group 'test' do
cookbook 'test-proxysql', path: 'test/integration/cookbooks/test-proxysql'
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,16 @@ end

```ruby
proxysql_service 'any name' do
# service_name 'proxysql-eu1'
# user String
# group String
# data_dir String
# config_dir String

# version String
# package_release String
# lock_version TrueClass, FalseClass
# pre_statements Array
# post_statements Array
# bin String
# admin_socket [String, NilClass]
# flags Hash
Expand All @@ -172,11 +176,13 @@ proxysql_service 'any name' do
# mysql_query_rules Hash
# schedulers Hash
# mysql_replication_hostgroups Hash

# service_name String
# service_unit_after Array
# service_install_wanted_by Array
# service_limit_core Integer
# service_limit_nofile Integer
# service_timeout_sec Integer
# service_restart String
# service_restart_sec Integer
end
```

Expand Down
55 changes: 27 additions & 28 deletions libraries/proxysql_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,11 @@ class ProxysqlService < ProxysqlBaseService

# Service
attribute(:service_name, kind_of: String, default: 'proxysql')
attribute(:service_unit_after, kind_of: Array, default: %w[network])
attribute(
:service_provider,
kind_of: Symbol,
default: lazy do
init_systemd = Mixlib::ShellOut.new('ps --no-headers -o comm 1')
init_systemd.run_command
init_systemd.error!
if init_systemd.stdout.chomp == 'systemd'
:systemd
else
:sysvinit
end
end
)
attribute(:service_unit_after, kind_of: Array, default: %w[network.target])
attribute(:service_limit_core, kind_of: Integer, default: 1_073_741_824)
attribute(:service_limit_nofile, kind_of: Integer, default: 102_400)
attribute(:service_timeout_sec, kind_of: Integer, default: 5)
attribute(:service_restart, kind_of: String, default: 'on-failure')
end
end

Expand Down Expand Up @@ -217,17 +207,12 @@ def install_config
post_st = new_resource.post_statements.map { |st| "#{st};" }
pre_cmd = %(echo "#{pre_st.join(' ')}" | #{mysql_cmd})
post_cmd = %(echo "#{post_st.join(' ')}" | #{mysql_cmd})
service = if new_resource.service_provider == :systemd
"systemctl is-active #{new_resource.service_name}"
else
"service status #{new_resource.service_name}"
end
variables = config_variables

execute 'load-config' do
command "#{pre_cmd} && #{post_cmd}"
action :nothing
only_if service
only_if "systemctl is-active #{new_resource.service_name}"
end

template config_file do
Expand Down Expand Up @@ -258,13 +243,27 @@ def service_args
end

def install_service
command = "#{new_resource.bin} #{service_args}"
systemd_after_target = Array(new_resource.service_unit_after).join(' ')
poise_service new_resource.service_name do
provider new_resource.service_provider
command command
user new_resource.user
options :systemd, after_target: systemd_after_target
exec_start = "#{new_resource.bin} #{service_args}"
systemd_service new_resource.service_name do
unit do
description 'Chef managed ProxySQL service'
after Array(new_resource.service_unit_after).join(' ')
end

install do
wanted_by 'multi-user.target'
end

service do
type 'simple'
exec_start exec_start
restart new_resource.service_restart
timeout_sec new_resource.service_timeout_sec
user new_resource.user
group new_resource.group
limit_core new_resource.service_limit_core
limit_nofile new_resource.service_limit_nofile
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
issues_url 'https://github.com/ernestas-poskus/chef-proxysql/issues'
source_url 'https://github.com/ernestas-poskus/chef-proxysql'
chef_version '>= 12.1' if respond_to?(:chef_version)
version '2.4.0'
version '3.0.0'

supports 'redhat'
supports 'centos'
supports 'ubuntu'
supports 'debian'

depends 'poise', '~> 2.8.1'
depends 'poise-service', '~> 1.5.2'
depends 'systemd', '~> 3.2.3'
7 changes: 0 additions & 7 deletions test/integration/default/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
it { should be_installed }
end

# ProxySQL
describe service('proxysql-first') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end

# ProxySQL admin
describe port(6033) do
it { should be_listening }
Expand Down
18 changes: 18 additions & 0 deletions test/integration/default/service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ProxySQL
describe service('proxysql-first') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end

describe file('/etc/systemd/system/proxysql-first.service') do
it { should exist }
its('owner') { should eq 'root' }
its('group') { should eq 'root' }
its('content') { should match 'TimeoutSec = 5' }
its('content') { should match 'Restart = on-failure' }
its('content') { should match 'User = proxysql' }
its('content') { should match 'Group = proxysql' }
its('content') { should match 'LimitCORE = 1073741824' }
its('content') { should match 'LimitNOFILE = 102400' }
end

0 comments on commit 73b3469

Please sign in to comment.