Dev set up

This commit is contained in:
2019-07-01 10:15:24 -04:00
parent da1a3d5491
commit 23a4e98668
340 changed files with 23143 additions and 41 deletions

View File

@ -0,0 +1,246 @@
# memcached Cookbook CHANGELOG
This file is used to list changes made in each version of the memcached cookbook.
## 5.1.1 (2018-07-24)
- Fix logging directory default to be /var/log/memcached not /var/log/
- Remove ChefSpec matchers since these are autogenerated by Chefspec now
## 5.1.0 (2018-01-30)
- Add 'binary-path' property to the resource
- Add 'no-restart' property to the resource
## 5.0.2 (2018-01-17)
- Use binary_path helper throughout code for consistency
## 5.0.1 (2018-01-10)
- Fix ulimit for runit based services
- Use Systemd User directive which is more secure
- Fix experimental_options to be properly spaced
## 5.0.0 (2017-09-06)
### Breaking changes
- Support for RHEL 5 has been removed. This removes the cookbook dependency on yum-epel as well
- Runit support has been marked as deprecated and will be removed in a future release of this cookbook. We highly recommend you utilize the native init system of your distro to have the best experience with memcached.
### Other fixes
- Fix using the resource to setup a sys-v init script on Fedora platforms
- Fix Amazon Linux support on Chef >= 13
- Don't delete the memcached init script if the instance name is 'memcached' and we're specifying the instance_name on the resource instead of using the resource's name
- Added new resource property for `log_level` and fixed logging setup in the resources
- Run failures with runit have been resolved
- Minor property cleanup in the resources
- Avoid an extra blank line in the command options
- Add Debian Sys-V script for Debian to allow for Debian 7 support
- Pull in systemd unit file security settings from upstream
## 4.1.0 (2017-05-06)
- Require Chef 12.7+ to workaround action_class bug
## 4.0.1 (2017-04-26)
- Update apache2 license string
## 4.0.0 (2017-03-13)
- Require 12.5 and remove dependency on compat_resource
- Let chef pick the best init system instead of hardcoding init systems per distro / version
- Avoid Chef 13 deprecation warnings
- Test with Local Delivery instead of Rake
- Add extra_cli_options for passing anything else you want in to the binary
- Use a consistent memcached path in the sysv script
## 3.0.3 (2017-01-19)
- Add missing `user` variable to template in instance_sysv_init resource
- Move testing to a test recipe and improve that testing
- Depend on the latest compat_resource
- Use :template_cookbook property for all template resources to fix specifying a different cookbook
## 3.0.2 (2016-06-28)
- Remove Chef 11 compatibility check in the metadata
- Better handle specifying non-standard init systems
## 3.0.1 (2016-06-23)
- Remove smartos from the supported platforms metadata as it's not longer supported
- Add opensuse and opensuseleap as supported platforms in the metadata
- Increase the compat_resource depdency from >= 12.9 to >= 12.10 to bring in important fixes
- Add requirement of Chef 12 to the metadata
- Restart the service on failure when running under systemd
- Disable FC023 in Foodcritic tests
## 3.0.0 (2016-05-24)
- The preferred method of use for this cookbook is now the custom resources via your own wrapper cookbook. The default recipe simply wraps the custom resource and allows you to set attributes instead of directly changing custom resource properties. To support this goal, the custom resource now uses the native init system of your OS by default (sys-v, upstart or systemd). The Runit provider is still present for backwards compatibility, but must be specified. See the readme for an example of how to do that with the custom resource. The default recipe does not support using runit and runit is no longer an init system we suggest users use.
- The ulimit attribute and custom resource property behavior have been changed. Ulimit now takes the actual ulimit value as a string or int. Previously a boolean value was passed and if true the connection max was set. This gives users additional control over the ulimit value.
- SmartOS support has been removed. SmartOS support was never properly implemented and didn't support the custom resource. We've chosen to remove it instead of leaving partially functional and untested code in place.
### Other CHANGES
- Testing has been improved with additional specs and integration tests that better match the capabilities of the cookbook
- Support has been added for platforms that lacked the Runit package, specifically opensuse -
## 2.1.0 (2016-03-16)
- Added a new property, disable_default_instance, to the instance custom resource for disabling the package installed memcached service. This prevents resource merging from resulting in a service that isn't disabled.
- Updated the custom resource to avoid potential namespace conflicts
- Require the latest custom_resource to avoid failures and extra warning messages
- Resolved nil attribute deprecation warnings
- Added maintainers files
## 2.0.3 (2016-02-16)
- Fix template whitespace location that resulted in bad command
## 2.0.2 (2015-11-20)
- Push new version to Supermarket to deal with bad artifact
## 2.0.1 (2015-11-19)
- Push new version to Supermarket to deal with bad artifact
## 2.0.0 (2015-11-10)
BREAKING CHANGES:
- The user and group attributes have been removed and are instead handled by a helper that picks the appropriate user / group based on the platform
- The memcached_instance definition that used both passed values and node attributes for configuration has been rewritten as a 12.5 custom resource with compat_resource providing backwards compatibility to all Chef 12.X releases. This new custom resource handles the installation of memcached and all configuration is passed in via custom resource properties. See the readme for examples of how to use this new resource. This change should greatly improve the ability to use memcached_instance within wrapper cookbooks.
## 1.9.0 (2015-11-05)
NOTE: This will be the last version of this cookbook that supports Chef 11 and the traditional attribute / resource hybrid setup for memcached instances. After this release this cookbook will function with attributes for a simple install or Chef 12.5 custom resources for creating individual memcached instances. If you utilize memcached instances using the attributes to define the config you'll need to pin to ~1.0 and later update to the new format in ~2.0.
- Debian/Ubuntu switched the user that memcached runs under from nobody to memcache. Updated the cookbook to use this user on those platforms and create it in case we're on an older distro release that didn't yet have that user
- Removed use of shellout that was causing issues for users
- Improved the workaround on Debian/Ubuntu for not starting the service on package install so that it doesn't show up as a changed resource on every Chef run
- Updated Chefspec to 4.X and added additional specs
- Add oracle to the metadata
- Add issues_url and source_url to the metadata
- Add new contributing.md, maintainers.md, and testing.md docs
- Add travis and cookbook version badges to the readme
- Clarified Chef 11 is the minimum required chef release
- Updated platforms in the Kitchen config
- Added chefignore file
- Removed all hash rockets
- Added a .foodcritic file with exclusions
- Updated travis to use their container infrastructure, chef-dk for testing deps, and kitchen-docker for integration testing
- Added a Rakefile to simplify testing
- Removed yum as a dependency as it wasn't being used.
- Removed attributes from the metadata as they hadn't been updated
## v1.8.0 (2015-08-11)
- updated serverspec tests to pass (See 3c7b5c9)
- deconflict memcached_instance runit definition from default init (See b06d2d)
- split `default.rb` into `install.rb` and `configure.rb` so that memcached_instance only starts the specified number of instances
- added attributes `logfilepath`, `version`, `threads`, `experimental_options`, and `ulimit`
- NOTE: if memcached_instance name is not specified or set to "memcached", the instance name will be "memcached". If anything else is specified, the instance name will be "memcached-${name}"
## v1.7.2 (2014-03-12)
- [COOK-4308] - Enable memcache on RHEL, Fedora, and Suse
- [COOK-4212] - Support max_object_size rhel and fedora
## v1.7.0
Updating for yum ~> 3.0\. Fixing up style issues for rubocop. Updating test-kitchen harness
## v1.6.6
fixing metadata version error. locking to 3.0
## v1.6.4
Locking yum dependency to '< 3'
## v1.6.2
[COOK-3741] UDP settings for memcached
## v1.6.0
### Bug
- **[COOK-3682](https://tickets.chef.io/browse/COOK-3682)** - Set user when using Debian packages
### Improvement
- **[COOK-3336](https://tickets.chef.io/browse/COOK-3336)** - Add an option to specify the logfile (fix)
## v1.5.0
### Improvement
- **[COOK-3336](https://tickets.chef.io/browse/COOK-3336)** - Add option to specify logfile
- **[COOK-3299](https://tickets.chef.io/browse/COOK-3299)** - Document that `memcached` is exposed by default
### Bug
- **[COOK-2990](https://tickets.chef.io/browse/COOK-2990)** - Include `listen`, `maxconn`, and `user` in the runit service
### New Feature
- **[COOK-2790](https://tickets.chef.io/browse/COOK-2790)** - Add support for defining max object size
## v1.4.0
### Improvement
- [COOK-2756]: add SUSE support to memcached cookbook
- [COOK-2791]: Remove the template for Karmic from the memcached cookbook
### Bug
- [COOK-2600]: support memcached on SmartOS
## v1.3.0
- [COOK-2386] - update `memcached_instance` definition for `runit_service` resource
## v1.2.0
- [COOK-1469] - include yum epel recipe on RHEL 5 (introduces yum cookbook dependency)
- [COOK-2202] - Fix typo in previous ticket/commits
- [COOK-2266] - pin runit dependency
## v1.1.2
- [COOK-990] - params insite runit_service isn't the same as outside
## v1.1.0
- [COOK-1764] - Add Max Connections to memcached.conf and fix typos
## v1.0.4
- [COOK-1192] - metadata doesn't include RH platforms (supported)
- [COOK-1354] - dev package changed name on centos6
## v1.0.2
- [COOK-1081] - support for centos/rhel
## v1.0.0
- [COOK-706] - Additional info in README
- [COOK-828] - Package for RHEL systems
## v0.10.4
- Current released version

View File

@ -0,0 +1,2 @@
Please refer to
https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD

126
ops/cookbooks/vendor/memcached/README.md vendored Normal file
View File

@ -0,0 +1,126 @@
# memcached Cookbook
[![Build Status](https://travis-ci.org/chef-cookbooks/memcached.svg?branch=master)](https://travis-ci.org/chef-cookbooks/memcached) [![Cookbook Version](https://img.shields.io/cookbook/v/memcached.svg)](https://supermarket.chef.io/cookbooks/memcached)
Provides a custom resource for installing instances of memcached. Also ships with a default recipe that uses attributes to configure a single memcached instance on a host.
## Requirements
### Platforms
- Debian / Ubuntu and derivatives
- RHEL and derivatives
- Fedora
- openSUSE/SLES
### Chef
- Chef 12.7+
### Cookbooks
- runit (not used by default)
## Attributes
The following are node attributes are used to configure the command line options of memcached if using the default.rb recipe. They are not used if using the memcached_instance custom resource.
- `memcached['memory']` - maximum memory for memcached instances.
- `memcached['user']` - user to run memcached as.
- `memcached['port']` - TCP port for memcached to listen on.
- `memcached['udp_port']` - UDP port for memcached to listen on.
- `memcached['listen']` - IP address for memcache to listen on, defaults to **0.0.0.0** (world accessible).
- `memcached['maxconn']` - maximum number of connections to accept (defaults to 1024)
- `memcached['max_object_size']` - maximum size of an object to cache (defaults to 1MB)
- `memcached['logfilepath']` - path to directory where log file will be written.
- `memcached['logfilename']` - logfile to which memcached output will be redirected in $logfilepath/$logfilename.
- `memcached['threads']` - Number of threads to use to process incoming requests. The default is 4.
- `memcached['experimental_options']` - Comma separated list of extended or experimental options. (array)
- `memcached['extra_cli_options']` - Array of single item options suchas -L for large pages.
- `memcached['ulimit']` - maxfile limit to set (needs to be at least maxconn)
## Usage
This cookbook can be used to to setup a single memcached instance running under the system's init provider by including `memcached::default` on your runlist. The above documented attributes can be used to control the configuration of that service.
The cookbook can also within other cookbooks in your infrastructure with the `memcached_instance` custom resource. See the documentation below for the usage and examples of that custom resource.
## Custom Resources
### instance
Adds or removes an instance of memcached running under the system's native init system (sys-v, upstart, or systemd). For backwards compatibility there is also a runit provider that can be used if desired.
#### Actions
- :start: Starts (and installs) an instance of memcached
- :stop: Stops an instance of memcached
- :enable: Enabled (and installs) an instance of memcached to run at boot
- :restart: Restarts an instance of memcached
#### Properties
- :memory - the amount of memory allocated for the cache. default: 64
- :port - the TCP port to listen on. default: 11,211
- :udp_port - the UDP port to listen on. default: 11,211
- :listen - the IP to listen on. default: '0.0.0.0'
- :maxconn - the maximum number of connections to accept. default: 1024
- :user - the user to run as
- :binary_path - path of memcached binary, when set we assume memcached is already installed
- :threads - the number of threads to use
- :max_object_size - the largest object size to store
- :experimental_options - an array of experimental config options, such as: ['maxconns_fast', 'hashpower']
- :extra_cli_options - an array of additional config options, such as: ['-L']
- :ulimit - the ulimit setting to use for the service
- :template_cookbook - the cookbook containing the runit service template. default: memcached
- :disable_default_instance - disable the default 'memcached' service installed by the package. default: true
- :no_restart - disable the service restart on configuration change. default: false
- :log_level - The level at which we log, default to 'info'. Choose from: 'info', 'debug', 'trace' which map to '-v', '-vv' or '-vvv' arguments.
#### Examples
Create a new memcached instance named super_custom_memcached:
```ruby
memcached_instance 'super_custom_memcached' do
port 11_212
memory 128
end
```
Stop and disable the super_custom_memcached instance:
```ruby
memcached_instance 'super_custom_memcached' do
action :remove
end
```
Specify the runit provider to maintain legacy behavior (including optional usage of legacy actions)
```ruby
memcached_instance_runit 'super_custom_memcached' do
action :create
end
```
## License & Authors
- Author:: Cookbook Engineering Team ([cookbooks@chef.io](mailto:cookbooks@chef.io))
```text
Copyright:: 2009-2016, Chef Software, Inc
Copyright:: 2009, 37signals
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.
```

View File

@ -0,0 +1,33 @@
#
# Cookbook:: memcached
# Attributes:: default
#
# Copyright:: 2009-2016, Chef Software, Inc.
#
# 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.
#
# these attributes are only used if running the default recipe
# they have no impact on the custom resources
# see the readme for usage details
default['memcached']['version'] = nil
default['memcached']['memory'] = 64
default['memcached']['port'] = 11_211
default['memcached']['udp_port'] = 11_211
default['memcached']['listen'] = '0.0.0.0'
default['memcached']['maxconn'] = 1024
default['memcached']['max_object_size'] = '1m'
default['memcached']['experimental_options'] = []
default['memcached']['extra_cli_options'] = []
default['memcached']['ulimit'] = 1024
default['memcached']['logfilepath'] = '/var/log/memcached'

View File

@ -0,0 +1,109 @@
def service_user
value_for_platform_family(
%w(suse fedora rhel amazon) => 'memcached',
'debian' => 'memcache',
'default' => 'nobody'
)
end
def service_group
value_for_platform_family(
%w(suse fedora rhel amazon) => 'memcached',
'debian' => 'memcache',
'default' => 'nogroup'
)
end
def binary_path
new_resource.binary_path || value_for_platform_family(
'suse' => '/usr/sbin/memcached',
'default' => '/usr/bin/memcached'
)
end
def lock_dir
value_for_platform_family(
%w(rhel fedora suse amazon) => '/var/lock/subsys',
'default' => '/var/lock'
)
end
# if the instance name is memcached don't spit out memcached_memcached
def memcached_instance_name
new_resource.instance_name == 'memcached' ? 'memcached' : "memcached_#{new_resource.instance_name}"
end
def disable_default_memcached_instance
return unless new_resource.disable_default_instance
service 'disable default memcached' do
service_name 'memcached'
action [:stop, :disable]
not_if { new_resource.instance_name == 'memcached' }
end
end
def remove_default_memcached_configs
return unless new_resource.remove_default_config
%w(/etc/memcached.conf /etc/sysconfig/memcached /etc/default/memcached).each do |f|
file f do
action :delete
end
end
end
def cli_options
options = "-m #{new_resource.memory} \
-U #{new_resource.udp_port} \
-p #{new_resource.port} \
-u #{new_resource.user} \
-l #{new_resource.listen} \
-c #{new_resource.maxconn} \
-I #{new_resource.max_object_size}"
options << " -o #{new_resource.experimental_options.join(',')}" unless new_resource.experimental_options.empty?
log_arg = ''
case new_resource.log_level
when 'info'
log_arg = 'v'
when 'debug'
log_arg = 'vv'
when 'trace'
log_arg = 'vvv'
end
options << " -#{log_arg}"
options << " -t #{new_resource.threads}" if new_resource.threads
options << " #{new_resource.extra_cli_options.join(' ')}" unless new_resource.extra_cli_options.empty?
options
end
def disable_legacy_runit_instance
return unless ::File.exist?("/etc/sv/#{memcached_instance_name}/run")
memcached_instance_runit memcached_instance_name do
action :remove
end
end
# choose the right platform init class
def platform_sysv_init_class
value_for_platform_family(
'debian' => Chef::Provider::Service::Init::Debian,
'default' => Chef::Provider::Service::Init::Redhat
)
end
def log_file_name
File.join(node['memcached']['logfilepath'], "#{memcached_instance_name}.log")
end
def create_log_file
file log_file_name do
user service_user
group service_group
mode '0644'
end
end

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,72 @@
#
# Cookbook:: memcached
# Recipe:: default
#
# Copyright:: 2009-2016, Chef Software, Inc.
#
# 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.
#
if node['platform_family'] == 'debian'
# dpkg, imma let you finish but don't start services automatically
# https://jpetazzo.github.io/2013/10/06/policy-rc-d-do-not-start-services-automatically/
file '/usr/sbin/policy-rc.d with exit 101' do
path '/usr/sbin/policy-rc.d'
content 'exit 101'
mode '0755'
not_if 'dpkg -s memcached'
end
package 'memcached' do
version node['memcached']['version']
action :install
end
file '/usr/sbin/policy-rc.d with exit 0' do
path '/usr/sbin/policy-rc.d'
content 'exit 0'
mode '0755'
end
else
package 'memcached' do
version node['memcached']['version']
action :install
end
end
group service_group do
system true
not_if "getent passwd #{service_user}"
end
user service_user do
system true
manage_home false
gid service_group
home '/nonexistent'
comment 'Memcached'
shell '/bin/false'
action [:create, :lock]
end
directory node['memcached']['logfilepath'] do
user service_user
group service_group
mode '0755'
end
directory '/var/run/memcached' do
user service_user
group service_group
mode '0755'
end

View File

@ -0,0 +1,37 @@
#
# Cookbook:: memcached
# Recipe:: default
#
# Copyright:: 2009-2016, Chef Software, Inc.
#
# 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.
#
# this recipe simply uses the memcached_instance custom resource
# for additional customization you can use this resource in your own wrapper cookbook
# this recipe simply uses the memcached_instance custom resource
# for additional customization you can use this resource in your own wrapper cookbook
memcached_instance 'memcached' do
memory node['memcached']['memory']
port node['memcached']['port']
udp_port node['memcached']['udp_port']
listen node['memcached']['listen']
maxconn node['memcached']['maxconn']
user service_user
max_object_size node['memcached']['max_object_size']
threads node['memcached']['threads']
experimental_options node['memcached']['experimental_options']
extra_cli_options node['memcached']['extra_cli_options']
ulimit node['memcached']['ulimit']
action [:start, :enable]
end

View File

@ -0,0 +1,143 @@
#
# Cookbook:: memcached
# resource:: instance_runit
#
# Author:: Tim Smith <tsmith@chef.io>
# Copyright:: 2009-2016, Chef Software, Inc.
#
# 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.
#
property :instance_name, String, name_property: true
property :memory, [Integer, String], default: 64
property :port, [Integer, String], default: 11_211
property :udp_port, [Integer, String], default: 11_211
property :listen, String, default: '0.0.0.0'
property :maxconn, [Integer, String], default: 1024
property :user, String, default: lazy { service_user }
property :binary_path, String
property :threads, [Integer, String]
property :max_object_size, String, default: '1m'
property :experimental_options, Array, default: []
property :extra_cli_options, Array, default: []
property :ulimit, [Integer, String], default: 1024
property :template_cookbook, String, default: 'memcached'
property :disable_default_instance, [true, false], default: true
property :remove_default_config, [true, false], default: true
property :log_level, String, default: 'info'
action :start do
Chef::Log.warn('The memcached_instance_runit resource has been deprecated as of 9/2017. This resource will be removed in the next major release of the memcached cookbook. We highly recommend using your distributions native init systeam instead.')
create_init
runit_service memcached_instance_name do
run_template_name 'memcached'
default_logger true
cookbook new_resource.template_cookbook
supports restart: true, status: true
action :start
end
end
action :stop do
runit_service memcached_instance_name do
run_template_name 'memcached'
default_logger true
cookbook new_resource.template_cookbook
supports status: true
action :stop
only_if { ::File.exist?("/etc/sv/#{memcached_instance_name}/run") }
end
end
action :restart do
runit_service memcached_instance_name do
run_template_name 'memcached'
default_logger true
cookbook new_resource.template_cookbook
supports restart: true, status: true
action :restart
end
end
action :enable do
create_init
runit_service memcached_instance_name do
run_template_name 'memcached'
default_logger true
cookbook new_resource.template_cookbook
supports status: true
action :enable
only_if { ::File.exist?("/etc/sv/#{memcached_instance_name}/run") }
end
end
action :disable do
runit_service memcached_instance_name do
run_template_name 'memcached'
default_logger true
cookbook new_resource.template_cookbook
supports status: true
action :disable
only_if { ::File.exist?("/etc/sv/#{memcached_instance_name}/run") }
end
end
### Legacy actions included for compatibility
action :remove do
runit_service memcached_instance_name do
run_template_name 'memcached'
default_logger true
cookbook new_resource.template_cookbook
action [:stop, :disable]
only_if { ::File.exist?("/etc/sv/#{memcached_instance_name}/run") }
end
end
action :create do
create_init
runit_service memcached_instance_name do
run_template_name 'memcached'
default_logger true
cookbook new_resource.template_cookbook
action [:start, :enable]
end
end
action_class do
def create_init
include_recipe 'runit'
include_recipe 'memcached::_package' unless new_resource.binary_path
# Disable the default memcached service to avoid port conflicts + wasted memory
disable_default_memcached_instance
# cleanup default configs to avoid confusion
remove_default_memcached_configs
runit_service memcached_instance_name do
run_template_name 'memcached'
default_logger true
cookbook new_resource.template_cookbook
options(
ulimit: new_resource.ulimit,
user: new_resource.user,
binary_path: binary_path,
cli_options: cli_options
)
end
end
end

View File

@ -0,0 +1,128 @@
#
# Cookbook:: memcached
# resource:: instance_systemd
#
# Author:: Tim Smith <tsmith@chef.io>
# Copyright:: 2016, Chef Software, Inc.
#
# 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.
#
provides :memcached_instance_systemd
provides :memcached_instance, os: 'linux' do |_node|
Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd)
end
property :instance_name, String, name_property: true
property :memory, [Integer, String], default: 64
property :port, [Integer, String], default: 11_211
property :udp_port, [Integer, String], default: 11_211
property :listen, String, default: '0.0.0.0'
property :maxconn, [Integer, String], default: 1024
property :user, String, default: lazy { service_user }
property :binary_path, String
property :threads, [Integer, String]
property :max_object_size, String, default: '1m'
property :experimental_options, Array, default: []
property :extra_cli_options, Array, default: []
property :ulimit, [Integer, String], default: 1024
property :template_cookbook, String, default: 'memcached'
property :disable_default_instance, [true, false], default: true
property :remove_default_config, [true, false], default: true
property :no_restart, [true, false], default: false
property :log_level, String, default: 'info'
action :start do
create_init
service memcached_instance_name do
provider Chef::Provider::Service::Systemd
supports restart: true, status: true
action :start
end
end
action :stop do
service memcached_instance_name do
provider Chef::Provider::Service::Systemd
supports status: true
action :stop
only_if { ::File.exist?("/etc/systemd/system/#{memcached_instance_name}.service") }
end
end
action :restart do
service memcached_instance_name do
provider Chef::Provider::Service::Systemd
supports restart: true, status: true
action :restart
end
end
action :disable do
service memcached_instance_name do
provider Chef::Provider::Service::Systemd
supports status: true
action :disable
only_if { ::File.exist?("/etc/systemd/system/#{memcached_instance_name}.service") }
end
end
action :enable do
create_init
service memcached_instance_name do
provider Chef::Provider::Service::Systemd
supports status: true
action :enable
end
end
action_class do
def create_init
include_recipe 'memcached::_package' unless new_resource.binary_path
# remove any runit instances with the same name if they exist
disable_legacy_runit_instance
# Disable the default memcached service to avoid port conflicts + wasted memory
disable_default_memcached_instance
# cleanup default configs to avoid confusion
remove_default_memcached_configs
template "/etc/systemd/system/#{memcached_instance_name}.service" do
source 'init_systemd.erb'
variables(
instance: memcached_instance_name,
ulimit: new_resource.ulimit,
user: new_resource.user,
binary_path: binary_path,
cli_options: cli_options
)
cookbook new_resource.template_cookbook
notifies :run, 'execute[reload_unit_file]', :immediately
notifies :restart, "service[#{memcached_instance_name}]", :immediately unless new_resource.no_restart
owner 'root'
group 'root'
mode '0644'
end
# systemd is cool like this
execute 'reload_unit_file' do
command 'systemctl daemon-reload'
action :nothing
end
end
end

View File

@ -0,0 +1,131 @@
#
# Cookbook:: memcached
# resource:: instance_sysv_init
#
# Author:: Tim Smith <tsmith@chef.io>
# Copyright:: 2016, Chef Software, Inc.
#
# 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.
#
provides :memcached_instance_sysv_init
provides :memcached_instance, os: 'linux'
property :instance_name, String, name_property: true
property :memory, [Integer, String], default: 64
property :port, [Integer, String], default: 11_211
property :udp_port, [Integer, String], default: 11_211
property :listen, String, default: '0.0.0.0'
property :maxconn, [Integer, String], default: 1024
property :user, String, default: lazy { service_user }
property :binary_path, String
property :threads, [Integer, String]
property :max_object_size, String, default: '1m'
property :experimental_options, Array, default: []
property :extra_cli_options, Array, default: []
property :ulimit, [Integer, String], default: 1024
property :template_cookbook, String, default: 'memcached'
property :disable_default_instance, [true, false], default: true
property :remove_default_config, [true, false], default: true
property :no_restart, [true, false], default: false
property :log_level, String, default: 'info'
action :start do
create_init
service memcached_instance_name do
provider platform_sysv_init_class
supports restart: true, status: true
action :start
end
end
action :stop do
service memcached_instance_name do
provider platform_sysv_init_class
supports status: true
action :stop
only_if { ::File.exist?("/etc/init.d/#{memcached_instance_name}") }
end
end
action :restart do
service memcached_instance_name do
provider platform_sysv_init_class
supports restart: true, status: true
action :restart
end
end
action :enable do
create_init
service memcached_instance_name do
provider platform_sysv_init_class
supports status: true
action :enable
only_if { ::File.exist?("/etc/init.d/#{memcached_instance_name}") }
end
end
action :disable do
service memcached_instance_name do
provider platform_sysv_init_class
supports status: true
action :disable
only_if { ::File.exist?("/etc/init.d/#{memcached_instance_name}") }
end
end
action_class do
def create_init
include_recipe 'memcached::_package' unless new_resource.binary_path
# remove any runit instances with the same name if they exist
disable_legacy_runit_instance
# Disable the default memcached service to avoid port conflicts + wasted memory
disable_default_memcached_instance
# cleanup default configs to avoid confusion
remove_default_memcached_configs
# the init script will not run without redhat-lsb packages
package 'redhat-lsb-core' if platform_family?('fedora', 'rhel', 'amazon')
# create the log file so we can write to it
create_log_file
# remove the debian defaults dir
file '/etc/default/memcached' do
action :delete
end
template "/etc/init.d/#{memcached_instance_name}" do
mode '0755'
source platform_family?('debian') ? 'init_sysv_debian.erb' : 'init_sysv.erb'
cookbook new_resource.template_cookbook
variables(
lock_dir: lock_dir,
instance: memcached_instance_name,
ulimit: new_resource.ulimit,
user: new_resource.user,
binary_path: binary_path,
cli_options: cli_options,
log_file: log_file_name
)
notifies :restart, "service[#{memcached_instance_name}]", :immediately unless new_resource.no_restart
end
end
end

View File

@ -0,0 +1,130 @@
#
# Cookbook:: memcached
# resource:: instance_upstart
#
# Author:: Tim Smith <tsmith@chef.io>
# Copyright:: 2016, Chef Software, Inc.
#
# 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.
#
provides :memcached_instance_upstart
provides :memcached_instance, platform_family: 'debian' do |_node|
Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) &&
!Chef::Platform::ServiceHelpers.service_resource_providers.include?(:systemd)
end
property :instance_name, String, name_property: true
property :memory, [Integer, String], default: 64
property :port, [Integer, String], default: 11_211
property :udp_port, [Integer, String], default: 11_211
property :listen, String, default: '0.0.0.0'
property :maxconn, [Integer, String], default: 1024
property :user, String, default: lazy { service_user }
property :binary_path, String
property :threads, [Integer, String]
property :max_object_size, String, default: '1m'
property :experimental_options, Array, default: []
property :extra_cli_options, Array, default: []
property :ulimit, [Integer, String], default: 1024
property :template_cookbook, String, default: 'memcached'
property :disable_default_instance, [true, false], default: true
property :remove_default_config, [true, false], default: true
property :no_restart, [true, false], default: false
property :log_level, String, default: 'info'
action :start do
create_init
service memcached_instance_name do
provider Chef::Provider::Service::Upstart
supports restart: true, status: true
action :start
end
end
action :stop do
service memcached_instance_name do
provider Chef::Provider::Service::Upstart
supports status: true
action :stop
only_if { ::File.exist?("/etc/init/#{memcached_instance_name}.conf") }
end
end
action :restart do
service memcached_instance_name do
provider Chef::Provider::Service::Upstart
supports restart: true, status: true
action :restart
end
end
action :enable do
create_init
service memcached_instance_name do
provider Chef::Provider::Service::Upstart
supports status: true
action :enable
only_if { ::File.exist?("/etc/init/#{memcached_instance_name}.conf") }
end
end
action :disable do
service memcached_instance_name do
provider Chef::Provider::Service::Upstart
supports status: true
action :disable
only_if { ::File.exist?("/etc/init/#{memcached_instance_name}.conf") }
end
end
action_class do
def create_init
include_recipe 'memcached::_package' unless new_resource.binary_path
# remove any runit instances with the same name if they exist
disable_legacy_runit_instance
# Disable the default memcached service to avoid port conflicts + wasted memory
disable_default_memcached_instance
# remove the default init script if our service is also named
# memcached so we don't have both an upstart script and an sys-v script
file '/etc/init.d/memcached' do
action :delete
only_if { new_resource.instance_name == 'memcached' }
end
# cleanup default configs to avoid confusion
remove_default_memcached_configs
# create the log file so we can write to it
create_log_file
template "/etc/init/#{memcached_instance_name}.conf" do
source 'init_upstart.erb'
variables(
instance: memcached_instance_name,
ulimit: new_resource.ulimit,
binary_path: binary_path,
cli_options: cli_options,
log_file: log_file_name
)
cookbook new_resource.template_cookbook
notifies :restart, "service[#{memcached_instance_name}]", :immediately unless new_resource.no_restart
end
end
end

View File

@ -0,0 +1,29 @@
# Systemd unit file for <%= @instance %>
[Unit]
Description=memcached instance <%= @instance %>
After=network.target
[Service]
User=<%= @user %>
LimitNOFILE=<%= @ulimit %>
ExecStart=<%= @binary_path %> <%= @cli_options %>
Restart=on-failure
# Various security configurations from:
# https://github.com/memcached/memcached/blob/master/scripts/memcached.service
PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
PrivateDevices=true
CapabilityBoundingSet=CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE
RestrictNamespaces=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
RestrictRealtime=true
ProtectControlGroups=true
ProtectKernelTunables=true
ProtectKernelModules=true
MemoryDenyWriteExecute=true
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,93 @@
#! /bin/sh
#
# memcached This shell script takes care of starting and stopping Memcached
#
# This script based off Atsushi NAGASE's script at https://gist.github.com/ngs/3081846
# chkconfig: - 55 45
### BEGIN INIT INFO
# Provides: <%= @instance %>
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: The memcached daemon is a network memory cache service.
# Processname: memcached
# Short-Description: start and stop memcached instance <%= @instance %>
### END INIT INFO
ulimit -n <%= @ulimit %>
## Source function library.
. /etc/rc.d/init.d/functions
# Source LSB function library.
if [ -r /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
else
echo 'Could not find necessary /lib/lsb/init-functions'
exit 1
fi
RETVAL=0
prog="memcached"
start () {
echo -n $"Starting $prog: "
# ensure that /var/run/memcached actually exists
if [ ! -d /var/run/memcached ]; then
mkdir /var/run/memcached
fi
# ensure that /var/run/memcached has proper permissions
if [ "`stat -c %U /var/run/memcached`" != "<%= @user %>" ]; then
chown <%= @user %> /var/run/memcached
fi
start_daemon -p /var/run/memcached/memcached_<%= @instance %>.pid <%= @binary_path %> -d \
-P /var/run/memcached/memcached_<%= @instance %>.pid <%= @cli_options %> >> <%= @log_file %> 2>&1
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch <%= @lock_dir %>/memcached
}
stop () {
echo -n $"Stopping $prog: "
killproc -p /var/run/memcached/memcached_<%= @instance %>.pid <%= @binary_path %>
RETVAL=$?
echo
if [ $RETVAL -eq 0 ] ; then
rm -f <%= @lock_dir %>/memcached
rm -f /var/run/memcached/memcached_<%= @instance %>.pid
fi
}
restart () {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status memcached
;;
restart|reload|force-reload)
restart
;;
condrestart)
[ -f <%= @lock_dir %>/memcached ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
exit 1
esac
exit $?

View File

@ -0,0 +1,103 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: <%= @instance %>
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop memcached instance <%= @instance %>
# Description: The memcached daemon is a network memory cache service.
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Description of the service"
NAME=<%= @instance %>
DAEMON=<%= @binary_path %>
PIDFILE=/var/run/$NAME.pid
DAEMON_ARGS="<%= @cli_options %> -d -P $PIDFILE"
SCRIPTNAME=/etc/init.d/$NAME
ulimit -n <%= @ulimit %>
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 1
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
touch $PIDFILE
chown <%= @user %>:root $PIDFILE
chmod 660 $PIDFILE
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS >> <%= @log_file %> 2>&1 \
|| return 2
}
#
# Function that stops the daemon/service
#
do_stop()
{
start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
RETVAL="$?"
rm -f $PIDFILE
return "$RETVAL"
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc -p $PIDFILE && exit 0 || exit $?
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:

View File

@ -0,0 +1,10 @@
description "Memcached instance <%= @instance -%>"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
respawn limit 10 5
limit nofile <%= @ulimit -%> <%= @ulimit -%>
exec <%= @binary_path %> <%= @cli_options %> >> <%= @log_file %> 2>&1

View File

@ -0,0 +1,2 @@
#!/bin/sh
exec svlogd -tt ./main

View File

@ -0,0 +1,6 @@
#!/bin/sh
exec 2>&1
ulimit -n <%= @options[:ulimit] %>
exec chpst -u <%= @options[:user] %> <%= @options[:binary_path] %> <%= @options[:cli_options] %>