diff --git a/README.md b/README.md index 630902f..6efa5b4 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Requirements Chef version 0.10.10+ and Ohai 0.6.12+ are required. ### Platform -* Ubuntu 12.10 +* Ubuntu 22.02 **Notes**: This cookbook has been tested on the listed platforms only. It may work on other platforms with modification. diff --git a/metadata.rb b/metadata.rb index 0385498..86ac4e2 100644 --- a/metadata.rb +++ b/metadata.rb @@ -7,7 +7,7 @@ version '1.2.3' issues_url 'https://github.com/simplereach/chef-nsq/issues' source_url 'https://github.com/simplereach/chef-nsq' -chef_version '11.18.6' +chef_version '12.21.31' supports 'debian', '>= 6.0' supports 'ubuntu', '>= 10.04' diff --git a/recipes/nsqadmin.rb b/recipes/nsqadmin.rb index 6210a49..5103314 100644 --- a/recipes/nsqadmin.rb +++ b/recipes/nsqadmin.rb @@ -13,9 +13,16 @@ nsq_release = "nsq-#{node['nsq']['version']}-#{node['nsq']['go_version']}" if node['nsq']['setup_services'] - template '/etc/init/nsqadmin.conf' do + template '/usr/local/sbin/nsqadmin.sh' do action :create - source 'upstart.nsqadmin.conf.erb' + source 'nsqadmin.sh' + owner 'root' + mode '0755' + end + + template '/etc/systemd/system/nsqadmin.service' do + action :create + source 'nsqadmin.service' mode '0644' # need to stop/start in order to reload config notifies :stop, 'service[nsqadmin]', :immediately @@ -23,7 +30,7 @@ end service 'nsqadmin' do - provider Chef::Provider::Service::Upstart + provider Chef::Provider::Service::Systemd action [:enable, :start] supports stop: true, start: true, restart: true, status: true subscribes :restart, "ark[#{nsq_release}]", :delayed diff --git a/recipes/nsqd.rb b/recipes/nsqd.rb index 485e055..202465e 100644 --- a/recipes/nsqd.rb +++ b/recipes/nsqd.rb @@ -24,17 +24,24 @@ end if node['nsq']['setup_services'] - template '/etc/init/nsqd.conf' do + template '/usr/local/sbin/nsqd.sh' do action :create - source 'upstart.nsqd.conf.erb' - mode '0644' + source 'nsqd.sh' + owner 'root' + mode '0755' + end + + template '/etc/systemd/system/nsqd.service' do + action :create + source 'nsqd.service' + mode '0644' # need to stop/start in order to reload config notifies :stop, 'service[nsqd]', :immediately notifies :start, 'service[nsqd]', :immediately end service 'nsqd' do - provider Chef::Provider::Service::Upstart + provider Chef::Provider::Service::Systemd action [:enable, :start] supports stop: true, start: true, restart: true, status: true subscribes :restart, "ark[#{nsq_release}]", :delayed diff --git a/recipes/nsqlookupd.rb b/recipes/nsqlookupd.rb index e9a4049..cdc2c9c 100644 --- a/recipes/nsqlookupd.rb +++ b/recipes/nsqlookupd.rb @@ -13,9 +13,16 @@ nsq_release = "nsq-#{node['nsq']['version']}-#{node['nsq']['go_version']}" if node['nsq']['setup_services'] - template '/etc/init/nsqlookupd.conf' do + template '/usr/local/sbin/nsqlookupd.sh' do action :create - source 'upstart.nsqlookupd.conf.erb' + source 'nsqlookupd.sh' + owner 'root' + mode '0755' + end + + template '/etc/systemd/system/nsqlookupd.service' do + action :create + source 'nsqlookupd.service' mode '0644' # need to stop/start in order to reload config notifies :stop, 'service[nsqlookupd]', :immediately @@ -23,7 +30,7 @@ end service 'nsqlookupd' do - provider Chef::Provider::Service::Upstart + provider Chef::Provider::Service::Systemd action [:enable, :start] supports stop: true, start: true, restart: true, status: true subscribes :restart, "ark[#{nsq_release}]", :delayed diff --git a/templates/default/nsqadmin.service b/templates/default/nsqadmin.service new file mode 100644 index 0000000..9790863 --- /dev/null +++ b/templates/default/nsqadmin.service @@ -0,0 +1,11 @@ +[Unit] +Description=nsqadmin + +[Service] +Type=simple +ExecStart=/usr/local/sbin/nsqadmin.sh +Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin +Restart=on-failure + +[Install] +WantedBy=multi-user.target diff --git a/templates/default/nsqadmin.sh b/templates/default/nsqadmin.sh new file mode 100644 index 0000000..6aa4dff --- /dev/null +++ b/templates/default/nsqadmin.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e +mkfifo /tmp/nsqadmin-log-fifo +( logger -t nsqadmin /tmp/nsqadmin-log-fifo +rm /tmp/nsqadmin-log-fifo + +exec su -s /bin/sh -c 'exec "$0" "$@"' <%= node["nsq"]["nsqadmin"]["user"] %> -- /usr/local/bin/nsqadmin \ + --template-dir <%= node["nsq"]["nsqadmin"]["nsqd_template_dir"] %> \ + <%- node["nsq"]["nsqadmin"]["lookupd_http_address"].each do |lookup_host| %> + --lookupd-http-address=<%= lookup_host %> \ + <%- end %> + --use-statsd-prefixes=<%= node["nsq"]["nsqadmin"]["use_statsd_prefixes"] %> \ + --statsd-interval=<%= node["nsq"]["nsqadmin"]["statsd_interval"] %> \ + --proxy-graphite=<%= node["nsq"]["nsqadmin"]["proxy_graphite"] %> \ + <% if node["nsq"]["nsqadmin"]["graphite_url"] != "" then %> + --graphite-url=<%= node["nsq"]["nsqadmin"]["graphite_url"] %> \ + <% end %> + --http-address=<%= node["nsq"]["nsqadmin"]["http_address"] %> 2>&1 \ No newline at end of file diff --git a/templates/default/nsqd.service b/templates/default/nsqd.service new file mode 100644 index 0000000..cb66e63 --- /dev/null +++ b/templates/default/nsqd.service @@ -0,0 +1,11 @@ +[Unit] +Description=nsqd + +[Service] +Type=simple +ExecStart=/usr/local/sbin/nsqd.sh +Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin +Restart=on-failure + +[Install] +WantedBy=multi-user.target diff --git a/templates/default/nsqd.sh b/templates/default/nsqd.sh new file mode 100644 index 0000000..af6af9f --- /dev/null +++ b/templates/default/nsqd.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +set -e +mkfifo /tmp/nsqd-log-fifo +( logger -t nsqd /tmp/nsqd-log-fifo +rm /tmp/nsqd-log-fifo + +exec su -s /bin/sh -c 'exec "$0" "$@"' <%= node['nsq']['nsqd']['user'] %> -- /usr/local/bin/nsqd \ + --data-path=<%= node['nsq']['nsqd']['data_path'] %> \ + <%- if !node['nsq']['nsqd']['tls_required'] %> + --http-address=<%= node['nsq']['nsqd']['http_address'] %> \ + <% end %> + <%- node['nsq']['nsqd']['lookupd_tcp_address'].each do |lookup_host| %> + --lookupd-tcp-address=<%= lookup_host %> \ + <% end %> + <%- if Semantic::Version.new(node['nsq']['version']) > Semantic::Version.new('0.2.21') %> + --max-output-buffer-size=<%= node['nsq']['nsqd']['max_output_buffer_size'] %> \ + --max-output-buffer-timeout=<%= node['nsq']['nsqd']['max_output_buffer_timeout'] %> \ + <% end %> + <%- if Semantic::Version.new(node['nsq']['version']) > Semantic::Version.new('0.2.22') %> + --deflate=<%= node['nsq']['nsqd']['deflate'] %> \ + --snappy=<%= node['nsq']['nsqd']['snappy'] %> \ + --max-deflate-level=<%= node['nsq']['nsqd']['max_deflate_level'] %> \ + <% end %> + <%- if Semantic::Version.new(node['nsq']['version']) > Semantic::Version.new('0.2.24') %> + --e2e-processing-latency-percentile=<%= node['nsq']['nsqd']['e2e_processing_latency_percentile'] %> \ + --e2e-processing-latency-window-time=<%= node['nsq']['nsqd']['e2e_processing_latency_window_time'] %> \ + <% end %> + <%- if Semantic::Version.new(node['nsq']['version']) >= Semantic::Version.new('0.2.27') %> + --max-msg-size=<%= node['nsq']['nsqd']['max_msg_size'] %> \ + <%- else %> + --max-message-size=<%= node['nsq']['nsqd']['max_message_size'] %> \ + <%- end %> + <%- if Semantic::Version.new(node['nsq']['version']) > Semantic::Version.new('0.2.28') %> + --https-address=<%= node['nsq']['nsqd']['https_address'] %> \ + <%- if !node['nsq']['nsqd']['tls_client_auth_policy'].empty? %> + --tls-client-auth-policy=<%= node['nsq']['nsqd']['tls_client_auth_policy'] %> \ + <%- end %> + <%- if !node['nsq']['nsqd']['tls_root_ca_file'].empty? %> + --tls-root-ca-file=<%= node['nsq']['nsqd']['tls_root_ca_file'] %> + <%- end %> + <% end %> + <%- if Semantic::Version.new(node['nsq']['version']) >= Semantic::Version.new('0.2.29') %> + --max-req-timeout=<%= node['nsq']['nsqd']['max_req_timeout'] %> \ + <%- if !node['nsq']['nsqd']['auth_http_address'].empty? %> + --auth-http-address=<%= node['nsq']['nsqd']['auth_http_address'] %> \ + <%- end %> + <%- end %> + <%- if !node['nsq']['nsqd']['tls_key'].empty? %> + --tls-key=<%= node['nsq']['nsqd']['tls_key'] %> \ + <%- end %> + <%- if !node['nsq']['nsqd']['tls_cert'].empty? %> + --tls-cert=<%= node['nsq']['nsqd']['tls_cert'] %> \ + <%- end %> + --max-body-size=<%= node['nsq']['nsqd']['max_body_size'] %> \ + --max-bytes-per-file=<%= node['nsq']['nsqd']['max_bytes_per_file'] %> \ + --max-msg-timeout=<%= node['nsq']['nsqd']['max_msg_timeout'] %> \ + --max-rdy-count=<%= node['nsq']['nsqd']['max_rdy_count'] %> \ + --mem-queue-size=<%= node['nsq']['nsqd']['mem_queue_size'] %> \ + --msg-timeout=<%= node['nsq']['nsqd']['msg_timeout'] %> \ + --statsd-address=<%= node['nsq']['nsqd']['statsd_address'] %> \ + --statsd-interval=<%= node['nsq']['nsqd']['statsd_interval'] %> \ + --statsd-mem-stats=<%= node['nsq']['nsqd']['statsd_mem_stats'] %> \ + --statsd-prefix=<%= node['nsq']['nsqd']['statsd_prefix'] %> \ + --sync-every=<%= node['nsq']['nsqd']['sync_every'] %> \ + --sync-timeout=<%= node['nsq']['nsqd']['sync_timeout'] %> \ + --tcp-address=<%= node['nsq']['nsqd']['tcp_address'] %> \ + <%- if !node['nsq']['nsqd']['broadcast_address'].empty? %> + --broadcast-address=<%= node['nsq']['nsqd']['broadcast_address'] %> \ + <%- else %> + --broadcast-address=<%= node['ipaddress'] %> \ + <%- end %> + --verbose=<%= node['nsq']['nsqd']['verbose'] %> 2>&1 \ No newline at end of file diff --git a/templates/default/nsqlookupd.service b/templates/default/nsqlookupd.service new file mode 100644 index 0000000..8388350 --- /dev/null +++ b/templates/default/nsqlookupd.service @@ -0,0 +1,11 @@ +[Unit] +Description=nsqlookupd + +[Service] +Type=simple +ExecStart=/usr/local/sbin/nsqlookupd.sh +Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin +Restart=on-failure + +[Install] +WantedBy=multi-user.target diff --git a/templates/default/nsqlookupd.sh b/templates/default/nsqlookupd.sh new file mode 100644 index 0000000..870b5f5 --- /dev/null +++ b/templates/default/nsqlookupd.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e +mkfifo /tmp/nsqlookupd-log-fifo +( logger -t nsqlookupd /tmp/nsqlookupd-log-fifo +rm /tmp/nsqlookupd-log-fifo + +exec su -s /bin/sh -c 'exec "$0" "$@"' <%= node["nsq"]["nsqlookupd"]["user"] %> -- /usr/local/bin/nsqlookupd \ + --http-address <%= node["nsq"]["nsqlookupd"]["http_address"] %> \ + --inactive-producer-timeout <%= node["nsq"]["nsqlookupd"]["inactive_producer_timeout"] %> \ + --tcp-address <%= node["nsq"]["nsqlookupd"]["tcp_address"] %> \ + <%- if !node['nsq']['nsqlookupd']['broadcast_address'].empty? %> + --broadcast-address <%= node["nsq"]["nsqlookupd"]["broadcast_address"] %> \ + <%- end %> + --tombstone-lifetime <%= node["nsq"]["nsqlookupd"]["tombstone_lifetime"] %> \ + --verbose <%= node["nsq"]["nsqlookupd"]["verbose"] %> 2>&1 \ No newline at end of file diff --git a/templates/default/upstart.nsqadmin.conf.erb b/templates/default/upstart.nsqadmin.conf.erb deleted file mode 100644 index a5969e6..0000000 --- a/templates/default/upstart.nsqadmin.conf.erb +++ /dev/null @@ -1,29 +0,0 @@ -description "nsqadmin" - -start on runlevel [2345] -stop on runlevel [!2345] - -env PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin - -respawn - -script - set -e - mkfifo /tmp/nsqadmin-log-fifo - ( logger -t nsqadmin /tmp/nsqadmin-log-fifo - rm /tmp/nsqadmin-log-fifo - - exec su -s /bin/sh -c 'exec "$0" "$@"' <%= node["nsq"]["nsqadmin"]["user"] %> -- /usr/local/bin/nsqadmin \ - --template-dir <%= node["nsq"]["nsqadmin"]["nsqd_template_dir"] %> \ - <%- node["nsq"]["nsqadmin"]["lookupd_http_address"].each do |lookup_host| %> - --lookupd-http-address=<%= lookup_host %> \ - <%- end %> - --use-statsd-prefixes=<%= node["nsq"]["nsqadmin"]["use_statsd_prefixes"] %> \ - --statsd-interval=<%= node["nsq"]["nsqadmin"]["statsd_interval"] %> \ - --proxy-graphite=<%= node["nsq"]["nsqadmin"]["proxy_graphite"] %> \ - <% if node["nsq"]["nsqadmin"]["graphite_url"] != "" then %> - --graphite-url=<%= node["nsq"]["nsqadmin"]["graphite_url"] %> \ - <% end %> - --http-address=<%= node["nsq"]["nsqadmin"]["http_address"] %> 2>&1 -end script diff --git a/templates/default/upstart.nsqd.conf.erb b/templates/default/upstart.nsqd.conf.erb deleted file mode 100644 index acfd900..0000000 --- a/templates/default/upstart.nsqd.conf.erb +++ /dev/null @@ -1,90 +0,0 @@ -description "nsqd" - -start on runlevel [2345] -stop on runlevel [!2345] - -<% if node['nsq']['nsqd']['filehandle_limit'] -%> -limit nofile <%= node['nsq']['nsqd']['filehandle_limit'] %> <%= node['nsq']['nsqd']['filehandle_limit'] %> -<% end -%> -<% if node['nsq']['nsqd']['nproc'] -%> -limit nproc <%= node['nsq']['nsqd']['nproc'] %> <%= node['nsq']['nsqd']['nproc'] %> -<% end -%> - -env PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin - -respawn - -script - set -e - mkfifo /tmp/nsqd-log-fifo - ( logger -t nsqd /tmp/nsqd-log-fifo - rm /tmp/nsqd-log-fifo - - exec su -s /bin/sh -c 'exec "$0" "$@"' <%= node['nsq']['nsqd']['user'] %> -- /usr/local/bin/nsqd \ - --data-path=<%= node['nsq']['nsqd']['data_path'] %> \ - <%- if !node['nsq']['nsqd']['tls_required'] %> - --http-address=<%= node['nsq']['nsqd']['http_address'] %> \ - <% end %> - <%- node['nsq']['nsqd']['lookupd_tcp_address'].each do |lookup_host| %> - --lookupd-tcp-address=<%= lookup_host %> \ - <% end %> - <%- if Semantic::Version.new(node['nsq']['version']) > Semantic::Version.new('0.2.21') %> - --max-output-buffer-size=<%= node['nsq']['nsqd']['max_output_buffer_size'] %> \ - --max-output-buffer-timeout=<%= node['nsq']['nsqd']['max_output_buffer_timeout'] %> \ - <% end %> - <%- if Semantic::Version.new(node['nsq']['version']) > Semantic::Version.new('0.2.22') %> - --deflate=<%= node['nsq']['nsqd']['deflate'] %> \ - --snappy=<%= node['nsq']['nsqd']['snappy'] %> \ - --max-deflate-level=<%= node['nsq']['nsqd']['max_deflate_level'] %> \ - <% end %> - <%- if Semantic::Version.new(node['nsq']['version']) > Semantic::Version.new('0.2.24') %> - --e2e-processing-latency-percentile=<%= node['nsq']['nsqd']['e2e_processing_latency_percentile'] %> \ - --e2e-processing-latency-window-time=<%= node['nsq']['nsqd']['e2e_processing_latency_window_time'] %> \ - <% end %> - <%- if Semantic::Version.new(node['nsq']['version']) >= Semantic::Version.new('0.2.27') %> - --max-msg-size=<%= node['nsq']['nsqd']['max_msg_size'] %> \ - <%- else %> - --max-message-size=<%= node['nsq']['nsqd']['max_message_size'] %> \ - <%- end %> - <%- if Semantic::Version.new(node['nsq']['version']) > Semantic::Version.new('0.2.28') %> - --https-address=<%= node['nsq']['nsqd']['https_address'] %> \ - <%- if !node['nsq']['nsqd']['tls_client_auth_policy'].empty? %> - --tls-client-auth-policy=<%= node['nsq']['nsqd']['tls_client_auth_policy'] %> \ - <%- end %> - <%- if !node['nsq']['nsqd']['tls_root_ca_file'].empty? %> - --tls-root-ca-file=<%= node['nsq']['nsqd']['tls_root_ca_file'] %> - <%- end %> - <% end %> - <%- if Semantic::Version.new(node['nsq']['version']) >= Semantic::Version.new('0.2.29') %> - --max-req-timeout=<%= node['nsq']['nsqd']['max_req_timeout'] %> \ - <%- if !node['nsq']['nsqd']['auth_http_address'].empty? %> - --auth-http-address=<%= node['nsq']['nsqd']['auth_http_address'] %> \ - <%- end %> - <%- end %> - <%- if !node['nsq']['nsqd']['tls_key'].empty? %> - --tls-key=<%= node['nsq']['nsqd']['tls_key'] %> \ - <%- end %> - <%- if !node['nsq']['nsqd']['tls_cert'].empty? %> - --tls-cert=<%= node['nsq']['nsqd']['tls_cert'] %> \ - <%- end %> - --max-body-size=<%= node['nsq']['nsqd']['max_body_size'] %> \ - --max-bytes-per-file=<%= node['nsq']['nsqd']['max_bytes_per_file'] %> \ - --max-msg-timeout=<%= node['nsq']['nsqd']['max_msg_timeout'] %> \ - --max-rdy-count=<%= node['nsq']['nsqd']['max_rdy_count'] %> \ - --mem-queue-size=<%= node['nsq']['nsqd']['mem_queue_size'] %> \ - --msg-timeout=<%= node['nsq']['nsqd']['msg_timeout'] %> \ - --statsd-address=<%= node['nsq']['nsqd']['statsd_address'] %> \ - --statsd-interval=<%= node['nsq']['nsqd']['statsd_interval'] %> \ - --statsd-mem-stats=<%= node['nsq']['nsqd']['statsd_mem_stats'] %> \ - --statsd-prefix=<%= node['nsq']['nsqd']['statsd_prefix'] %> \ - --sync-every=<%= node['nsq']['nsqd']['sync_every'] %> \ - --sync-timeout=<%= node['nsq']['nsqd']['sync_timeout'] %> \ - --tcp-address=<%= node['nsq']['nsqd']['tcp_address'] %> \ - <%- if !node['nsq']['nsqd']['broadcast_address'].empty? %> - --broadcast-address=<%= node['nsq']['nsqd']['broadcast_address'] %> \ - <%- else %> - --broadcast-address=<%= node['ipaddress'] %> \ - <%- end %> - --verbose=<%= node['nsq']['nsqd']['verbose'] %> 2>&1 -end script diff --git a/templates/default/upstart.nsqlookupd.conf.erb b/templates/default/upstart.nsqlookupd.conf.erb deleted file mode 100644 index 0c50ef0..0000000 --- a/templates/default/upstart.nsqlookupd.conf.erb +++ /dev/null @@ -1,26 +0,0 @@ -description "nsqlookupd" - -start on runlevel [2345] -stop on runlevel [!2345] - -env PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin - -respawn - -script - set -e - mkfifo /tmp/nsqlookupd-log-fifo - ( logger -t nsqlookupd /tmp/nsqlookupd-log-fifo - rm /tmp/nsqlookupd-log-fifo - - exec su -s /bin/sh -c 'exec "$0" "$@"' <%= node["nsq"]["nsqlookupd"]["user"] %> -- /usr/local/bin/nsqlookupd \ - --http-address <%= node["nsq"]["nsqlookupd"]["http_address"] %> \ - --inactive-producer-timeout <%= node["nsq"]["nsqlookupd"]["inactive_producer_timeout"] %> \ - --tcp-address <%= node["nsq"]["nsqlookupd"]["tcp_address"] %> \ - <%- if !node['nsq']['nsqlookupd']['broadcast_address'].empty? %> - --broadcast-address <%= node["nsq"]["nsqlookupd"]["broadcast_address"] %> \ - <%- end %> - --tombstone-lifetime <%= node["nsq"]["nsqlookupd"]["tombstone_lifetime"] %> \ - --verbose <%= node["nsq"]["nsqlookupd"]["verbose"] %> 2>&1 -end script