diff --git a/redisio/.gitignore b/redisio/.gitignore new file mode 100644 index 0000000..96eb002 --- /dev/null +++ b/redisio/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +*swp +*swo diff --git a/redisio/README.md b/redisio/README.md new file mode 100644 index 0000000..d01fdc7 --- /dev/null +++ b/redisio/README.md @@ -0,0 +1,373 @@ +Description +=========== + +Website:: https://github.com/brianbianco/redisio + +Installs and configures Redis server instances + +Requirements +============ + +This cookbook builds redis from source, so it should work on any architecture for the supported distributions. Init scripts are installed into /etc/init.d/ + +Platforms +--------- + +* Debian, Ubuntu +* CentOS, Red Hat, Fedora, Scientific Linux + +Tested on: + +* Ubuntu 10.10, 12.04 +* Debian 6.0 +* Fedora 16 +* Scientific Linux 6.2 +* Centos 6.2 + +Usage +===== + +The redisio cookbook has 3 LWRP's and 4 recipes. For most use cases it isn't necessary to use the "install" LWRP and you should use the install recipe unless +you have a good understanding of the required fields for the install LWRP. The service LWRP can be more useful if you have situations where you want to start, +stop, or restart the redis service based on certain conditions. + +If all you are interested in is having redis started and running as well as set to run in the default run levels, I suggest just using the install recipe followed by the enable recipe and not using the LWRP directly. + +I have provided a disable recipe as well which will stop redis and remove it from the defaults run levels. There is also an uninstall LWRP, which will remove the redis binaries and optionally the init scripts and configuration files. It will NOT delete the redis data files files, that will have to be done manually. I have provided for example and use, a redis uninstall recipe which will disable the service, remove the binaries, init scripts, and configuration files for all redis instances listed in the redisio['servers'] array. + +It is important to note that changing the configuration options of redis does not make them take effect on the next chef run. Due to how redis works, you cannot reload a configuration without restarting the redis service. If you make a configuration change and you want it to take effect, you can either use the service LWRP to issue a restart to the servers you want via a cookbook you write, or you can use knife ssh to restart the redis service on the servers you want to change configuration on. + +The cookbook also contains a recipe to allow for the installation of the redis ruby gem. + +Role File Examples +------------------ + +Install redis and setup an instance with default settings on default port, and start the service through a role file + +```ruby +run_list *%w[ + recipe[redisio::install] + recipe[redisio::enable] +] + +default_attributes({}) +``` + +Install redis and setup two instances on the same server, on different ports, with one slaved to the other through a role file + +```ruby +run_list *%w[ + recipe[redisio::install] + recipe[redisio::enable] +] + +default_attributes({ + 'redisio' => { + 'servers' => [ + {'port' => '6379'}, + {'port' => '6380', 'slaveof' => { 'address' => '127.0.0.1', 'port' => '6379' }} + ] + } +}) +``` + +Install redis and setup two instances, on the same server, on different ports, with the data directory changed to /mnt/redis + +```ruby +run_list *%w[ + recipe[redisio::install] + recipe[redisio::enable] +] + +default_attributes({ + 'redisio' => { + 'default_settings' => {'datadir' => '/mnt/redis'}, + 'servers' => [{'port' => '6379'}, {'port' => '6380'}] + } +}) +``` + +Install redis and setup three instances on the same server, changing the default data directory to /mnt/redis, each instance will use a different backup type, and one instance will use a different data dir + +```ruby +run_list *%w[ + recipe[redisio::install] + recipe[redisio::enable] +] + +default_attributes({ + 'redisio' => { + 'default_settings' => { 'datadir' => '/mnt/redis/'}, + 'servers' => [ + {'port' => '6379','backuptype' => 'aof'}, + {'port' => '6380','backuptype' => 'both'} + {'port' => '6381','backuptype' => 'rdb', 'datadir' => '/mnt/redis6381'} + ] + } +}) +``` + +Install redis 2.4.11 (lower than the default version of 2.4.16) and turn safe install off, for the event where redis is already installed. This will use the default settings. Keep in mind the redis version will +not actually be updated until you restart the service (either through the LWRP or manually). + +```ruby +run_list *%w[ + recipe[redisio::install] + recipe[redisio::enable] +] + +default_attributes({ + 'redisio' => { + 'safe_install' => false, + 'version' => '2.4.11' + } +}) +``` + +Install version 2.2.2 of the redis ruby gem, if you don't list the version, it will simply install the latest available. + +```ruby +run_list *%w[ + recipe[redisio::redis_gem] +] + +default_attributes({ + 'redisio' => { + 'gem' => { + 'version' => '2.2.2' + } + } +}) +``` + +LWRP Examples +------------- + +Instead of using my provided recipes, you can simply include the redisio default in your role and use the LWRP's yourself. I will show a few examples of ways to use the LWRPS, detailed breakdown of options are below +in the resources/providers section + +install resource +---------------- + +It is important to note that this call has certain expectations for example, it expects the redis package to be in the format `redis-VERSION.tar.gz'. The servers resource expects an array of hashes where each hash is required to contain at a key-value pair of 'port' => ''. + +```ruby +redisio_install "redis-servers" do + version '2.4.10' + download_url 'http://redis.googlecode.com/files/redis-2.4.10.tar.gz' + default_settings node['redisio']['default_settings'] + servers node['redisio']['servers'] + safe_install false + base_piddir node['redisio']['base_piddir'] +end +``` + +uninstall resource +------------------ + +I generally don't recommend using this LWRP or recipe at all, but in the event you really want to remove files, these are available. + + +This will only remove the redis binary files if they exist, nothing else. + +```ruby +redisio_uninstall "redis-servers" do + action :run +end +``` + +This will remove the redis binaries, as well as the init script and configuration files for the specified server. This will not remove any data files + +```ruby +redisio_uninstall "redis-servers" do + servers [{'port' => '6379'}] + action :run +end +``` + +service resource +---------------- + +This LWRP provides the ability to stop, start, restart, disable and enable the redis service. + +Start and add to default runlevels the instance running on port 6379 + +```ruby +redisio_service "6379" do + action [:start,:enable] +end +``` + +Stop and remove from default runlevels the instance running on port 6379 + +```ruby +redisio_service "6379" do + action [:stop,:disable] +end +``` + +Restart the instance running on port 6380 + +```ruby +redisio_service "6380" do + action [:restart] +end +``` + +Attributes +========== + +Configuration options, each option corresponds to the same-named configuration option in the redis configuration file; default values listed + +* `redisio['mirror']` - mirror server with path to download redis package, default is https://redis.googlecode.com/files +* `redisio['base_name']` - the base name of the redis package to be downloaded (the part before the version), default is 'redis-' +* `redisio['artifact_type']` - the file extension of the package. currently only .tar.gz and .tgz are supported, default is 'tar.gz' +* `redisio['version']` - the version number of redis to install (also appended to the `base_name` for downloading), default is '2.4.10' +* `redisio['safe_install'] - prevents redis from installing itself if another version of redis is installed, default is true +* `redisio['base_piddir'] - This is the directory that redis pidfile directories and pidfiles will be placed in. Since redis can run as non root, it needs to have proper + permissions to the directory to create its pid. Since each instance can run as a different user, these directories will all be nested inside this base one. + +Default settings is a hash of default settings to be applied to to ALL instances. These can be overridden for each individual server in the servers attribute. If you are going to set logfile to a specific file, make sure to set syslog-enabled to no. + +* `redisio['default_settings']` - { 'redis-option' => 'option setting' } + +Available options and their defaults + +``` +'user' => 'redis' - the user to own the redis datadir, redis will also run under this user +'group' => 'redis' - the group to own the redis datadir +'homedir' => Home directory of the user. Varies on distribution, check attributes file +'shell' => Users shell. Varies on distribution, check attributes file +'configdir' => '/etc/redis' - configuration directory +'address' => nil, +'databases' => '16', +'backuptype' => 'rdb', +'datadir' => '/var/lib/redis', +'timeout' => '0', +'loglevel' => 'verbose', +'logfile' => nil, +'syslogenabled' => 'yes',, +'syslogfacility => 'local0', +'save' => ['900 1','300 10','60 10000'], +'slaveof' => nil, +'masterauth' => nil, +'slaveservestaledata' => 'yes', +'replpingslaveperiod' => '10', +'repltimeout' => '60', +'requirepass' => nil, +'maxclients' => '10000', +'maxmemory' => nil, +'maxmemorypolicy' => 'volatile-lru', +'maxmemorysamples' => '3', +'appendfsync' => 'everysec', +'noappendfsynconrewrite' => 'no', +'aofrewritepercentage' => '100', +'aofrewriteminsize' => '64mb', +'includes' => nil +``` + +* `redisio['servers']` - An array where each item is a set of key value pairs for redis instance specific settings. The only required option is 'port'. These settings will override the options in 'default_settings', default is set to [{'port' => '6379'}] + +The redis_gem recipe will also allow you to install the redis ruby gem, these are attributes related to that, and are in the redis_gem attributes file. + +* `redisio['gem']['name']` - the name of the gem to install, defaults to 'redis' +* `redisio['gem']['version']` - the version of the gem to install. if it is nil, the latest available version will be installed. + +Resources/Providers +=================== + +This cookbook contains 3 LWRP's + +`install` +-------- + +Actions: + +* `run` - perform the install (default) +* `nothing` - do nothing + +Attribute Parameters + +* `version` - the version of redis to download / install +* `download_url` - the URL plus filename of the redis package to install +* `download_dir` - the directory to store the downloaded package +* `artifact_type` - the file extension of the package +* `base_name` - the name of the package minus the extension and version number +* `user` - the user to run redis as, and to own the redis files +* `group` - the group to own the redis files +* `default_settings` - a hash of the default redis server settings +* `servers` - an array of hashes containing server configurations overrides (port is the only required) +* `safe_install` - a true or false value which determines if a version of redis will be installed if one already exists, defaults to true + +This resource expects the following naming conventions: + +package file should be in the format . + +package file after extraction should be inside of the directory + +```ruby +install "redis" do + action [:run,:nothing] +end +``` + +`uninstall` +---------- + +Actions: + +* `run` - perform the uninstall +* `nothing` - do nothing (default) + +Attribute Parameters + +* `servers` - an array of hashes containing the port number of instances to remove along with the binarires. (it is fine to pass in the same hash you used to install, even if there are additional + only the port is used) + +```ruby +uninstall "redis" do + action [:run,:nothing] +end +``` + +`service` +--------- + +Actions: + +* `start` +* `stop` +* `restart` +* `enable` +* `disable` + +The name of the service must be the port that the redis server you want to perform the action on is identified by + +```ruby +service "redis_port" do + action [:start,:stop,:restart,:enable,:disable] +end +``` + +License and Author +================== + +Author:: [Brian Bianco] () +Author\_Website:: http://www.brianbianco.com +Twitter:: @brianwbianco +IRC:: geekbri + +Copyright 2012, Brian Bianco + +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. + diff --git a/redisio/attributes/default.rb b/redisio/attributes/default.rb new file mode 100644 index 0000000..c767dfa --- /dev/null +++ b/redisio/attributes/default.rb @@ -0,0 +1,82 @@ +# +# Cookbook Name:: redisio +# Attribute::default +# +# Copyright 2012, Brian Bianco +# +# 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. +# + +case node['platform'] +when 'ubuntu','debian' + shell = '/bin/false' + homedir = '/var/lib/redis' +when 'centos','redhat','fedora','scientific','amazon','suse' + shell = '/bin/sh' + homedir = '/var/lib/redis' #this is necessary because selinux by default prevents the homedir from being managed in /var/lib/ +when 'fedora' + shell = '/bin/sh' + homedir = '/home' +else + shell = '/bin/sh' + homedir = '/redis' +end + +#Install related attributes +default['redisio']['safe_install'] = true + +#Tarball and download related defaults +default['redisio']['mirror'] = "https://redis.googlecode.com/files" +default['redisio']['base_name'] = 'redis-' +default['redisio']['artifact_type'] = 'tar.gz' +default['redisio']['version'] = '2.4.16' +default['redisio']['base_piddir'] = '/var/run/redis' + +#Default settings for all redis instances, these can be overridden on a per server basis in the 'servers' hash +default['redisio']['default_settings'] = { + 'user' => 'redis', + 'group' => 'redis', + 'homedir' => homedir, + 'shell' => shell, + 'configdir' => '/etc/redis', + 'address' => nil, + 'databases' => '16', + 'backuptype' => 'rdb', + 'datadir' => '/var/lib/redis', + 'timeout' => '0', + 'loglevel' => 'verbose', + 'logfile' => nil, + 'syslogenabled' => 'yes', + 'syslogfacility' => 'local0', + 'save' => ['900 1','300 10','60 10000'], + 'slaveof' => nil, + 'masterauth' => nil, + 'slaveservestaledata' => 'yes', + 'replpingslaveperiod' => '10', + 'repltimeout' => '60', + 'requirepass' => nil, + 'maxclients' => 10000, + 'maxmemory' => nil, + 'maxmemorypolicy' => 'volatile-lru', + 'maxmemorysamples' => '3', + 'appendfsync' => 'everysec', + 'noappendfsynconrewrite' => 'no', + 'aofrewritepercentage' => '100', + 'aofrewriteminsize' => '64mb', + 'includes' => nil +} + +#Individual server overrides, port is required and must be unique per instance, by default we setup a single redis instance on the default redis port of 6379 +default['redisio']['servers'] = [{'port' => '6379'}] + + diff --git a/redisio/attributes/redis_gem.rb b/redisio/attributes/redis_gem.rb new file mode 100644 index 0000000..565379e --- /dev/null +++ b/redisio/attributes/redis_gem.rb @@ -0,0 +1,23 @@ +# +# Cookbook Name:: redisio +# Attribute::redis_gem +# +# Copyright 2012, Brian Bianco +# +# 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. +# + +#Allow for a redis ruby gem to be installed +default['redisio']['gem']['name'] = 'redis' +default['redisio']['gem']['version'] = nil + diff --git a/redisio/changelog.md b/redisio/changelog.md new file mode 100644 index 0000000..20fd5ee --- /dev/null +++ b/redisio/changelog.md @@ -0,0 +1,53 @@ +redisio CHANGE LOG +=== + +1.1.0 - Released 8/21/2012 +--- + ! Warning breaking change !: The redis pidfile directory by default has changed, if you do not STOP redis before upgrading to the new version + of this cookbook, it will not be able to stop your instance properly via the redis service provider, or the init script. + If this happens to you, you can always log into the server and manually send a SIGTERM to redis + + - Changed the init script to run redis as the specified redis user + - Updated the default version of redis to 2.4.16 + - Setup a new directory structure for redis pid files. The install provider will now nest its pid directories in base_piddir//redis_.pid. + - Added a RedisioHelper module in libraries. The recipe_eval method inside is used to wrap nested resources to allow for the proper resource update propigation. The install provider uses this. + - The init script now properly respects the configdir attribute + - Changed the redis data directories to be 775 instead of 755 (this allows multiple instances with different owners to write their data to the same shared dir so long as they are in a common group) + - Changed default for maxclients to be 10000 instead of 0. This is to account for the fact that maxclients no longer supports 0 as 'unlimited' in the 2.6 series + - Added logic to replace hash-max-ziplist-entries, hash-max-ziplist-value with hash-max-zipmap-entires, hash-max-zipmap-value when using 2.6 series + - Added the ability to log to any file, not just syslog. Please do make sure after you set your file with the logfile attribute you also set syslogenabled to 'no' + +1.0.3 - Released 5/2/2012 +--- + + - Added changelog.md + - Added a bunch more configuration options that were left out (default values left as they were before): + - databases + - slaveservestaledata + - replpingslaveperiod + - repltimeout + - maxmemorysamples + - noappendfsynconwrite + - aofrewritepercentage + - aofrewriteminsize + + It is worth nothing that since there is a configurable option for conf include files, and the fact that redis uses the most recently read configuration option... even if a new option where to show up, or and old one was not included they could be added using that pattern. + + +1.0.2 - Released 4/25/2012 +--- + + - Merged in pull request from meskyanichi which improved the README.md and added a .gitignore + - Added a "safe_install" node attribute which will prevent redis from installing anything if it exists already. Defaults to true. + - Addedd a "redis_gem" recipe which will install the redis gem from ruby gems, added associated attributes. See README for me + +1.0.1 - Released 4/8/2012 +--- + + - Added some prequisite checks for RHEL based distributions + - Minor typos and formatting fixes in metadata.rb and README.md + +1.0.0 - Released 4/8/2012 +--- + + - Initial Release diff --git a/redisio/libraries/redisio.rb b/redisio/libraries/redisio.rb new file mode 100644 index 0000000..acba110 --- /dev/null +++ b/redisio/libraries/redisio.rb @@ -0,0 +1,52 @@ +# +# Cookbook Name:: redisio +# Resource::install +# +# Copyright 2012, Brian Bianco +# +# 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. +# + +module RedisioHelper + def recipe_eval + sub_run_context = @run_context.dup + sub_run_context.resource_collection = Chef::ResourceCollection.new + begin + original_run_context, @run_context = @run_context, sub_run_context + yield + ensure + @run_context = original_run_context + end + + begin + Chef::Runner.new(sub_run_context).converge + ensure + if sub_run_context.resource_collection.any?(&:updated?) + new_resource.updated_by_last_action(true) + end + end + end + + def self.version_to_hash(version_string) + version_array = version_string.split('.') + version_array[2] = version_array[2].split("-") + version_array.flatten! + version_hash = { + :major => version_array[0], + :minor => version_array[1], + :tiny => version_array[2], + :rc => version_array[3] + } + end +end + diff --git a/redisio/metadata.json b/redisio/metadata.json new file mode 100644 index 0000000..d28df13 --- /dev/null +++ b/redisio/metadata.json @@ -0,0 +1,43 @@ +{ + "name": "redisio", + "description": "Installs/Configures redis", + "long_description": "Description\n===========\n\nWebsite:: https://github.com/brianbianco/redisio\n\nInstalls and configures Redis server instances\n\nRequirements\n============\n\nThis cookbook builds redis from source, so it should work on any architecture for the supported distributions. Init scripts are installed into /etc/init.d/\n\nPlatforms\n---------\n\n* Debian, Ubuntu\n* CentOS, Red Hat, Fedora, Scientific Linux\n\nTested on:\n\n* Ubuntu 10.10, 12.04\n* Debian 6.0\n* Fedora 16\n* Scientific Linux 6.2\n* Centos 6.2\n\nUsage\n=====\n\nThe redisio cookbook has 3 LWRP's and 4 recipes. For most use cases it isn't necessary to use the \"install\" LWRP and you should use the install recipe unless\nyou have a good understanding of the required fields for the install LWRP. The service LWRP can be more useful if you have situations where you want to start,\nstop, or restart the redis service based on certain conditions.\n\nIf all you are interested in is having redis started and running as well as set to run in the default run levels, I suggest just using the install recipe followed by the enable recipe and not using the LWRP directly.\n\nI have provided a disable recipe as well which will stop redis and remove it from the defaults run levels. There is also an uninstall LWRP, which will remove the redis binaries and optionally the init scripts and configuration files. It will NOT delete the redis data files files, that will have to be done manually. I have provided for example and use, a redis uninstall recipe which will disable the service, remove the binaries, init scripts, and configuration files for all redis instances listed in the redisio['servers'] array.\n\nIt is important to note that changing the configuration options of redis does not make them take effect on the next chef run. Due to how redis works, you cannot reload a configuration without restarting the redis service. If you make a configuration change and you want it to take effect, you can either use the service LWRP to issue a restart to the servers you want via a cookbook you write, or you can use knife ssh to restart the redis service on the servers you want to change configuration on.\n\nThe cookbook also contains a recipe to allow for the installation of the redis ruby gem. \n\nRole File Examples\n------------------\n\nInstall redis and setup an instance with default settings on default port, and start the service through a role file\n\n```ruby\nrun_list *%w[\n recipe[redisio::install]\n recipe[redisio::enable]\n]\n\ndefault_attributes({})\n```\n\nInstall redis and setup two instances on the same server, on different ports, with one slaved to the other through a role file\n\n```ruby\nrun_list *%w[\n recipe[redisio::install]\n recipe[redisio::enable]\n]\n\ndefault_attributes({\n 'redisio' => {\n 'servers' => [\n {'port' => '6379'},\n {'port' => '6380', 'slaveof' => { 'address' => '127.0.0.1', 'port' => '6379' }}\n ]\n }\n})\n```\n\nInstall redis and setup two instances, on the same server, on different ports, with the data directory changed to /mnt/redis\n\n```ruby\nrun_list *%w[\n recipe[redisio::install]\n recipe[redisio::enable]\n]\n\ndefault_attributes({\n 'redisio' => {\n 'default_settings' => {'datadir' => '/mnt/redis'},\n 'servers' => [{'port' => '6379'}, {'port' => '6380'}]\n }\n})\n```\n\nInstall redis and setup three instances on the same server, changing the default data directory to /mnt/redis, each instance will use a different backup type, and one instance will use a different data dir\n\n```ruby\nrun_list *%w[\n recipe[redisio::install]\n recipe[redisio::enable]\n]\n\ndefault_attributes({\n 'redisio' => {\n 'default_settings' => { 'datadir' => '/mnt/redis/'},\n 'servers' => [\n {'port' => '6379','backuptype' => 'aof'},\n {'port' => '6380','backuptype' => 'both'}\n {'port' => '6381','backuptype' => 'rdb', 'datadir' => '/mnt/redis6381'}\n ]\n }\n})\n```\n\nInstall redis 2.4.11 (lower than the default version of 2.4.16) and turn safe install off, for the event where redis is already installed. This will use the default settings. Keep in mind the redis version will\nnot actually be updated until you restart the service (either through the LWRP or manually).\n\n```ruby\nrun_list *%w[\n recipe[redisio::install]\n recipe[redisio::enable]\n]\n\ndefault_attributes({\n 'redisio' => {\n 'safe_install' => false,\n 'version' => '2.4.11'\n }\n})\n```\n\nInstall version 2.2.2 of the redis ruby gem, if you don't list the version, it will simply install the latest available.\n\n```ruby\nrun_list *%w[\n recipe[redisio::redis_gem]\n]\n\ndefault_attributes({\n 'redisio' => {\n 'gem' => {\n 'version' => '2.2.2'\n }\n }\n})\n```\n\nLWRP Examples\n-------------\n\nInstead of using my provided recipes, you can simply include the redisio default in your role and use the LWRP's yourself. I will show a few examples of ways to use the LWRPS, detailed breakdown of options are below\nin the resources/providers section\n\ninstall resource\n----------------\n\nIt is important to note that this call has certain expectations for example, it expects the redis package to be in the format `redis-VERSION.tar.gz'. The servers resource expects an array of hashes where each hash is required to contain at a key-value pair of 'port' => ''.\n\n```ruby\nredisio_install \"redis-servers\" do\n version '2.4.10'\n download_url 'http://redis.googlecode.com/files/redis-2.4.10.tar.gz'\n default_settings node['redisio']['default_settings']\n servers node['redisio']['servers']\n safe_install false\n base_piddir node['redisio']['base_piddir']\nend\n```\n\nuninstall resource\n------------------\n\nI generally don't recommend using this LWRP or recipe at all, but in the event you really want to remove files, these are available.\n\n\nThis will only remove the redis binary files if they exist, nothing else.\n\n```ruby\nredisio_uninstall \"redis-servers\" do\n action :run\nend\n```\n\nThis will remove the redis binaries, as well as the init script and configuration files for the specified server. This will not remove any data files\n\n```ruby\nredisio_uninstall \"redis-servers\" do\n servers [{'port' => '6379'}]\n action :run\nend\n```\n\nservice resource\n----------------\n\nThis LWRP provides the ability to stop, start, restart, disable and enable the redis service.\n\nStart and add to default runlevels the instance running on port 6379\n\n```ruby\nredisio_service \"6379\" do\n action [:start,:enable]\nend\n```\n\nStop and remove from default runlevels the instance running on port 6379\n\n```ruby\nredisio_service \"6379\" do\n action [:stop,:disable]\nend\n```\n\nRestart the instance running on port 6380\n\n```ruby\nredisio_service \"6380\" do\n action [:restart]\nend\n```\n\nAttributes\n==========\n\nConfiguration options, each option corresponds to the same-named configuration option in the redis configuration file; default values listed\n\n* `redisio['mirror']` - mirror server with path to download redis package, default is https://redis.googlecode.com/files\n* `redisio['base_name']` - the base name of the redis package to be downloaded (the part before the version), default is 'redis-'\n* `redisio['artifact_type']` - the file extension of the package. currently only .tar.gz and .tgz are supported, default is 'tar.gz'\n* `redisio['version']` - the version number of redis to install (also appended to the `base_name` for downloading), default is '2.4.10'\n* `redisio['safe_install'] - prevents redis from installing itself if another version of redis is installed, default is true\n* `redisio['base_piddir'] - This is the directory that redis pidfile directories and pidfiles will be placed in. Since redis can run as non root, it needs to have proper\n permissions to the directory to create its pid. Since each instance can run as a different user, these directories will all be nested inside this base one.\n\nDefault settings is a hash of default settings to be applied to to ALL instances. These can be overridden for each individual server in the servers attribute. If you are going to set logfile to a specific file, make sure to set syslog-enabled to no.\n\n* `redisio['default_settings']` - { 'redis-option' => 'option setting' }\n\nAvailable options and their defaults\n\n```\n'user' => 'redis' - the user to own the redis datadir, redis will also run under this user\n'group' => 'redis' - the group to own the redis datadir\n'homedir' => Home directory of the user. Varies on distribution, check attributes file \n'shell' => Users shell. Varies on distribution, check attributes file\n'configdir' => '/etc/redis' - configuration directory\n'address' => nil,\n'databases' => '16',\n'backuptype' => 'rdb',\n'datadir' => '/var/lib/redis',\n'timeout' => '0',\n'loglevel' => 'verbose',\n'logfile' => nil,\n'syslogenabled' => 'yes',,\n'syslogfacility => 'local0',\n'save' => ['900 1','300 10','60 10000'],\n'slaveof' => nil,\n'masterauth' => nil,\n'slaveservestaledata' => 'yes',\n'replpingslaveperiod' => '10',\n'repltimeout' => '60',\n'requirepass' => nil,\n'maxclients' => '10000',\n'maxmemory' => nil,\n'maxmemorypolicy' => 'volatile-lru',\n'maxmemorysamples' => '3',\n'appendfsync' => 'everysec',\n'noappendfsynconrewrite' => 'no',\n'aofrewritepercentage' => '100',\n'aofrewriteminsize' => '64mb',\n'includes' => nil\n```\n\n* `redisio['servers']` - An array where each item is a set of key value pairs for redis instance specific settings. The only required option is 'port'. These settings will override the options in 'default_settings', default is set to [{'port' => '6379'}]\n\nThe redis_gem recipe will also allow you to install the redis ruby gem, these are attributes related to that, and are in the redis_gem attributes file.\n\n* `redisio['gem']['name']` - the name of the gem to install, defaults to 'redis' \n* `redisio['gem']['version']` - the version of the gem to install. if it is nil, the latest available version will be installed.\n\nResources/Providers\n===================\n\nThis cookbook contains 3 LWRP's\n\n`install`\n--------\n\nActions:\n\n* `run` - perform the install (default)\n* `nothing` - do nothing\n\nAttribute Parameters\n\n* `version` - the version of redis to download / install\n* `download_url` - the URL plus filename of the redis package to install\n* `download_dir` - the directory to store the downloaded package\n* `artifact_type` - the file extension of the package\n* `base_name` - the name of the package minus the extension and version number\n* `user` - the user to run redis as, and to own the redis files\n* `group` - the group to own the redis files\n* `default_settings` - a hash of the default redis server settings\n* `servers` - an array of hashes containing server configurations overrides (port is the only required)\n* `safe_install` - a true or false value which determines if a version of redis will be installed if one already exists, defaults to true\n\nThis resource expects the following naming conventions:\n\npackage file should be in the format .\n\npackage file after extraction should be inside of the directory \n\n```ruby\ninstall \"redis\" do\n action [:run,:nothing]\nend\n```\n\n`uninstall`\n----------\n\nActions:\n\n* `run` - perform the uninstall\n* `nothing` - do nothing (default)\n\nAttribute Parameters\n\n* `servers` - an array of hashes containing the port number of instances to remove along with the binarires. (it is fine to pass in the same hash you used to install, even if there are additional\n only the port is used)\n\n```ruby\nuninstall \"redis\" do\n action [:run,:nothing]\nend\n```\n\n`service`\n---------\n\nActions:\n\n* `start`\n* `stop`\n* `restart`\n* `enable`\n* `disable`\n\nThe name of the service must be the port that the redis server you want to perform the action on is identified by\n\n```ruby\nservice \"redis_port\" do\n action [:start,:stop,:restart,:enable,:disable]\nend\n```\n\nLicense and Author\n==================\n\nAuthor:: [Brian Bianco] ()\nAuthor\\_Website:: http://www.brianbianco.com\nTwitter:: @brianwbianco\nIRC:: geekbri\n\nCopyright 2012, Brian Bianco\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n", + "maintainer": "Brian Bianco", + "maintainer_email": "brian.bianco@gmail.com", + "license": "Apache 2.0", + "platforms": { + "debian": ">= 0.0.0", + "ubuntu": ">= 0.0.0", + "centos": ">= 0.0.0", + "redhat": ">= 0.0.0", + "fedora": ">= 0.0.0", + "scientific": ">= 0.0.0", + "suse": ">= 0.0.0", + "amazon": ">= 0.0.0" + }, + "dependencies": { + }, + "recommendations": { + }, + "suggestions": { + }, + "conflicting": { + }, + "providing": { + }, + "replacing": { + }, + "attributes": { + }, + "groupings": { + }, + "recipes": { + "redisio": "This recipe is used to install the prequisites for building and installing redis, as well as provides the LWRPs", + "redisio::install": "This recipe is used to install redis and create the configuration files and init scripts", + "redisio::uninstall": "This recipe is used to uninstall the redis binaries as well as optionally the configuration files and init scripts", + "redisio::enable": "This recipe is used to start the redis instances and enable them in the default run levels", + "redisio::disable": "this recipe is used to stop the redis instances and disable them in the default run levels", + "redisio::redis_gem": "this recipe will install the redis ruby gem into the system ruby" + }, + "version": "1.1.0" +} \ No newline at end of file diff --git a/redisio/metadata.rb b/redisio/metadata.rb new file mode 100644 index 0000000..335ecb4 --- /dev/null +++ b/redisio/metadata.rb @@ -0,0 +1,17 @@ +name 'redisio' +maintainer 'Brian Bianco' +maintainer_email 'brian.bianco@gmail.com' +license 'Apache 2.0' +description 'Installs/Configures redis' +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +version '1.1.0' +%w[ debian ubuntu centos redhat fedora scientific suse amazon].each do |os| + supports os +end + +recipe "redisio", "This recipe is used to install the prequisites for building and installing redis, as well as provides the LWRPs" +recipe "redisio::install", "This recipe is used to install redis and create the configuration files and init scripts" +recipe "redisio::uninstall", "This recipe is used to uninstall the redis binaries as well as optionally the configuration files and init scripts" +recipe "redisio::enable", "This recipe is used to start the redis instances and enable them in the default run levels" +recipe "redisio::disable", "this recipe is used to stop the redis instances and disable them in the default run levels" +recipe "redisio::redis_gem", "this recipe will install the redis ruby gem into the system ruby" diff --git a/redisio/providers/install.rb b/redisio/providers/install.rb new file mode 100644 index 0000000..9e527c0 --- /dev/null +++ b/redisio/providers/install.rb @@ -0,0 +1,216 @@ +# +# Cookbook Name:: redisio +# Provider::install +# +# Copyright 2012, Brian Bianco +# +# 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. +# + +action :run do + @tarball = "#{new_resource.base_name}#{new_resource.version}.#{new_resource.artifact_type}" + + unless ( current_resource.version == new_resource.version || (redis_exists? && new_resource.safe_install) ) + Chef::Log.info("Installing Redis #{new_resource.version} from source") + download + unpack + build + install + end + configure +end + +def download + Chef::Log.info("Downloading redis tarball from #{new_resource.download_url}") + remote_file "#{new_resource.download_dir}/#{@tarball}" do + source new_resource.download_url + end +end + +def unpack + case new_resource.artifact_type + when "tar.gz",".tgz" + execute "cd #{new_resource.download_dir} && tar zxf #{@tarball}" + else + raise Chef::Exceptions::UnsupportedAction, "Current package type #{new_resource.artifact_type} is unsupported" + end +end + +def build + execute"cd #{new_resource.download_dir}/#{new_resource.base_name}#{new_resource.version} && make clean && make" +end + +def install + execute "cd #{new_resource.download_dir}/#{new_resource.base_name}#{new_resource.version} && make install" + new_resource.updated_by_last_action(true) +end + +def configure + base_piddir = new_resource.base_piddir + version_hash = RedisioHelper.version_to_hash(new_resource.version) + + #Setup a configuration file and init script for each configuration provided + new_resource.servers.each do |current_instance| + + #Retrieve the default settings hash and the current server setups settings hash. + current_instance_hash = current_instance.to_hash + current_defaults_hash = new_resource.default_settings.to_hash + + #Merge the configuration defaults with the provided array of configurations provided + current = current_defaults_hash.merge(current_instance_hash) + + recipe_eval do + piddir = "#{base_piddir}/#{current['port']}" + aof_file = "#{current['datadir']}/appendonly-#{current['port']}.aof" + rdb_file = "#{current['datadir']}/dump-#{current['port']}.rdb" + + #Create the owner of the redis data directory + user current['user'] do + comment 'Redis service account' + supports :manage_home => true + home current['homedir'] + shell current['shell'] + end + #Create the redis configuration directory + directory current['configdir'] do + owner 'root' + group 'root' + mode '0755' + recursive true + action :create + end + #Create the instance data directory + directory current['datadir'] do + owner current['user'] + group current['group'] + mode '0775' + recursive true + action :create + end + #Create the pid file directory + directory piddir do + owner current['user'] + group current['group'] + mode '0755' + recursive true + action :create + end + #Create the log directory if syslog is not being used + directory ::File.dirname("#{current['logfile']}") do + owner current['user'] + group current['group'] + mode '0755' + recursive true + action :create + only_if { current['syslogenabled'] != 'yes' && current['logfile'] && current['logfile'] != 'stdout' } + end + #Create the log file is syslog is not being used + file current['logfile'] do + owner current['user'] + group current['group'] + mode '0644' + backup false + action :touch + only_if { current['logfile'] && current['logfile'] != 'stdout' } + end + #Set proper permissions on the AOF or RDB files + file aof_file do + owner current['user'] + group current['group'] + mode '0644' + only_if { current['backuptype'] == 'aof' || current['backuptype'] == 'both' } + only_if { ::File.exists?(aof_file) } + end + file rdb_file do + owner current['user'] + group current['group'] + mode '0644' + only_if { current['backuptype'] == 'rdb' || current['backuptype'] == 'both' } + only_if { ::File.exists?(rdb_file) } + end + #Lay down the configuration files for the current instance + template "#{current['configdir']}/#{current['port']}.conf" do + source 'redis.conf.erb' + owner current['user'] + group current['group'] + mode '0644' + variables({ + :version => version_hash, + :piddir => piddir, + :port => current['port'], + :address => current['address'], + :databases => current['databases'], + :backuptype => current['backuptype'], + :datadir => current['datadir'], + :timeout => current['timeout'], + :loglevel => current['loglevel'], + :logfile => current['logfile'], + :syslogenabled => current['syslogenabled'], + :syslogfacility => current['syslogfacility'], + :save => current['save'], + :slaveof => current['slaveof'], + :masterauth => current['masterauth'], + :slaveservestaledata => current['slaveservestaledata'], + :replpingslaveperiod => current['replpingslaveperiod'], + :repltimeout => current['repltimeout'], + :requirepass => current['requirepass'], + :maxclients => current['maxclients'], + :maxmemory => current['maxmemory'], + :maxmemorypolicy => current['maxmemorypolicy'], + :maxmemorysamples => current['maxmemorysamples'], + :appendfsync => current['appendfsync'], + :noappendfsynconrewrite => current['noappendfsynconrewrite'], + :aofrewritepercentage => current['aofrewritepercentage'] , + :aofrewriteminsize => current['aofrewriteminsize'], + :includes => current['includes'] + }) + end + #Setup init.d file + template "/etc/init.d/redis#{current['port']}" do + source 'redis.init.erb' + owner 'root' + group 'root' + mode '0755' + variables({ + :port => current['port'], + :user => current['user'], + :configdir => current['configdir'], + :piddir => piddir, + :requirepass => current['requirepass'], + :platform => node['platform'] + }) + end + end + end # servers each loop +end + +def redis_exists? + exists = Chef::ShellOut.new("which redis-server") + exists.run_command + exists.exitstatus == 0 ? true : false +end + +def version + if redis_exists? + redis_version = Chef::ShellOut.new("redis-server -v | cut -d ' ' -f 4") + redis_version.run_command + return redis_version.stdout.gsub("\n",'') + end + nil +end + +def load_current_resource + @current_resource = Chef::Resource::RedisioInstall.new(new_resource.name) + @current_resource.version(version) + @current_resource +end diff --git a/redisio/providers/service.rb b/redisio/providers/service.rb new file mode 100644 index 0000000..8d37cb7 --- /dev/null +++ b/redisio/providers/service.rb @@ -0,0 +1,87 @@ +# +# Cookbook Name:: redisio +# Provider::service +# +# Copyright 2012, Brian Bianco +# +# 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. +# + +action :start do + case node.platform + when 'ubuntu','debian','centos','redhat','fedora' + if ::File.exists?("/etc/init.d/redis#{new_resource.server_port}") + execute "/etc/init.d/redis#{new_resource.server_port} start" + else + Chef::Log.warn("Cannot start service, init script does not exist") + end + end +end + +action :stop do + case node.platform + when 'ubuntu','debian','centos','redhat','fedora' + if ::File.exists?("/etc/init.d/redis#{new_resource.server_port}") + execute "/etc/init.d/redis#{new_resource.server_port} stop" + else + Chef::Log.warn("Cannot stop service, init script does not exist") + end + end +end + +action :restart do + case node.platform + when 'ubuntu','debian','centos','redhat','fedora' + if ::File.exists?("/etc/init.d/redis#{new_resource.server_port}") + execute "/etc/init.d/redis#{new_resource.server_port} stop && /etc/init.d/redis#{new_resource.server_port} start" + else + Chef::Log.warn("Cannot restart service, init script does not exist") + end + end +end + +action :enable do + case node.platform + when 'ubuntu','debian' + if ::File.exists?("/etc/init.d/redis#{new_resource.server_port}") + execute "update-rc.d redis#{new_resource.server_port} start 91 2 3 4 5 . stop 91 0 1 6 ." + else + Chef::Log.warn("Cannot enable service, init script does not exist") + end + when 'redhat','centos','fedora','scientific','amazon','suse' + if ::File.exists?("/etc/init.d/redis#{new_resource.server_port}") + execute "chkconfig --add redis#{new_resource.server_port} && chkconfig --level 2345 redis#{new_resource.server_port} on" + else + Chef::Log.warn("Cannot enable service, init script does not exist") + end + end +end + +action :disable do + case node.platform + when 'ubuntu','debian' + if ::File.exists?("/etc/init.d/redis#{new_resource.server_port}") + execute "update-rc.d -f redis#{new_resource.server_port} remove" + else + Chef::Log.warn("Cannot disable service, init script does not exist") + end + + when 'redhat','centos','fedora','scientific','amazon','suse' + if ::File.exists?("/etc/init.d/redis#{new_resource.server_port}") + execute "chkconfig --level 2345 redis#{new_resource.server_port} off && chkconfig --del redis#{new_resource.server_port}" + else + Chef::Log.warn("Cannot disable service, init script does not exist") + end + end + +end diff --git a/redisio/providers/uninstall.rb b/redisio/providers/uninstall.rb new file mode 100644 index 0000000..f16a0a8 --- /dev/null +++ b/redisio/providers/uninstall.rb @@ -0,0 +1,31 @@ +# +# Cookbook Name:: redisio +# Provider::uninstall +# +# Copyright 2012, Brian Bianco +# +# 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. +# + +action :run do + #remove redis binaries + execute "rm -rf /usr/local/bin/redis*" if ::File.exists?("/usr/local/bin/redis-server") + + #remove configuration file and init script for servers provided + unless new_resource.servers.nil? + new_resource.servers.each do |server| + execute "rm -rf /etc/redis/#{server['port']}.conf" if ::File.exists?("/etc/redis/#{server['port']}.conf") + execute "rm -rf /etc/init.d/redis#{server['port']}" if ::File.exists?("/etc/init.d/redis#{server['port']}") + end + end +end diff --git a/redisio/recipes/default.rb b/redisio/recipes/default.rb new file mode 100644 index 0000000..91b9a09 --- /dev/null +++ b/redisio/recipes/default.rb @@ -0,0 +1,34 @@ +# +# Cookbook Name:: redisio +# Recipe:: default +# +# Copyright 2012, Brian Bianco +# +# 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. +# + +case node.platform +when 'debian','ubuntu' + %w[tar build-essential].each do |pkg| + package pkg do + action :install + end + end +when 'redhat','centos','fedora','scientific','suse','amazon' + %w[tar make automake gcc].each do |pkg| + package pkg do + action :install + end + end +end + diff --git a/redisio/recipes/disable.rb b/redisio/recipes/disable.rb new file mode 100644 index 0000000..4e66c96 --- /dev/null +++ b/redisio/recipes/disable.rb @@ -0,0 +1,28 @@ +# +# Cookbook Name:: redisio +# Recipe:: disable +# +# Copyright 2012, Brian Bianco +# +# +# 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. +# + +redis = node['redisio'] + +redis['servers'].each do |current_server| + redisio_service "#{current_server['port']}" do + action [:stop,:disable] + end +end + diff --git a/redisio/recipes/enable.rb b/redisio/recipes/enable.rb new file mode 100644 index 0000000..bfb66f0 --- /dev/null +++ b/redisio/recipes/enable.rb @@ -0,0 +1,29 @@ +# +# Cookbook Name:: redisio +# Recipe:: enable +# +# Copyright 2012, Brian Bianco +# +# +# 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. +# + +redis = node['redisio'] + +redis['servers'].each do |current_server| + Chef::Log.info("Enabling redis_#{current_server['port']}") + redisio_service "#{current_server['port']}" do + action [:start,:enable] + end +end + diff --git a/redisio/recipes/install.rb b/redisio/recipes/install.rb new file mode 100644 index 0000000..b593187 --- /dev/null +++ b/redisio/recipes/install.rb @@ -0,0 +1,32 @@ +# +# Cookbook Name:: redisio +# Recipe:: install +# +# Copyright 2012, Brian Bianco +# +# 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. +# +include_recipe 'redisio::default' + +redis = node['redisio'] +location = "#{redis['mirror']}/#{redis['base_name']}#{redis['version']}.#{redis['artifact_type']}" + +redisio_install "redis-servers" do + version redis['version'] + download_url location + default_settings redis['default_settings'] + servers redis['servers'] + safe_install redis['safe_install'] + base_piddir redis['base_piddir'] +end + diff --git a/redisio/recipes/redis_gem.rb b/redisio/recipes/redis_gem.rb new file mode 100644 index 0000000..36d38a0 --- /dev/null +++ b/redisio/recipes/redis_gem.rb @@ -0,0 +1,23 @@ +# +# Cookbook Name:: redisio +# Recipe:: redis_gem +# +# Copyright 2012, Brian Bianco +# +# 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. +# + +gem_package node['redisio']['gem']['name'] do + version node['redisio']['gem']['version'] unless node['redisio']['gem']['version'].nil? + action :install +end diff --git a/redisio/recipes/uninstall.rb b/redisio/recipes/uninstall.rb new file mode 100644 index 0000000..da8f5b8 --- /dev/null +++ b/redisio/recipes/uninstall.rb @@ -0,0 +1,25 @@ +# +# Cookbook Name:: redisio +# Recipe:: uninstall +# +# Copyright 2012, Brian Bianco +# +# 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. +# + +redis = node['redisio'] + +redisio_uninstall "redis-servers" do + servers redis['servers'] + action :run +end diff --git a/redisio/resources/install.rb b/redisio/resources/install.rb new file mode 100644 index 0000000..22f19f2 --- /dev/null +++ b/redisio/resources/install.rb @@ -0,0 +1,45 @@ +# +# Cookbook Name:: redisio +# Resource::install +# +# Copyright 2012, Brian Bianco +# +# 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. +# +actions :run + +#Uncomment this and remove the block in initialize when ready to drop support for chef <= 0.10.8 +#default_action :run + +#Installation attributes +attribute :version, :kind_of => String +attribute :download_url, :kind_of => String +attribute :download_dir, :kind_of => String, :default => Chef::Config[:file_cache_path] +attribute :artifact_type, :kind_of => String, :default => 'tar.gz' +attribute :base_name, :kind_of => String, :default => 'redis-' +attribute :safe_install, :kind_of => [ TrueClass, FalseClass ], :default => true +attribute :base_piddir, :kind_of => String, :default => '/var/run/redis' + +#Configuration attributes +attribute :user, :kind_of => String, :default => 'redis' +attribute :group, :kind_of => String, :default => 'redis' + +attribute :default_settings, :kind_of => Hash +attribute :servers, :kind_of => Array + +def initialize(name, run_context=nil) + super + @action = :run + @tarball = nil +end + diff --git a/redisio/resources/service.rb b/redisio/resources/service.rb new file mode 100644 index 0000000..ddac2cc --- /dev/null +++ b/redisio/resources/service.rb @@ -0,0 +1,27 @@ +# +# Cookbook Name:: redisio +# Resource::service +# +# Copyright 2012, Brian Bianco +# +# 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. +# + +actions :start, :stop, :restart, :enable, :disable + +attribute :server_port, :name_attribute => true + +def initialize(name, run_context=nil) + super + @action = :start +end diff --git a/redisio/resources/uninstall.rb b/redisio/resources/uninstall.rb new file mode 100644 index 0000000..53065db --- /dev/null +++ b/redisio/resources/uninstall.rb @@ -0,0 +1,28 @@ +# +# Cookbook Name:: redisio +# Resource::uninstall +# +# Copyright 2012, Brian Bianco +# +# 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. +# + +actions :run, :nothing + +attribute :servers, :kind_of => Array, :default => nil + +def initialize(name, run_context=nil) + super + @action = :nothing +end + diff --git a/redisio/templates/default/redis.conf.erb b/redisio/templates/default/redis.conf.erb new file mode 100644 index 0000000..f95538e --- /dev/null +++ b/redisio/templates/default/redis.conf.erb @@ -0,0 +1,526 @@ +# Redis configuration file example + +# Note on units: when memory size is needed, it is possible to specifiy +# it in the usual form of 1k 5GB 4M and so forth: +# +# 1k => 1000 bytes +# 1kb => 1024 bytes +# 1m => 1000000 bytes +# 1mb => 1024*1024 bytes +# 1g => 1000000000 bytes +# 1gb => 1024*1024*1024 bytes +# +# units are case insensitive so 1GB 1Gb 1gB are all the same. + +# By default Redis does not run as a daemon. Use 'yes' if you need it. +# Note that Redis will write a pid file in /var/run/redis.pid when daemonized. +daemonize yes + +# When running daemonized, Redis writes a pid file in /var/run/redis.pid by +# default. You can specify a custom pid file location here. +pidfile <%= @piddir %>/redis_<%=@port%>.pid + +# Accept connections on the specified port, default is 6379. +# If port 0 is specified Redis will not listen on a TCP socket. +port <%=@port%> + +# If you want you can bind a single interface, if the bind option is not +# specified all the interfaces will listen for incoming connections. +# +# bind 127.0.0.1 +<%= "bind #{@address}" unless @address.nil? %> + +# Specify the path for the unix socket that will be used to listen for +# incoming connections. There is no default, so Redis will not listen +# on a unix socket when not specified. +# +# unixsocket /tmp/redis.sock +# unixsocketperm 755 +# Close the connection after a client is idle for N seconds (0 to disable) +<%= "timeout #{@timeout}" %> + +# Set server verbosity to 'debug' +# it can be one of: +# debug (a lot of information, useful for development/testing) +# verbose (many rarely useful info, but not a mess like the debug level) +# notice (moderately verbose, what you want in production probably) +# warning (only very important / critical messages are logged) +loglevel <%=@loglevel%> + +# Specify the log file name. Also 'stdout' can be used to force +# Redis to log on the standard output. Note that if you use standard +# output for logging but daemonize, logs will be sent to /dev/null +# +# logfile stdout +<%= "logfile #{@logfile}" unless @logfile.nil? %> + +# To enable logging to the system logger, just set 'syslog-enabled' to yes, +# and optionally update the other syslog parameters to suit your needs. +syslog-enabled <%= "#{@syslogenabled}" %> + +# Specify the syslog identity. +syslog-ident redis-<%=@port%> + +# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7. +syslog-facility <%= "#{@syslogfacility}" %> + +# Set the number of databases. The default database is DB 0, you can select +# a different one on a per-connection basis using SELECT where +# dbid is a number between 0 and 'databases'-1 +databases <%=@databases%> + +################################ SNAPSHOTTING ################################# +# +# Save the DB on disk: +# +# save +# +# Will save the DB if both the given number of seconds and the given +# number of write operations against the DB occurred. +# +# In the example below the behaviour will be to save: +# after 900 sec (15 min) if at least 1 key changed +# after 300 sec (5 min) if at least 10 keys changed +# after 60 sec if at least 10000 keys changed +# +# Note: you can disable saving at all commenting all the "save" lines. + +#save 900 1 +#save 300 10 +#save 60 10000 + +<% if (@backuptype == 'rdb' || @backuptype == 'both') %> + <% @save.each do |save_option| %> + <%= "save #{save_option}" %> + <% end %> + +# Compress string objects using LZF when dump .rdb databases? +# For default that's set to 'yes' as it's almost always a win. +# If you want to save some CPU in the saving child set it to 'no' but +# the dataset will likely be bigger if you have compressible values or keys. +rdbcompression yes + +# The filename where to dump the DB +dbfilename dump-<%=@port%>.rdb +<%end%> + +# The working directory. +# +# The DB will be written inside this directory, with the filename specified +# above using the 'dbfilename' configuration directive. +# +# Also the Append Only File will be created inside this directory. +# +# Note that you must specify a directory here, not a file name. +dir <%=@datadir%> + +################################# REPLICATION ################################# + +# Master-Slave replication. Use slaveof to make a Redis instance a copy of +# another Redis server. Note that the configuration is local to the slave +# so for example it is possible to configure the slave to save the DB with a +# different interval, or to listen to another port, and so on. +# +# slaveof +<%= "slaveof #{@slaveof['address']} #{@slaveof['port']}" unless @slaveof.nil? %> + +# If the master is password protected (using the "requirepass" configuration +# directive below) it is possible to tell the slave to authenticate before +# starting the replication synchronization process, otherwise the master will +# refuse the slave request. +# +# masterauth +<%= "masterauth #{@masterauth}" unless @masterauth.nil? %> + +# When a slave lost the connection with the master, or when the replication +# is still in progress, the slave can act in two different ways: +# +# 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will +# still reply to client requests, possibly with out of data data, or the +# data set may just be empty if this is the first synchronization. +# +# 2) if slave-serve-stale data is set to 'no' the slave will reply with +# an error "SYNC with master in progress" to all the kind of commands +# but to INFO and SLAVEOF. +# +slave-serve-stale-data <%=@slaveservestaledata%> + +# Slaves send PINGs to server in a predefined interval. It's possible to change +# this interval with the repl_ping_slave_period option. The default value is 10 +# seconds. +# +repl-ping-slave-period <%=@replpingslaveperiod%> + +# The following option sets a timeout for both Bulk transfer I/O timeout and +# master data or ping response timeout. The default value is 60 seconds. +# +# It is important to make sure that this value is greater than the value +# specified for repl-ping-slave-period otherwise a timeout will be detected +# every time there is low traffic between the master and the slave. +# +repl-timeout <%=@repltimeout%> + +################################## SECURITY ################################### + +# Require clients to issue AUTH before processing any other +# commands. This might be useful in environments in which you do not trust +# others with access to the host running redis-server. +# +# This should stay commented out for backward compatibility and because most +# people do not need auth (e.g. they run their own servers). +# +# Warning: since Redis is pretty fast an outside user can try up to +# 150k passwords per second against a good box. This means that you should +# use a very strong password otherwise it will be very easy to break. +# +# requirepass foobared +<%= "requirepass #{@requirepass}" unless @requirepass.nil? %> + +# Command renaming. +# +# It is possilbe to change the name of dangerous commands in a shared +# environment. For instance the CONFIG command may be renamed into something +# of hard to guess so that it will be still available for internal-use +# tools but not available for general clients. +# +# Example: +# +# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52 +# +# It is also possilbe to completely kill a command renaming it into +# an empty string: +# +# rename-command CONFIG "" + +################################### LIMITS #################################### + +# Set the max number of connected clients at the same time. By default there +# is no limit, and it's up to the number of file descriptors the Redis process +# is able to open. The special value '0' means no limits. +# Once the limit is reached Redis will close all the new connections sending +# an error 'max number of clients reached'. +# +<%= "maxclients #{@maxclients}" %> + +# Don't use more memory than the specified amount of bytes. +# When the memory limit is reached Redis will try to remove keys +# accordingly to the eviction policy selected (see maxmemmory-policy). +# +# If Redis can't remove keys according to the policy, or if the policy is +# set to 'noeviction', Redis will start to reply with errors to commands +# that would use more memory, like SET, LPUSH, and so on, and will continue +# to reply to read-only commands like GET. +# +# This option is usually useful when using Redis as an LRU cache, or to set +# an hard memory limit for an instance (using the 'noeviction' policy). +# +# WARNING: If you have slaves attached to an instance with maxmemory on, +# the size of the output buffers needed to feed the slaves are subtracted +# from the used memory count, so that network problems / resyncs will +# not trigger a loop where keys are evicted, and in turn the output +# buffer of slaves is full with DELs of keys evicted triggering the deletion +# of more keys, and so forth until the database is completely emptied. +# +# In short... if you have slaves attached it is suggested that you set a lower +# limit for maxmemory so that there is some free RAM on the system for slave +# output buffers (but this is not needed if the policy is 'noeviction'). +# +#maxmemory +<%= "maxmemory #{@maxmemory}" unless @maxmemory.nil? %> + +# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory +# is reached? You can select among five behavior: +# +# volatile-lru -> remove the key with an expire set using an LRU algorithm +# allkeys-lru -> remove any key accordingly to the LRU algorithm +# volatile-random -> remove a random key with an expire set +# allkeys->random -> remove a random key, any key +# volatile-ttl -> remove the key with the nearest expire time (minor TTL) +# noeviction -> don't expire at all, just return an error on write operations +# +# Note: with all the kind of policies, Redis will return an error on write +# operations, when there are not suitable keys for eviction. +# +# At the date of writing this commands are: set setnx setex append +# incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd +# sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby +# zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby +# getset mset msetnx exec sort +# +# The default is: +# +# maxmemory-policy volatile-lru +<%= "maxmemory-policy #{@maxmemorypolicy}" unless @maxmemorypolicy.nil? %> + +# LRU and minimal TTL algorithms are not precise algorithms but approximated +# algorithms (in order to save memory), so you can select as well the sample +# size to check. For instance for default Redis will check three keys and +# pick the one that was used less recently, you can change the sample size +# using the following configuration directive. +# +# maxmemory-samples 3 +maxmemory-samples <%=@maxmemorysamples%> + +############################## APPEND ONLY MODE ############################### + +# By default Redis asynchronously dumps the dataset on disk. If you can live +# with the idea that the latest records will be lost if something like a crash +# happens this is the preferred way to run Redis. If instead you care a lot +# about your data and don't want to that a single record can get lost you should +# enable the append only mode: when this mode is enabled Redis will append +# every write operation received in the file appendonly.aof. This file will +# be read on startup in order to rebuild the full dataset in memory. +# +# Note that you can have both the async dumps and the append only file if you +# like (you have to comment the "save" statements above to disable the dumps). +# Still if append only mode is enabled Redis will load the data from the +# log file at startup ignoring the dump.rdb file. +# +# IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append +# log file in background when it gets too big. + +<%if (@backuptype == 'aof' || @backuptype == 'both')%> +appendonly yes +<%else%> +appendonly no +<%end%> +# The name of the append only file (default: "appendonly.aof") +appendfilename appendonly-<%=@port%>.aof + +# The fsync() call tells the Operating System to actually write data on disk +# instead to wait for more data in the output buffer. Some OS will really flush +# data on disk, some other OS will just try to do it ASAP. +# +# Redis supports three different modes: +# +# no: don't fsync, just let the OS flush the data when it wants. Faster. +# always: fsync after every write to the append only log . Slow, Safest. +# everysec: fsync only if one second passed since the last fsync. Compromise. +# +# The default is "everysec" that's usually the right compromise between +# speed and data safety. It's up to you to understand if you can relax this to +# "no" that will will let the operating system flush the output buffer when +# it wants, for better performances (but if you can live with the idea of +# some data loss consider the default persistence mode that's snapshotting), +# or on the contrary, use "always" that's very slow but a bit safer than +# everysec. +# +# If unsure, use "everysec". + +# appendfsync always +# appendfsync everysec +# appendfsync no +<%= "appendfsync #{@appendfsync}" %> + +# When the AOF fsync policy is set to always or everysec, and a background +# saving process (a background save or AOF log background rewriting) is +# performing a lot of I/O against the disk, in some Linux configurations +# Redis may block too long on the fsync() call. Note that there is no fix for +# this currently, as even performing fsync in a different thread will block +# our synchronous write(2) call. +# +# In order to mitigate this problem it's possible to use the following option +# that will prevent fsync() from being called in the main process while a +# BGSAVE or BGREWRITEAOF is in progress. +# +# This means that while another child is saving the durability of Redis is +# the same as "appendfsync none", that in pratical terms means that it is +# possible to lost up to 30 seconds of log in the worst scenario (with the +# default Linux settings). +# +# If you have latency problems turn this to "yes". Otherwise leave it as +# "no" that is the safest pick from the point of view of durability. +no-appendfsync-on-rewrite <%=@noappendfsynconrewrite%> + +# Automatic rewrite of the append only file. +# Redis is able to automatically rewrite the log file implicitly calling +# BGREWRITEAOF when the AOF log size will growth by the specified percentage. +# +# This is how it works: Redis remembers the size of the AOF file after the +# latest rewrite (or if no rewrite happened since the restart, the size of +# the AOF at startup is used). +# +# This base size is compared to the current size. If the current size is +# bigger than the specified percentage, the rewrite is triggered. Also +# you need to specify a minimal size for the AOF file to be rewritten, this +# is useful to avoid rewriting the AOF file even if the percentage increase +# is reached but it is still pretty small. +# +# Specify a precentage of zero in order to disable the automatic AOF +# rewrite feature. + +auto-aof-rewrite-percentage <%=@aofrewritepercentage%> +auto-aof-rewrite-min-size <%=@aofrewriteminsize%> + +################################## SLOW LOG ################################### + +# The Redis Slow Log is a system to log queries that exceeded a specified +# execution time. The execution time does not include the I/O operations +# like talking with the client, sending the reply and so forth, +# but just the time needed to actually execute the command (this is the only +# stage of command execution where the thread is blocked and can not serve +# other requests in the meantime). +# +# You can configure the slow log with two parameters: one tells Redis +# what is the execution time, in microseconds, to exceed in order for the +# command to get logged, and the other parameter is the length of the +# slow log. When a new command is logged the oldest one is removed from the +# queue of logged commands. + +# The following time is expressed in microseconds, so 1000000 is equivalent +# to one second. Note that a negative number disables the slow log, while +# a value of zero forces the logging of every command. +slowlog-log-slower-than 10000 + +# There is no limit to this length. Just be aware that it will consume memory. +# You can reclaim memory used by the slow log with SLOWLOG RESET. +slowlog-max-len 1024 + +<% unless @version[:major].to_i == 2 && @version[:minor].to_i >= 5 %> +################################ VIRTUAL MEMORY ############################### + +### WARNING! Virtual Memory is deprecated in Redis 2.4 +### The use of Virtual Memory is strongly discouraged. + +# Virtual Memory allows Redis to work with datasets bigger than the actual +# amount of RAM needed to hold the whole dataset in memory. +# In order to do so very used keys are taken in memory while the other keys +# are swapped into a swap file, similarly to what operating systems do +# with memory pages. +# +# To enable VM just set 'vm-enabled' to yes, and set the following three +# VM parameters accordingly to your needs. + +vm-enabled no +# vm-enabled yes + +# This is the path of the Redis swap file. As you can guess, swap files +# can't be shared by different Redis instances, so make sure to use a swap +# file for every redis process you are running. Redis will complain if the +# swap file is already in use. +# +# The best kind of storage for the Redis swap file (that's accessed at random) +# is a Solid State Disk (SSD). +# +# *** WARNING *** if you are using a shared hosting the default of putting +# the swap file under /tmp is not secure. Create a dir with access granted +# only to Redis user and configure Redis to create the swap file there. +vm-swap-file /tmp/redis.swap + +# vm-max-memory configures the VM to use at max the specified amount of +# RAM. Everything that deos not fit will be swapped on disk *if* possible, that +# is, if there is still enough contiguous space in the swap file. +# +# With vm-max-memory 0 the system will swap everything it can. Not a good +# default, just specify the max amount of RAM you can in bytes, but it's +# better to leave some margin. For instance specify an amount of RAM +# that's more or less between 60 and 80% of your free RAM. +vm-max-memory 0 + +# Redis swap files is split into pages. An object can be saved using multiple +# contiguous pages, but pages can't be shared between different objects. +# So if your page is too big, small objects swapped out on disk will waste +# a lot of space. If you page is too small, there is less space in the swap +# file (assuming you configured the same number of total swap file pages). +# +# If you use a lot of small objects, use a page size of 64 or 32 bytes. +# If you use a lot of big objects, use a bigger page size. +# If unsure, use the default :) +vm-page-size 32 + +# Number of total memory pages in the swap file. +# Given that the page table (a bitmap of free/used pages) is taken in memory, +# every 8 pages on disk will consume 1 byte of RAM. +# +# The total swap size is vm-page-size * vm-pages +# +# With the default of 32-bytes memory pages and 134217728 pages Redis will +# use a 4 GB swap file, that will use 16 MB of RAM for the page table. +# +# It's better to use the smallest acceptable value for your application, +# but the default is large in order to work in most conditions. +vm-pages 134217728 + +# Max number of VM I/O threads running at the same time. +# This threads are used to read/write data from/to swap file, since they +# also encode and decode objects from disk to memory or the reverse, a bigger +# number of threads can help with big objects even if they can't help with +# I/O itself as the physical device may not be able to couple with many +# reads/writes operations at the same time. +# +# The special value of 0 turn off threaded I/O and enables the blocking +# Virtual Memory implementation. +vm-max-threads 4 +<% end %> + +############################### ADVANCED CONFIG ############################### + +# Hashes are encoded using a memory efficient data structure when they have a +# small number of entries, and the biggest entry does not exceed a given +# threshold. These thresholds can be configured using the following directives. + +<% #Once the first official 2.6 release is out, it would make sense to remove the extraneous :minor 5 comparison %> +<% if @version[:major].to_i == 2 && (@version[:minor].to_i == 6 || @version[:minor].to_i == 5) %> + ######## Redis 2.6 ######## + hash-max-ziplist-entries 512 + hash-max-ziplist-value 64 +<% elsif @version[:major].to_i == 2 && @version[:minor].to_i == 4 %> + ######## Redis 2.4 ######## + hash-max-zipmap-entries 512 + hash-max-zipmap-value 64 +<% end %> + +# Similarly to hashes, small lists are also encoded in a special way in order +# to save a lot of space. The special representation is only used when +# you are under the following limits: +list-max-ziplist-entries 512 +list-max-ziplist-value 64 + +# Sets have a special encoding in just one case: when a set is composed +# of just strings that happens to be integers in radix 10 in the range +# of 64 bit signed integers. +# The following configuration setting sets the limit in the size of the +# set in order to use this special memory saving encoding. +set-max-intset-entries 512 + +# Similarly to hashes and lists, sorted sets are also specially encoded in +# order to save a lot of space. This encoding is only used when the length and +# elements of a sorted set are below the following limits: +zset-max-ziplist-entries 128 +zset-max-ziplist-value 64 + +# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in +# order to help rehashing the main Redis hash table (the one mapping top-level +# keys to values). The hash table implementation redis uses (see dict.c) +# performs a lazy rehashing: the more operation you run into an hash table +# that is rhashing, the more rehashing "steps" are performed, so if the +# server is idle the rehashing is never complete and some more memory is used +# by the hash table. +# +# The default is to use this millisecond 10 times every second in order to +# active rehashing the main dictionaries, freeing memory when possible. +# +# If unsure: +# use "activerehashing no" if you have hard latency requirements and it is +# not a good thing in your environment that Redis can reply form time to time +# to queries with 2 milliseconds delay. +# +# use "activerehashing yes" if you don't have such hard requirements but +# want to free memory asap when possible. +activerehashing yes + +################################## INCLUDES ################################### + +# Include one or more other config files here. This is useful if you +# have a standard template that goes to all redis server but also need +# to customize a few per-server settings. Include files can include +# other files, so use this wisely. +# +# include /path/to/local.conf +# include /path/to/other.conf +<% unless @includes.nil? %> + <% @includes.each do |include_option| %> + <%= "include #{include_option}" %> + <% end %> +<% end %> + diff --git a/redisio/templates/default/redis.init.erb b/redisio/templates/default/redis.init.erb new file mode 100644 index 0000000..cafb8b9 --- /dev/null +++ b/redisio/templates/default/redis.init.erb @@ -0,0 +1,55 @@ +#!/bin/sh +# +# Simple Redis init.d script conceived to work on Linux systems +# as it does use of the /proc filesystem. +# +# description: Redis is an in memory key-value store database +# +### BEGIN INIT INFO +# Provides: redis<%= @port %> +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: redis<%= @port %> init script +### END INIT INFO + +REDISPORT=<%= @port %> +<% case @platform %> +<% when 'ubuntu','debian','fedora' %> +EXEC="sudo -u <%= @user %> /usr/local/bin/redis-server <%= @configdir %>/${REDISPORT}.conf" +<% else %> +EXEC="runuser <%= @user %> -c \"/usr/local/bin/redis-server <%= @configdir %>/${REDISPORT}.conf\"" +<% end %> +CLIEXEC=/usr/local/bin/redis-cli + +PIDFILE=<%= @piddir %>/redis_${REDISPORT}.pid + +case "$1" in + start) + if [ -f $PIDFILE ] + then + echo "$PIDFILE exists, process is already running or crashed" + else + echo "Starting Redis server..." + eval $EXEC + fi + ;; + stop) + if [ ! -f $PIDFILE ] + then + echo "$PIDFILE does not exist, process is not running" + else + PID=$(cat $PIDFILE) + echo "Stopping ..." + $CLIEXEC -p $REDISPORT<%= @requirepass ? " -a '#{@requirepass}'" : "" %> shutdown + while [ -x /proc/${PID} ] + do + echo "Waiting for Redis to shutdown ..." + sleep 1 + done + echo "Redis stopped" + fi + ;; + *) + echo "Please use start or stop as first argument" + ;; +esac diff --git a/sphinx/README.rdoc b/sphinx/README.rdoc new file mode 100644 index 0000000..cbe2f62 --- /dev/null +++ b/sphinx/README.rdoc @@ -0,0 +1,26 @@ += DESCRIPTION: +Install Sphinx + += REQUIREMENTS: + += ATTRIBUTES: + += USAGE: + += POSTGRESQL +To setup with postgresql support override the sphinx/configure_flags attribute. + +Here is an example of how I do it in one of my cookbook attributes file: + + +include_attribute "sphinx::default" + +set[:sphinx][:configure_flags] = [ + "--with-pgsql", + "--without-mysql", + "#{sphinx[:use_stemmer] ? '--with-stemmer' : '--without-stemmer'}" +] + += History + +0.4 Updated Download URL for sphinx source diff --git a/sphinx/attributes/default.rb b/sphinx/attributes/default.rb new file mode 100644 index 0000000..c6df258 --- /dev/null +++ b/sphinx/attributes/default.rb @@ -0,0 +1,17 @@ +default[:sphinx][:install_path] = "/opt/sphinx" +default[:sphinx][:version] = '0.9.9' +default[:sphinx][:url] = "http://sphinxsearch.com/downloads/sphinx-#{sphinx[:version]}.tar.gz" +default[:sphinx][:stemmer_url] = "http://snowball.tartarus.org/dist/libstemmer_c.tgz" + +# tunable options +default[:sphinx][:use_stemmer] = false +default[:sphinx][:use_mysql] = true +default[:sphinx][:use_postgres] = false + +default[:sphinx][:configure_flags] = [ + "#{sphinx[:use_stemmer] ? '--with-stemmer' : '--without-stemmer'}", + "#{sphinx[:use_mysql] ? '--with-mysql' : '--without-mysql'}", + "#{sphinx[:use_postgres] ? '--with-pgsql' : '--without-pgsql'}" +] + + diff --git a/sphinx/metadata.json b/sphinx/metadata.json new file mode 100644 index 0000000..5fde86c --- /dev/null +++ b/sphinx/metadata.json @@ -0,0 +1,38 @@ +{ + "version": "0.4.0", + "recipes": { + }, + "groupings": { + }, + "recommendations": { + }, + "long_description": "= DESCRIPTION:\nInstall Sphinx\n\n= REQUIREMENTS:\n\n= ATTRIBUTES: \n\n= USAGE:\n\n= POSTGRESQL\nTo setup with postgresql support override the sphinx/configure_flags attribute.\n\nHere is an example of how I do it in one of my cookbook attributes file:\n\n\ninclude_attribute \"sphinx::default\"\n\nset[:sphinx][:configure_flags] = [\n \"--with-pgsql\",\n \"--without-mysql\",\n \"#{sphinx[:use_stemmer] ? '--with-stemmer' : '--without-stemmer'}\"\n]\n\n= History\n\n0.4 Updated Download URL for sphinx source\n", + "attributes": { + }, + "suggestions": { + }, + "dependencies": { + "mysql": [ + + ], + "build-essential": [ + + ], + "postgresql": [ + + ] + }, + "conflicting": { + }, + "license": "Apache 2.0", + "providing": { + }, + "maintainer": "Alex Soto", + "name": "sphinx", + "replacing": { + }, + "platforms": { + }, + "maintainer_email": "apsoto@gmail.com", + "description": "Installs/Configures sphinx search engine." +} \ No newline at end of file diff --git a/sphinx/metadata.rb b/sphinx/metadata.rb new file mode 100644 index 0000000..0d86122 --- /dev/null +++ b/sphinx/metadata.rb @@ -0,0 +1,10 @@ +maintainer "Alex Soto" +maintainer_email "apsoto@gmail.com" +license "Apache 2.0" +description "Installs/Configures sphinx search engine." +long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc')) +version "0.4" + +depends "build-essential" +depends "mysql" +depends "postgresql" diff --git a/sphinx/recipes/default.rb b/sphinx/recipes/default.rb new file mode 100644 index 0000000..1f6d60c --- /dev/null +++ b/sphinx/recipes/default.rb @@ -0,0 +1,58 @@ +# +# Cookbook Name:: sphinx +# Recipe:: default +# +# Copyright 2010, Alex Soto +# +# 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. +# +include_recipe "build-essential" +include_recipe "mysql::client" if node[:sphinx][:use_mysql] +include_recipe "postgresql::client" if node[:sphinx][:use_postgres] + +remote_file "/tmp/sphinx-#{node[:sphinx][:version]}.tar.gz" do + source "#{node[:sphinx][:url]}" + not_if { ::File.exists?("/tmp/sphinx-#{node[:sphinx][:version]}.tar.gz") } +end + +execute "Extract Sphinx source" do + cwd "/tmp" + command "tar -zxvf /tmp/sphinx-#{node[:sphinx][:version]}.tar.gz" + not_if { ::File.exists?("/tmp/sphinx-#{node[:sphinx][:version]}") } +end + +if node[:sphinx][:use_stemmer] + remote_file "/tmp/libstemmer_c.tgz" do + source node[:sphinx][:stemmer_url] + not_if { ::File.exists?("/tmp/libstemmer_c.tgz") } + end + + execute "Extract libstemmer source" do + cwd "/tmp" + command "tar -C /tmp/sphinx-#{node[:sphinx][:version]} -zxf libstemmer_c.tgz" + not_if { ::File.exists?("/tmp/sphinx-#{node[:sphinx][:version]}/libstemmer_c/src_c") } + end +end + +bash "Build and Install Sphinx Search" do + cwd "/tmp/sphinx-#{node[:sphinx][:version]}" + code <<-EOH + ./configure #{node[:sphinx][:configure_flags].join(" ")} + make + make install + EOH + not_if { ::File.exists?("/usr/local/bin/searchd") } + # add additional test to verify of searchd is same as version of sphinx we are installing + # && system("#{node[:sphinx][:install_path]}/bin/ree-version | grep -q '#{node[:sphinx][:version]}$'") +end +