itamae/cookbooks/loki/setup.rb

101 lines
1.8 KiB
Ruby
Raw Normal View History

2020-10-12 14:20:52 +00:00
# Create `/etc/loki/`:
%w(/etc/loki).each do |d|
directory d do
owner 'root'
group 'root'
mode '0755'
end
end
# Deploy `prometheus` files:
2024-04-27 05:26:19 +00:00
remote_file '/etc/loki/loki-config.yml' do
2020-10-12 14:20:52 +00:00
owner 'root'
group 'root'
mode '644'
2020-10-17 05:41:02 +00:00
notifies :restart, 'service[loki]'
2020-10-12 14:20:52 +00:00
end
# Deploy `systemd` configuration for `prometheus`:
remote_file '/etc/systemd/system/loki.service' do
owner 'root'
group 'root'
mode '644'
end
# Service setting:
service 'loki' do
action [ :enable, :restart ]
end
# Depoy `consul` service configuration for `loki`:
2020-10-17 05:41:02 +00:00
template '/etc/consul.d/service-loki.json' do
owner 'consul'
group 'consul'
2020-10-12 14:20:52 +00:00
mode '644'
2024-04-03 05:40:40 +00:00
variables(ipaddr: node['loki']['ipaddr'])
2020-10-17 05:41:02 +00:00
notifies :reload, 'service[consul]'
end
service 'consul' do
action :nothing
2020-10-12 14:20:52 +00:00
end
remote_file '/etc/rsyslog.d/30-loki.conf' do
owner 'root'
group 'root'
mode '644'
notifies :restart, 'service[rsyslog]'
end
service 'rsyslog' do
action [ :nothing ]
end
# Deploy the `logrotated` configuration:
remote_file '/etc/logrotate.d/loki' do
owner 'root'
group 'root'
mode '644'
end
2024-04-03 05:32:39 +00:00
# Deploy the config file for `vector`:
remote_file '/etc/vector/loki.toml' do
owner 'root'
group 'root'
mode '644'
end
# Deploy the `systemd` configuration:
remote_file '/lib/systemd/system/vector-loki.service' do
owner 'root'
group 'root'
mode '644'
end
# Service setting:
service 'vector-loki' do
action [ :enable, :restart ]
end
2020-10-12 14:20:52 +00:00
# Firewall settings here:
%w( 3100/tcp ).each do |p|
execute "ufw allow #{p}" do
user 'root'
not_if "LANG=c ufw status | grep #{p}"
notifies :run, 'execute[ufw reload-or-enable]'
end
end
execute 'ufw reload-or-enable' do
user 'root'
command 'LANG=C ufw reload | grep skipping && ufw --force enable || exit 0'
action :nothing
end