From e6ec32f343a53ecd5536b2580297b64873a2fe3c Mon Sep 17 00:00:00 2001 From: Will Jordan Date: Thu, 21 Nov 2019 16:03:58 -0800 Subject: [PATCH] Install/configure new CloudWatch agent Use new agent for collecting CloudWatch metrics and logs. --- .../cloud_formation_stack.yml.erb | 3 +- cookbooks/.kitchen.ec2.yml | 5 +- cookbooks/Berksfile.lock | 25 +++-- cookbooks/cdo-apps/metadata.rb | 4 +- cookbooks/cdo-apps/recipes/default.rb | 4 +- .../.kitchen.yml | 20 ++-- .../Berksfile | 0 cookbooks/cdo-cloudwatch-agent/README.md | 5 + .../attributes/default.rb | 6 ++ cookbooks/cdo-cloudwatch-agent/metadata.rb | 9 ++ .../cdo-cloudwatch-agent/recipes/default.rb | 9 ++ .../default/amazon-cloudwatch-agent.json.erb | 81 ++++++++++++++++ .../integration/default/inspec/ruby_spec.rb | 11 +++ .../cdo-cloudwatch-extra-metrics/README.md | 6 -- .../cdo-cloudwatch-extra-metrics/metadata.rb | 9 -- .../recipes/default.rb | 10 -- .../default/serverspec/ruby_spec.rb | 12 --- cookbooks/cdo-cloudwatch-logger/README.md | 6 -- .../attributes/default.rb | 2 - .../cdo-cloudwatch-logger/recipes/default.rb | 95 ------------------- cookbooks/cdo-mysql/attributes/default.rb | 3 +- cookbooks/cdo-mysql/metadata.rb | 2 +- cookbooks/cdo-mysql/recipes/proxy.rb | 3 + .../.kitchen.yml | 5 +- .../Berksfile | 0 cookbooks/cdo-syslog/README.md | 4 + cookbooks/cdo-syslog/attributes/default.rb | 1 + .../metadata.rb | 8 +- cookbooks/cdo-syslog/recipes/default.rb | 47 +++++++++ .../integration/default/inspec/test_spec.rb | 10 -- 30 files changed, 217 insertions(+), 188 deletions(-) rename cookbooks/{cdo-cloudwatch-extra-metrics => cdo-cloudwatch-agent}/.kitchen.yml (59%) rename cookbooks/{cdo-cloudwatch-extra-metrics => cdo-cloudwatch-agent}/Berksfile (100%) create mode 100644 cookbooks/cdo-cloudwatch-agent/README.md create mode 100644 cookbooks/cdo-cloudwatch-agent/attributes/default.rb create mode 100644 cookbooks/cdo-cloudwatch-agent/metadata.rb create mode 100644 cookbooks/cdo-cloudwatch-agent/recipes/default.rb create mode 100644 cookbooks/cdo-cloudwatch-agent/templates/default/amazon-cloudwatch-agent.json.erb create mode 100644 cookbooks/cdo-cloudwatch-agent/test/integration/default/inspec/ruby_spec.rb delete mode 100644 cookbooks/cdo-cloudwatch-extra-metrics/README.md delete mode 100644 cookbooks/cdo-cloudwatch-extra-metrics/metadata.rb delete mode 100644 cookbooks/cdo-cloudwatch-extra-metrics/recipes/default.rb delete mode 100644 cookbooks/cdo-cloudwatch-extra-metrics/test/integration/default/serverspec/ruby_spec.rb delete mode 100644 cookbooks/cdo-cloudwatch-logger/README.md delete mode 100644 cookbooks/cdo-cloudwatch-logger/attributes/default.rb delete mode 100644 cookbooks/cdo-cloudwatch-logger/recipes/default.rb rename cookbooks/{cdo-cloudwatch-logger => cdo-syslog}/.kitchen.yml (82%) rename cookbooks/{cdo-cloudwatch-logger => cdo-syslog}/Berksfile (100%) create mode 100644 cookbooks/cdo-syslog/README.md create mode 100644 cookbooks/cdo-syslog/attributes/default.rb rename cookbooks/{cdo-cloudwatch-logger => cdo-syslog}/metadata.rb (52%) create mode 100644 cookbooks/cdo-syslog/recipes/default.rb rename cookbooks/{cdo-cloudwatch-logger => cdo-syslog}/test/integration/default/inspec/test_spec.rb (62%) diff --git a/aws/cloudformation/cloud_formation_stack.yml.erb b/aws/cloudformation/cloud_formation_stack.yml.erb index 62ec63e2e8e7e..5832dec208f48 100644 --- a/aws/cloudformation/cloud_formation_stack.yml.erb +++ b/aws/cloudformation/cloud_formation_stack.yml.erb @@ -108,8 +108,7 @@ Resources: - 'logs:PutRetentionPolicy' - 'logs:PutLogEvents' Resource: - - !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:<%=environment%>-syslog" - - !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:<%=environment%>-syslog:log-stream:*" + - !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:<%=environment%>-*" - !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${AWS::StackName}" - !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${AWS::StackName}:log-stream:*" # Put custom metrics to CloudWatch. diff --git a/cookbooks/.kitchen.ec2.yml b/cookbooks/.kitchen.ec2.yml index 2f76fd4e95ca5..580093229c4d3 100644 --- a/cookbooks/.kitchen.ec2.yml +++ b/cookbooks/.kitchen.ec2.yml @@ -11,11 +11,11 @@ driver: instance_type: m5.4xlarge <% if ENV['SUBNET_ID'] %> subnet_id: <%= ENV['SUBNET_ID'] %> + associate_public_ip: true <% end %> <% if ENV['IMAGE_ID'] %> image_id: <%= ENV['IMAGE_ID']%> <% end %> - associate_public_ip: true block_device_mappings: - device_name: /dev/sda1 ebs: @@ -29,3 +29,6 @@ driver: iam_profile_name: <%=ENV['IAM_PROFILE_NAME']%> provisioner: name: chef_zero + environments_path: ../cdo-apps/test/environments + client_rb: + environment: adhoc diff --git a/cookbooks/Berksfile.lock b/cookbooks/Berksfile.lock index 54e6acffea9b6..8c97c377affb6 100644 --- a/cookbooks/Berksfile.lock +++ b/cookbooks/Berksfile.lock @@ -10,10 +10,8 @@ DEPENDENCIES path: cdo-authorized-keys cdo-awscli path: cdo-awscli - cdo-cloudwatch-extra-metrics - path: cdo-cloudwatch-extra-metrics - cdo-cloudwatch-logger - path: cdo-cloudwatch-logger + cdo-cloudwatch-agent + path: cdo-cloudwatch-agent cdo-github-access path: cdo-github-access cdo-home-ubuntu @@ -40,6 +38,8 @@ DEPENDENCIES path: cdo-ruby cdo-secrets path: cdo-secrets + cdo-syslog + path: cdo-syslog cdo-tippecanoe path: cdo-tippecanoe cdo-users @@ -58,6 +58,7 @@ GRAPH ark (4.0.0) build-essential (>= 0.0.0) seven_zip (>= 0.0.0) + aws_cloudwatch (1.0.2) build-essential (8.2.1) mingw (>= 1.1) seven_zip (>= 0.0.0) @@ -68,8 +69,7 @@ GRAPH apt (>= 0.0.0) build-essential (>= 0.0.0) cdo-analytics (>= 0.0.0) - cdo-cloudwatch-extra-metrics (>= 0.0.0) - cdo-cloudwatch-logger (>= 0.0.0) + cdo-cloudwatch-agent (>= 0.0.0) cdo-i18n (>= 0.0.0) cdo-java-7 (>= 0.0.0) cdo-jemalloc (>= 0.0.0) @@ -81,6 +81,7 @@ GRAPH cdo-repository (>= 0.0.0) cdo-ruby (>= 0.0.0) cdo-secrets (>= 0.0.0) + cdo-syslog (>= 0.0.0) cdo-tippecanoe (>= 0.0.0) cdo-varnish (>= 0.0.0) chef_client_updater (>= 0.0.0) @@ -93,12 +94,8 @@ GRAPH apt (~> 2.6.0) poise-python (>= 0.0.0) sudo-user (>= 0.0.0) - cdo-cloudwatch-extra-metrics (0.1.8) - ark (>= 0.0.0) - cdo-cloudwatch-logger (0.1.14) - cdo-awscli (>= 0.0.0) - poise-service (>= 0.0.0) - sudo-user (>= 0.0.0) + cdo-cloudwatch-agent (0.1.1) + aws_cloudwatch (>= 0.0.0) cdo-github-access (0.1.9) cdo-home-ubuntu (0.1.3) cdo-i18n (0.0.0) @@ -108,7 +105,7 @@ GRAPH build-essential (>= 0.0.0) cdo-jemalloc (0.1.4) ark (>= 0.0.0) - cdo-mysql (0.1.25) + cdo-mysql (0.1.27) apt (~> 2.6.0) cdo-nginx (0.0.16) apt (>= 0.0.0) @@ -126,6 +123,8 @@ GRAPH apt (~> 2.6.0) sudo-user (>= 0.0.0) cdo-secrets (0.1.8) + cdo-syslog (0.1.1) + sudo-user (>= 0.0.0) cdo-tippecanoe (0.1.4) ark (>= 0.0.0) cdo-users (0.1.30) diff --git a/cookbooks/cdo-apps/metadata.rb b/cookbooks/cdo-apps/metadata.rb index aba75a533d0c5..a8d88a3483a25 100644 --- a/cookbooks/cdo-apps/metadata.rb +++ b/cookbooks/cdo-apps/metadata.rb @@ -10,7 +10,7 @@ depends 'build-essential' depends 'yarn' -depends 'cdo-cloudwatch-extra-metrics' +depends 'cdo-cloudwatch-agent' depends 'cdo-repository' depends 'cdo-secrets' depends 'cdo-postfix' @@ -27,6 +27,6 @@ depends 'cdo-redis' depends 'cdo-i18n' depends 'cdo-analytics' -depends 'cdo-cloudwatch-logger' +depends 'cdo-syslog' depends 'cdo-jemalloc' depends 'cdo-tippecanoe' diff --git a/cookbooks/cdo-apps/recipes/default.rb b/cookbooks/cdo-apps/recipes/default.rb index e49268cc6ce1b..a09c6db795294 100644 --- a/cookbooks/cdo-apps/recipes/default.rb +++ b/cookbooks/cdo-apps/recipes/default.rb @@ -85,8 +85,8 @@ include_recipe 'cdo-postfix' include_recipe 'cdo-varnish' -include_recipe 'cdo-cloudwatch-extra-metrics' -include_recipe 'cdo-cloudwatch-logger' if node[:ec2] +include_recipe 'cdo-cloudwatch-agent' +include_recipe 'cdo-syslog' include_recipe 'cdo-apps::jemalloc' if node['cdo-apps']['jemalloc'] include_recipe 'cdo-apps::bundle_bootstrap' diff --git a/cookbooks/cdo-cloudwatch-extra-metrics/.kitchen.yml b/cookbooks/cdo-cloudwatch-agent/.kitchen.yml similarity index 59% rename from cookbooks/cdo-cloudwatch-extra-metrics/.kitchen.yml rename to cookbooks/cdo-cloudwatch-agent/.kitchen.yml index b78c982926a30..6c8b14d6d6a08 100644 --- a/cookbooks/cdo-cloudwatch-extra-metrics/.kitchen.yml +++ b/cookbooks/cdo-cloudwatch-agent/.kitchen.yml @@ -1,19 +1,25 @@ # Note: EC2 driver with IAM Instance Profile required to run integration test successfully, e.g.: # IAM_PROFILE_NAME=[IAMProfileName] KITCHEN_LOCAL_YAML=../.kitchen.ec2.yml bundle exec kitchen verify --- -transport: - name: sftp driver: - name: docker - use_sudo: false + name: dokken + chef_version: 15.2.20 + privileged: true +verifier: + name: inspec +transport: + name: dokken provisioner: - name: chef_zero - require_chef_omnibus: 15.2.20 + name: dokken platforms: - name: ubuntu-18.04 + driver: + image: dokken/ubuntu-18.04 run_list: - recipe[apt] suites: - name: default run_list: - - recipe[cdo-cloudwatch-extra-metrics] + - recipe[cdo-cloudwatch-agent] + attributes: + cdo-cloudwatch-agent: diff --git a/cookbooks/cdo-cloudwatch-extra-metrics/Berksfile b/cookbooks/cdo-cloudwatch-agent/Berksfile similarity index 100% rename from cookbooks/cdo-cloudwatch-extra-metrics/Berksfile rename to cookbooks/cdo-cloudwatch-agent/Berksfile diff --git a/cookbooks/cdo-cloudwatch-agent/README.md b/cookbooks/cdo-cloudwatch-agent/README.md new file mode 100644 index 0000000000000..4761c1210c2a6 --- /dev/null +++ b/cookbooks/cdo-cloudwatch-agent/README.md @@ -0,0 +1,5 @@ +cdo-cloudwatch-agent Cookbook +===================================== + +Installs/configures CloudWatch Agent, following setup instructions defined at +https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html diff --git a/cookbooks/cdo-cloudwatch-agent/attributes/default.rb b/cookbooks/cdo-cloudwatch-agent/attributes/default.rb new file mode 100644 index 0000000000000..d771dcbea2266 --- /dev/null +++ b/cookbooks/cdo-cloudwatch-agent/attributes/default.rb @@ -0,0 +1,6 @@ +default['cdo-cloudwatch-agent'] = { + log_files: { + amazon_cloudwatch_agent: '/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log', + syslog: '/var/log/syslog' + } +} diff --git a/cookbooks/cdo-cloudwatch-agent/metadata.rb b/cookbooks/cdo-cloudwatch-agent/metadata.rb new file mode 100644 index 0000000000000..cdb0eebd54aa7 --- /dev/null +++ b/cookbooks/cdo-cloudwatch-agent/metadata.rb @@ -0,0 +1,9 @@ +name 'cdo-cloudwatch-agent' +maintainer 'Code.org' +maintainer_email 'will@code.org' +license 'All rights reserved' +description 'Installs/Configures cdo-cloudwatch-agent' +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +version '0.1.1' + +depends 'aws_cloudwatch' diff --git a/cookbooks/cdo-cloudwatch-agent/recipes/default.rb b/cookbooks/cdo-cloudwatch-agent/recipes/default.rb new file mode 100644 index 0000000000000..e208a5e053ed0 --- /dev/null +++ b/cookbooks/cdo-cloudwatch-agent/recipes/default.rb @@ -0,0 +1,9 @@ +# +# Cookbook Name:: cdo-cloudwatch-agent +# Recipe:: default +# + +aws_cloudwatch_agent 'default' do + action [:install, :configure, :restart] + json_config 'amazon-cloudwatch-agent.json.erb' +end diff --git a/cookbooks/cdo-cloudwatch-agent/templates/default/amazon-cloudwatch-agent.json.erb b/cookbooks/cdo-cloudwatch-agent/templates/default/amazon-cloudwatch-agent.json.erb new file mode 100644 index 0000000000000..fa254adecbb8b --- /dev/null +++ b/cookbooks/cdo-cloudwatch-agent/templates/default/amazon-cloudwatch-agent.json.erb @@ -0,0 +1,81 @@ +{ + "metrics": { + "append_dimensions": { + "AutoScalingGroupName":"${aws:AutoScalingGroupName}", + "InstanceId":"${aws:InstanceId}" + }, + "aggregation_dimensions": [["AutoScalingGroupName"]], + "metrics_collected": { + "statsd": {}, + "cpu": { + "totalcpu": true, + "measurement": [ + "cpu_usage_idle", + "cpu_usage_nice", + "cpu_usage_iowait", + "cpu_usage_system", + "cpu_usage_user" + ], + "metrics_collection_interval": 1, + "append_dimensions": { + "Environment": "<%=node.chef_environment%>" + } + }, + "disk": { + "measurement": [ + "free", + "used_percent" + ], + "ignore_file_system_types": [ + "sysfs", "devtmpfs", "squashfs", "tmpfs" + ], + "append_dimensions": { + "Environment": "<%=node.chef_environment%>" + } + }, + "swap": { + "measurement": [ + "swap_used", + "swap_free" + ], + "append_dimensions": { + "Environment": "<%=node.chef_environment%>" + } + }, + "mem": { + "measurement": [ + "mem_used_percent", + "mem_cached", + "mem_total" + ], + "metrics_collection_interval": 1, + "append_dimensions": { + "Environment": "<%=node.chef_environment%>" + } + }, + "processes": { + "measurement": [ + "processes_running", + "processes_sleeping", + "processes_total", + "processes_dead", + "total_threads" + ], + "append_dimensions": { + "Environment": "<%=node.chef_environment%>" + } + } + }, + "force_flush_interval" : 30 + }, + "logs": { + "logs_collected": { + "files": { + "collect_list": <%= node.default['cdo-cloudwatch-agent']['log_files'].map do |name, path| + {log_group_name: "#{node.chef_environment}-#{name}", file_path: path} + end.to_json %> + } + }, + "force_flush_interval" : 15 + } +} diff --git a/cookbooks/cdo-cloudwatch-agent/test/integration/default/inspec/ruby_spec.rb b/cookbooks/cdo-cloudwatch-agent/test/integration/default/inspec/ruby_spec.rb new file mode 100644 index 0000000000000..85de3ff5b71ac --- /dev/null +++ b/cookbooks/cdo-cloudwatch-agent/test/integration/default/inspec/ruby_spec.rb @@ -0,0 +1,11 @@ +require 'serverspec' +set :backend, :exec + +def cmd(exec, match) + describe command(exec) do + its(:stdout) {should match match} + end +end + +# Ensure proper version of agent is installed. +cmd '/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent --version', 'AmazonCloudWatchAgent v1.231221.0' diff --git a/cookbooks/cdo-cloudwatch-extra-metrics/README.md b/cookbooks/cdo-cloudwatch-extra-metrics/README.md deleted file mode 100644 index 5ffc7a5c00999..0000000000000 --- a/cookbooks/cdo-cloudwatch-extra-metrics/README.md +++ /dev/null @@ -1,6 +0,0 @@ -cdo-cloudwatch-extra-metrics Cookbook -===================================== - -Adds memory and disc usage metrics to cloudwatch, following setup -instructions defined at -http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/mon-scripts.html diff --git a/cookbooks/cdo-cloudwatch-extra-metrics/metadata.rb b/cookbooks/cdo-cloudwatch-extra-metrics/metadata.rb deleted file mode 100644 index 0b967902d9d81..0000000000000 --- a/cookbooks/cdo-cloudwatch-extra-metrics/metadata.rb +++ /dev/null @@ -1,9 +0,0 @@ -name 'cdo-cloudwatch-extra-metrics' -maintainer 'Code.org' -maintainer_email 'elijah@code.org' -license 'All rights reserved' -description 'Installs/Configures cdo-cloudwatch-extra-metrics' -long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '0.1.8' - -depends 'ark' diff --git a/cookbooks/cdo-cloudwatch-extra-metrics/recipes/default.rb b/cookbooks/cdo-cloudwatch-extra-metrics/recipes/default.rb deleted file mode 100644 index bf5507e058991..0000000000000 --- a/cookbooks/cdo-cloudwatch-extra-metrics/recipes/default.rb +++ /dev/null @@ -1,10 +0,0 @@ -# -# Cookbook Name:: cdo-cloudwatch-extra-metrics -# Recipe:: default -# - -apt_package ['unzip', 'libwww-perl', 'libdatetime-perl', 'rsync'] - -ark 'aws-scripts-mon' do - url 'http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip' -end diff --git a/cookbooks/cdo-cloudwatch-extra-metrics/test/integration/default/serverspec/ruby_spec.rb b/cookbooks/cdo-cloudwatch-extra-metrics/test/integration/default/serverspec/ruby_spec.rb deleted file mode 100644 index 5254b804c7fdc..0000000000000 --- a/cookbooks/cdo-cloudwatch-extra-metrics/test/integration/default/serverspec/ruby_spec.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'serverspec' -set :backend, :exec - -def cmd(exec, match) - describe command(exec) do - its(:stdout) {should match match} - end -end - -# Ensure proper version of script is installed. -cmd '/usr/local/aws-scripts-mon/mon-put-instance-data.pl --version', 'CloudWatch-PutInstanceData version 1.2.1' -cmd '/usr/local/aws-scripts-mon/mon-put-instance-data.pl --mem-util --disk-space-util --disk-path=/ --verify', 'Verification completed successfully' diff --git a/cookbooks/cdo-cloudwatch-logger/README.md b/cookbooks/cdo-cloudwatch-logger/README.md deleted file mode 100644 index 82fe1bc76b267..0000000000000 --- a/cookbooks/cdo-cloudwatch-logger/README.md +++ /dev/null @@ -1,6 +0,0 @@ -cdo-cloudwatch-logger Cookbook -===================================== - -Configures rsyslog to pipe all syslog events to CloudWatch Logs. - -Uses [cloudwatch-logger](https://github.com/zendesk/cloudwatch-logger) for CloudWatch Logs integration. diff --git a/cookbooks/cdo-cloudwatch-logger/attributes/default.rb b/cookbooks/cdo-cloudwatch-logger/attributes/default.rb deleted file mode 100644 index e7fccb39e987f..0000000000000 --- a/cookbooks/cdo-cloudwatch-logger/attributes/default.rb +++ /dev/null @@ -1,2 +0,0 @@ -default['cdo-cloudwatch-logger']['dry_run'] = false -default['cdo-cloudwatch-logger']['syslog_size'] = 1024 * 1024 * 128 diff --git a/cookbooks/cdo-cloudwatch-logger/recipes/default.rb b/cookbooks/cdo-cloudwatch-logger/recipes/default.rb deleted file mode 100644 index 942dd23554241..0000000000000 --- a/cookbooks/cdo-cloudwatch-logger/recipes/default.rb +++ /dev/null @@ -1,95 +0,0 @@ -# -# Cookbook Name:: cdo-cloudwatch-logger -# Recipe:: default -# - -# Ensure 'aws logs push' command is available. -include_recipe 'cdo-awscli' - -fifo = '/var/log/cloudwatch' - -execute("mkfifo #{fifo}") {creates fifo} -file(fifo) {owner 'syslog'; action :touch} - -script_path = '/usr/local/bin' -file 'cloudwatch-logger' do - path "#{script_path}/#{name}" - content < 2.6.0' diff --git a/cookbooks/cdo-mysql/recipes/proxy.rb b/cookbooks/cdo-mysql/recipes/proxy.rb index 78be88b55a51f..569efb8423cc7 100644 --- a/cookbooks/cdo-mysql/recipes/proxy.rb +++ b/cookbooks/cdo-mysql/recipes/proxy.rb @@ -26,6 +26,7 @@ def get_cname(domain) end writer = URI.parse(node['cdo-secrets']['db_writer'] || 'mysql2://root@localhost/') +writer.hostname = '127.0.0.1' if writer.hostname == 'localhost' reader = URI.parse((node['cdo-secrets']['db_reader'] || writer).to_s) # If this is an Aurora cluster, resolve instance-endpoint hostnames @@ -105,3 +106,5 @@ def get_cname(domain) node.override['cdo-secrets']['db_writer'] = writer.dup.tap {|r| r.hostname = '127.0.0.1'; r.port = proxy_port}.to_s node.override['cdo-secrets']['db_reader'] = reader.dup.tap {|r| r.hostname = '127.0.0.1'; r.port = proxy_port}.to_s node.override['cdo-secrets']['db_proxy_admin'] = admin.to_s +# Send log to CloudWatch. +node.default['cdo-cloudwatch-agent']['log_files']['proxysql'] = '/var/lib/proxysql/proxysql.log' diff --git a/cookbooks/cdo-cloudwatch-logger/.kitchen.yml b/cookbooks/cdo-syslog/.kitchen.yml similarity index 82% rename from cookbooks/cdo-cloudwatch-logger/.kitchen.yml rename to cookbooks/cdo-syslog/.kitchen.yml index a0ae03e2fc108..9c0dd15f787f7 100644 --- a/cookbooks/cdo-cloudwatch-logger/.kitchen.yml +++ b/cookbooks/cdo-syslog/.kitchen.yml @@ -18,10 +18,9 @@ platforms: - recipe[apt] - recipe[sudo-user] attributes: - cdo-cloudwatch-logger: - dry_run: true + cdo-syslog: syslog_size: 256 suites: - name: default run_list: - - recipe[cdo-cloudwatch-logger] + - recipe[cdo-syslog] diff --git a/cookbooks/cdo-cloudwatch-logger/Berksfile b/cookbooks/cdo-syslog/Berksfile similarity index 100% rename from cookbooks/cdo-cloudwatch-logger/Berksfile rename to cookbooks/cdo-syslog/Berksfile diff --git a/cookbooks/cdo-syslog/README.md b/cookbooks/cdo-syslog/README.md new file mode 100644 index 0000000000000..3daced6810d72 --- /dev/null +++ b/cookbooks/cdo-syslog/README.md @@ -0,0 +1,4 @@ +cdo-syslog Cookbook +===================================== + +Configures rsyslog to write syslog to a fixed-length file. diff --git a/cookbooks/cdo-syslog/attributes/default.rb b/cookbooks/cdo-syslog/attributes/default.rb new file mode 100644 index 0000000000000..f1aafdd7539b2 --- /dev/null +++ b/cookbooks/cdo-syslog/attributes/default.rb @@ -0,0 +1 @@ +default['cdo-syslog']['syslog_size'] = 1024 * 1024 * 128 diff --git a/cookbooks/cdo-cloudwatch-logger/metadata.rb b/cookbooks/cdo-syslog/metadata.rb similarity index 52% rename from cookbooks/cdo-cloudwatch-logger/metadata.rb rename to cookbooks/cdo-syslog/metadata.rb index 98b3ec026b0e5..9556046fe5ca1 100644 --- a/cookbooks/cdo-cloudwatch-logger/metadata.rb +++ b/cookbooks/cdo-syslog/metadata.rb @@ -1,11 +1,9 @@ -name 'cdo-cloudwatch-logger' +name 'cdo-syslog' maintainer 'Code.org' maintainer_email 'will@code.org' license 'All rights reserved' -description 'Installs/Configures cdo-cloudwatch-logger' +description 'Installs/Configures syslog' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '0.1.14' +version '0.1.1' -depends 'poise-service' -depends 'cdo-awscli' depends 'sudo-user' diff --git a/cookbooks/cdo-syslog/recipes/default.rb b/cookbooks/cdo-syslog/recipes/default.rb new file mode 100644 index 0000000000000..dac67d4f89d60 --- /dev/null +++ b/cookbooks/cdo-syslog/recipes/default.rb @@ -0,0 +1,47 @@ +# +# Cookbook Name:: cdo-syslog +# Recipe:: default +# + +include_recipe 'apt' +apt_repository 'rsyslog' do + uri 'ppa:adiscon/v8-stable' + distribution node['lsb']['codename'] + retries 3 +end +apt_package %w(rsyslog) do + action :upgrade +end + +syslog_file = '/var/log/syslog' +syslog_size = node['cdo-syslog']['syslog_size'] + +script_path = '/usr/local/bin' +file 'rotate_syslog' do + path "#{script_path}/#{name}" + content <