From 29a5947d18ba3b84d8573de854bd840f538f3909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Wed, 25 Mar 2020 12:43:39 +0100 Subject: [PATCH] Deploy Sockethub from the npm package This is currently 3.1.4 and is set as an attribute. The recipe is very simple now, it installs the npm package, and the systemd service runs /usr/bin/sockethub and sets the environment variables Closes #145 --- .../sockethub/attributes/default.rb | 2 +- site-cookbooks/sockethub/metadata.rb | 3 +- site-cookbooks/sockethub/recipes/default.rb | 72 ++++++++----------- .../default/nginx_conf_sockethub.erb | 8 ++- .../default/nodejs.systemd.service.erb | 1 - 5 files changed, 37 insertions(+), 49 deletions(-) diff --git a/site-cookbooks/sockethub/attributes/default.rb b/site-cookbooks/sockethub/attributes/default.rb index 7935b9b..c3a9599 100644 --- a/site-cookbooks/sockethub/attributes/default.rb +++ b/site-cookbooks/sockethub/attributes/default.rb @@ -1,4 +1,4 @@ node.default['sockethub']['port'] = '10551' node.default['sockethub']['external_port'] = '10550' -node.default['sockethub']['revision'] = 'v3.0.1' +node.default['sockethub']['version'] = '3.1.4' node.default['sockethub']['nginx']['server_name'] = 'sockethub.kosmos.org' diff --git a/site-cookbooks/sockethub/metadata.rb b/site-cookbooks/sockethub/metadata.rb index 0c5347b..db2d286 100644 --- a/site-cookbooks/sockethub/metadata.rb +++ b/site-cookbooks/sockethub/metadata.rb @@ -4,9 +4,8 @@ maintainer_email 'mail@kosmos.org' license 'MIT' description 'Installs/Configures sockethub' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '0.1.1' +version '0.2.0' -depends 'application_javascript' depends 'kosmos-redis' depends 'kosmos-nodejs' depends 'kosmos-nginx' diff --git a/site-cookbooks/sockethub/recipes/default.rb b/site-cookbooks/sockethub/recipes/default.rb index df30690..156ada0 100644 --- a/site-cookbooks/sockethub/recipes/default.rb +++ b/site-cookbooks/sockethub/recipes/default.rb @@ -39,47 +39,33 @@ user "sockethub" do shell "/bin/bash" end -path_to_deploy = "/opt/sockethub" -application path_to_deploy do - owner "sockethub" - group "sockethub" - - git do - user "sockethub" - group "sockethub" - repository 'https://github.com/sockethub/sockethub.git' - revision node['sockethub']['revision'] - end - - npm_install do - user "sockethub" - end - - execute "systemctl daemon-reload" do - command "systemctl daemon-reload" - action :nothing - end - - template "/lib/systemd/system/sockethub_nodejs.service" do - source 'nodejs.systemd.service.erb' - owner 'root' - group 'root' - mode '0644' - variables( - user: "sockethub", - group: "sockethub", - app_dir: path_to_deploy, - entry: "/usr/bin/node /usr/bin/npm start", - environment: { 'DEBUG' => '*', - 'PORT' => node['sockethub']['port'], - # Use the second database (index starts at 0) - 'REDIS_URL' => "redis://localhost:6379/1" } - ) - notifies :run, "execute[systemctl daemon-reload]", :delayed - notifies :restart, "service[sockethub_nodejs]", :delayed - end - - service "sockethub_nodejs" do - action [:enable, :start] - end +npm_package "sockethub" do + version node['sockethub']['version'] +end + +execute "systemctl daemon-reload" do + command "systemctl daemon-reload" + action :nothing +end + +template "/lib/systemd/system/sockethub_nodejs.service" do + source 'nodejs.systemd.service.erb' + owner 'root' + group 'root' + mode '0644' + variables( + user: "sockethub", + group: "sockethub", + entry: "/usr/bin/sockethub", + environment: { 'DEBUG' => '*', + 'PORT' => node['sockethub']['port'], + # Use the second database (index starts at 0) + 'REDIS_URL' => "redis://localhost:6379/1" } + ) + notifies :run, "execute[systemctl daemon-reload]", :delayed + notifies :restart, "service[sockethub_nodejs]", :delayed +end + +service "sockethub_nodejs" do + action [:enable, :start] end diff --git a/site-cookbooks/sockethub/templates/default/nginx_conf_sockethub.erb b/site-cookbooks/sockethub/templates/default/nginx_conf_sockethub.erb index 4ed2689..a25bd84 100644 --- a/site-cookbooks/sockethub/templates/default/nginx_conf_sockethub.erb +++ b/site-cookbooks/sockethub/templates/default/nginx_conf_sockethub.erb @@ -8,10 +8,13 @@ map $http_upgrade $connection_upgrade { '' close; } -<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%> server { + <% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%> listen <%= @sockethub_external_port %> ssl http2; add_header Strict-Transport-Security "max-age=15768000"; + <% else -%> + listen <%= @sockethub_external_port %>; + <% end -%> server_name <%= @server_name %>; @@ -32,7 +35,8 @@ server { proxy_set_header Connection $connection_upgrade; } + <% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%> ssl_certificate <%= @ssl_cert %>; ssl_certificate_key <%= @ssl_key %>; + <% end -%> } -<% end -%> diff --git a/site-cookbooks/sockethub/templates/default/nodejs.systemd.service.erb b/site-cookbooks/sockethub/templates/default/nodejs.systemd.service.erb index 8dc98a9..2c42623 100644 --- a/site-cookbooks/sockethub/templates/default/nodejs.systemd.service.erb +++ b/site-cookbooks/sockethub/templates/default/nodejs.systemd.service.erb @@ -5,7 +5,6 @@ After=redis-server.service [Service] ExecStart=<%= @entry %> -WorkingDirectory=<%= @app_dir %> User=<%= @user %> Group=<%= @group %> <% unless @environment.empty? -%>