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,28 +39,16 @@ 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"
git do execute "systemctl daemon-reload" 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" command "systemctl daemon-reload"
action :nothing action :nothing
end end
template "/lib/systemd/system/sockethub_nodejs.service" do template "/lib/systemd/system/sockethub_nodejs.service" do
source 'nodejs.systemd.service.erb' source 'nodejs.systemd.service.erb'
owner 'root' owner 'root'
group 'root' group 'root'
@ -68,8 +56,7 @@ application path_to_deploy do
variables( variables(
user: "sockethub", user: "sockethub",
group: "sockethub", group: "sockethub",
app_dir: path_to_deploy, entry: "/usr/bin/sockethub",
entry: "/usr/bin/node /usr/bin/npm start",
environment: { 'DEBUG' => '*', environment: { 'DEBUG' => '*',
'PORT' => node['sockethub']['port'], 'PORT' => node['sockethub']['port'],
# Use the second database (index starts at 0) # Use the second database (index starts at 0)
@ -77,9 +64,8 @@ application path_to_deploy do
) )
notifies :run, "execute[systemctl daemon-reload]", :delayed notifies :run, "execute[systemctl daemon-reload]", :delayed
notifies :restart, "service[sockethub_nodejs]", :delayed notifies :restart, "service[sockethub_nodejs]", :delayed
end end
service "sockethub_nodejs" do service "sockethub_nodejs" do
action [:enable, :start] 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? -%>