72 lines
1.9 KiB
Ruby
72 lines
1.9 KiB
Ruby
#
|
|
# Cookbook:: esh_webhook
|
|
# Recipe:: service
|
|
#
|
|
# Copyright:: 2023, https://easyself.host
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
version = node['esh']['webhook']['service']['version']
|
|
url = "https://github.com/adnanh/webhook/releases/download/#{version}/webhook-linux-amd64.tar.gz"
|
|
|
|
remote_file "webhook.#{version}.tar.gz" do
|
|
source url
|
|
path "#{Chef::Config[:file_cache_path]}/webhook.#{version}.tar.gz"
|
|
notifies :run, 'execute[extract webhook]', :immediately
|
|
end
|
|
|
|
execute 'extract webhook' do
|
|
command <<~EOT
|
|
tar -zxvf \
|
|
#{Chef::Config[:file_cache_path]}/webhook.#{version}.tar.gz \
|
|
-C /usr/local/bin webhook-linux-amd64/webhook \
|
|
--strip-components=1
|
|
EOT
|
|
action :nothing
|
|
end
|
|
|
|
cookbook_file '/usr/local/bin/webhook.sh' do
|
|
owner 'root'
|
|
group 'root'
|
|
mode '0755'
|
|
action :create
|
|
end
|
|
|
|
template '/etc/webhook/hooks.json' do
|
|
owner 'webhook'
|
|
group 'webhook'
|
|
mode '0400'
|
|
variables secret: node['esh']['webhook']['service']['hook_secret']
|
|
action :create
|
|
end
|
|
|
|
systemd_unit 'webhook.service' do
|
|
content <<~EOU
|
|
[Unit]
|
|
Description=Webhook service
|
|
|
|
[Service]
|
|
User=webhook
|
|
Group=webhook
|
|
ExecStart=/usr/local/bin/webhook -hooks /etc/webhook/hooks.json -debug
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOU
|
|
action :create
|
|
end
|
|
|
|
service 'webhook' do
|
|
action [:enable, :start]
|
|
subscribes :restart, 'template[/etc/webhook/hooks.json]', :delayed
|
|
end
|