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
This commit is contained in:
Greg Karékinian 2020-03-25 12:43:39 +01:00
parent a3b95463fa
commit 29a5947d18
5 changed files with 37 additions and 49 deletions

View File

@ -1,4 +1,4 @@
node.default['sockethub']['port'] = '10551' node.default['sockethub']['port'] = '10551'
node.default['sockethub']['external_port'] = '10550' 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' node.default['sockethub']['nginx']['server_name'] = 'sockethub.kosmos.org'

View File

@ -4,9 +4,8 @@ maintainer_email 'mail@kosmos.org'
license 'MIT' license 'MIT'
description 'Installs/Configures sockethub' description 'Installs/Configures sockethub'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 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-redis'
depends 'kosmos-nodejs' depends 'kosmos-nodejs'
depends 'kosmos-nginx' depends 'kosmos-nginx'

View File

@ -39,47 +39,33 @@ user "sockethub" do
shell "/bin/bash" shell "/bin/bash"
end end
path_to_deploy = "/opt/sockethub" npm_package "sockethub" do
application path_to_deploy do version node['sockethub']['version']
owner "sockethub" end
group "sockethub"
execute "systemctl daemon-reload" do
git do command "systemctl daemon-reload"
user "sockethub" action :nothing
group "sockethub" end
repository 'https://github.com/sockethub/sockethub.git'
revision node['sockethub']['revision'] template "/lib/systemd/system/sockethub_nodejs.service" do
end source 'nodejs.systemd.service.erb'
owner 'root'
npm_install do group 'root'
user "sockethub" mode '0644'
end variables(
user: "sockethub",
execute "systemctl daemon-reload" do group: "sockethub",
command "systemctl daemon-reload" entry: "/usr/bin/sockethub",
action :nothing environment: { 'DEBUG' => '*',
end 'PORT' => node['sockethub']['port'],
# Use the second database (index starts at 0)
template "/lib/systemd/system/sockethub_nodejs.service" do 'REDIS_URL' => "redis://localhost:6379/1" }
source 'nodejs.systemd.service.erb' )
owner 'root' notifies :run, "execute[systemctl daemon-reload]", :delayed
group 'root' notifies :restart, "service[sockethub_nodejs]", :delayed
mode '0644' end
variables(
user: "sockethub", service "sockethub_nodejs" do
group: "sockethub", action [:enable, :start]
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
end end

View File

@ -8,10 +8,13 @@ map $http_upgrade $connection_upgrade {
'' close; '' close;
} }
<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%>
server { server {
<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%>
listen <%= @sockethub_external_port %> ssl http2; listen <%= @sockethub_external_port %> ssl http2;
add_header Strict-Transport-Security "max-age=15768000"; add_header Strict-Transport-Security "max-age=15768000";
<% else -%>
listen <%= @sockethub_external_port %>;
<% end -%>
server_name <%= @server_name %>; server_name <%= @server_name %>;
@ -32,7 +35,8 @@ server {
proxy_set_header Connection $connection_upgrade; proxy_set_header Connection $connection_upgrade;
} }
<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%>
ssl_certificate <%= @ssl_cert %>; ssl_certificate <%= @ssl_cert %>;
ssl_certificate_key <%= @ssl_key %>; ssl_certificate_key <%= @ssl_key %>;
<% end -%>
} }
<% end -%>

View File

@ -5,7 +5,6 @@ After=redis-server.service
[Service] [Service]
ExecStart=<%= @entry %> ExecStart=<%= @entry %>
WorkingDirectory=<%= @app_dir %>
User=<%= @user %> User=<%= @user %>
Group=<%= @group %> Group=<%= @group %>
<% unless @environment.empty? -%> <% unless @environment.empty? -%>