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/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/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/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.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