From 255e43c680172f8b406d2755e679cff04695817b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Thu, 22 Oct 2020 15:07:16 +0200 Subject: [PATCH] Fix the Systemd unit for discourse Switch the systemd unit to a oneshot type --- .../kosmos_discourse/recipes/default.rb | 31 +++++++++++-------- .../templates/discourse.service.erb | 23 -------------- 2 files changed, 18 insertions(+), 36 deletions(-) delete mode 100644 site-cookbooks/kosmos_discourse/templates/discourse.service.erb diff --git a/site-cookbooks/kosmos_discourse/recipes/default.rb b/site-cookbooks/kosmos_discourse/recipes/default.rb index a2ed224..5e65960 100644 --- a/site-cookbooks/kosmos_discourse/recipes/default.rb +++ b/site-cookbooks/kosmos_discourse/recipes/default.rb @@ -35,19 +35,24 @@ git deploy_path do revision "master" end -# FIXME: The systemd unit does not work -template "/etc/systemd/system/discourse.service" do - source "discourse.service.erb" - variables deploy_path: deploy_path - notifies :run, "execute[systemctl daemon-reload]", :immediately -end - -execute "systemctl daemon-reload" do - action :nothing -end - -service "discourse" do - action [:enable] +systemd_unit "discourse.service" do + content({Unit: { + Description: "discourse service with docker compose", + Requires: "docker.service", + After: "docker.service", + }, + Service: { + Type: "oneshot", + RemainAfterExit: "true", + WorkingDirectory: deploy_path, + Environment: "SUPERVISED=true", + ExecStart: "#{deploy_path}/launcher start app", + ExecStop: "#{deploy_path}/launcher stop app", + }, + Install: { + WantedBy: "multi-user.target" + }}) + action [:create, :enable] end template "#{node['nginx']['dir']}/sites-available/#{domain}" do diff --git a/site-cookbooks/kosmos_discourse/templates/discourse.service.erb b/site-cookbooks/kosmos_discourse/templates/discourse.service.erb deleted file mode 100644 index f85253d..0000000 --- a/site-cookbooks/kosmos_discourse/templates/discourse.service.erb +++ /dev/null @@ -1,23 +0,0 @@ -[Unit] -Description=discourse service with docker compose -Requires=docker.service -After=docker.service - -[Service] -Restart=always - -WorkingDirectory=<%= @deploy_path %> - -Environment="SUPERVISED=true" - -ExecStartPre=<%= @deploy_path %>/launcher stop app -# Remove all containers that have stopped for > 24 hours -ExecStartPre=<%= @deploy_path %>/launcher cleanup - -ExecStart=<%= @deploy_path %>/launcher start app - -ExecStop=<%= @deploy_path %>/launcher stop app - -[Install] -WantedBy=multi-user.target -