Skip to content
Permalink
Fetching contributors…
Cannot retrieve contributors at this time
161 lines (145 sloc) 4.25 KB
#
# Cookbook:: echoserver
# Recipe:: default
#
# based very heavily on https://gist.github.com/sethvargo/6f1a315094fbd1a18c6d
# Install the unzip package because Consul and Consul Template are
# published as ZIP files.
package "unzip"
# Download the latest version of Consul Template using the remote_file
# resource in Chef and trigger an extraction.
remote_file "/tmp/consul-template.zip" do
# I wish there was a better mechanism for this
source "https://releases.hashicorp.com/consul-template/0.19.4/consul-template_0.19.4_linux_amd64.zip"
owner "root"
group "root"
mode "0755"
backup false
action :create_if_missing
notifies :run, "execute[extract_consul_template]", :immediately
end
# Unzips the binary.
execute "extract_consul_template" do
command <<-EOH
unzip /tmp/consul-template.zip
mv consul-template /usr/local/bin/consul-template
chmod +x /usr/local/bin/consul-template
EOH
action :nothing
end
# Create the configuration directory where the template configurations
# will reside.
directory "/etc/consul-template.d" do
owner "root"
group "root"
action :create
end
# Create directory for echoserver config
directory "/opt/echoserver/config" do
owner "root"
group "root"
recursive true
action :create
end
# Create systemd service unit file for echoserver
systemd_unit 'echoserver.service' do
content <<-EOU.gsub(/^\s+/, '')
[Unit]
Description=echoserver-service
Requires=network.target
After=network.target
[Service]
EnvironmentFile=-/etc/sysconfig/echoserver
Restart=on-failure
ExecStart=/usr/local/bin/echoserver
ExecStop=/bin/kill -TERM $MAINPID
KillSignal=SIGINT
Restart=always
[Install]
WantedBy=multi-user.target
EOU
verify false
action [:create, :enable]
end
# Create systemd service unit file for consul-template
systemd_unit 'consul-template.service' do
content <<-EOU.gsub(/^\s+/, '')
[Unit]
Description=consul-template
Requires=network.target
After=network.target
[Service]
EnvironmentFile=-/etc/sysconfig/consul-template
Restart=on-failure
ExecStart=/usr/local/bin/consul-template $OPTIONS -config=/etc/consul-template.d
ExecStop=/bin/kill -TERM $MAINPID
KillSignal=SIGINT
Restart=always
[Install]
WantedBy=multi-user.target
EOU
verify false
action [:create, :enable]
end
# register, enable, start services
service 'echoserver' do
provider Chef::Provider::Service::Systemd
action [ :enable, :start ]
retries 3
end
service 'consul-template' do
provider Chef::Provider::Service::Systemd
action [ :enable, :start ]
retries 3
end
# This writes the Consul Template template that Consul Template will
# read, parse, communicate with Vault, and render as the application
# configuration. Since Consul Template is running as a process, it
# will read all files in /etc/consul-template.d as configured in the
# upstart script above.
template "/etc/consul-template.d/echoserver.hcl" do
source "echoserver.erb"
owner "root"
group "root"
mode "0644"
notifies :reload, "service[consul-template]", :delayed
end
# This is the actual consul-template, used by consul-template as specified in
# /etc/consul-template.d/echoserver.hcl. Consul-template renders the
# application config based on the contents of this template.
template "/opt/echoserver/config.ctmpl" do
source "config.ctmpl"
owner "root"
group "root"
mode "0644"
end
# This template is used for configuring the connection to vault.
# There are other ways to do it; you could put it all in the OPTIONS
# variable in /etc/sysconfig/consul-template.
template "/etc/consul-template.d/config.hcl" do
source "config.erb"
owner "root"
group "root"
mode "0644"
notifies :reload, "service[consul-template]", :delayed
end
# place the echoserver application
cookbook_file "/usr/local/bin/echoserver" do
source "default/echoserver"
owner "root"
group "root"
mode "0750"
action :create
end
# add epel for python 3.4 :/
include_recipe "echoserver::repos"
# add required packages from yum
[ "python34", "python34-sqlalchemy", "python34-mysql", "python34-pip" ].each do |pkg|
package pkg do
action :upgrade
end
end
# and one from pip
execute 'pip install pymysql' do
command 'pip3 install -U pymysql'
end
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.