Switch to a systemd unit Chef resource

This commit is contained in:
Greg 2021-07-09 11:32:33 +02:00
parent e9c86081f7
commit d135b3873c
2 changed files with 26 additions and 34 deletions

View File

@ -27,11 +27,15 @@
include_recipe 'kosmos-nodejs'
include_recipe 'kosmos-redis'
group "sockethub" do
user = "sockethub"
group = "sockethub"
entry = "/usr/bin/sockethub"
group group do
gid 7625
end
user "sockethub" do
user user do
comment "sockethub user"
uid 7625
gid 7625
@ -57,21 +61,25 @@ unless node['sockethub']['debug_logs'].nil?
environment_variables['DEBUG'] = node['sockethub']['debug_logs']
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: environment_variables
)
notifies :run, "execute[systemctl daemon-reload]", :delayed
notifies :restart, "service[sockethub_nodejs]", :delayed
end
environment = environment_variables.map{|k, v| "'#{k}=#{v}'"}.join(' ')
service "sockethub_nodejs" do
action [:enable, :start]
systemd_unit "sockethub_nodejs.service" do
content <<-EOF
[Unit]
Description=Start sockethub
Requires=redis-server.service
After=redis-server.service
[Service]
ExecStart=#{entry}
User=#{user}
Group=#{group}
Environment=#{environment}
Restart=always
[Install]
WantedBy=multi-user.target
EOF
triggers_reload true
action [:create, :enable, :start]
end

View File

@ -1,16 +0,0 @@
[Unit]
Description=Start nodejs app
Requires=redis-server.service
After=redis-server.service
[Service]
ExecStart=<%= @entry %>
User=<%= @user %>
Group=<%= @group %>
<% unless @environment.empty? -%>
Environment=<% @environment.each do |key, value| -%>'<%= key %>=<%= value %>' <% end %>
<% end -%>
Restart=always
[Install]
WantedBy=multi-user.target