From 83774efe4445de1504589eba4d4c8e1b6c78512d Mon Sep 17 00:00:00 2001 From: Ernestas Poskus Date: Tue, 26 Jun 2018 14:55:37 +0300 Subject: [PATCH] Drop sysvinit support --- .kitchen.yml | 6 --- Berksfile | 2 +- README.md | 12 ++++-- libraries/proxysql_service.rb | 55 ++++++++++++++-------------- metadata.rb | 4 +- test/integration/default/proxysql.rb | 7 ---- test/integration/default/service.rb | 18 +++++++++ 7 files changed, 57 insertions(+), 47 deletions(-) create mode 100644 test/integration/default/service.rb diff --git a/.kitchen.yml b/.kitchen.yml index 406258a..3863ece 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -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: diff --git a/Berksfile b/Berksfile index 0ee901d..184d020 100644 --- a/Berksfile +++ b/Berksfile @@ -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' diff --git a/README.md b/README.md index af659d6..2c8c37f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` diff --git a/libraries/proxysql_service.rb b/libraries/proxysql_service.rb index 77147ca..2a1ac84 100644 --- a/libraries/proxysql_service.rb +++ b/libraries/proxysql_service.rb @@ -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 @@ -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 @@ -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 diff --git a/metadata.rb b/metadata.rb index 5865b9f..365d1ce 100644 --- a/metadata.rb +++ b/metadata.rb @@ -7,7 +7,7 @@ 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' @@ -15,4 +15,4 @@ supports 'debian' depends 'poise', '~> 2.8.1' -depends 'poise-service', '~> 1.5.2' +depends 'systemd', '~> 3.2.3' diff --git a/test/integration/default/proxysql.rb b/test/integration/default/proxysql.rb index 599f74c..5320b0d 100644 --- a/test/integration/default/proxysql.rb +++ b/test/integration/default/proxysql.rb @@ -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 } diff --git a/test/integration/default/service.rb b/test/integration/default/service.rb new file mode 100644 index 0000000..b3406fc --- /dev/null +++ b/test/integration/default/service.rb @@ -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