Permalink
Browse files

logrotate improvements from customer work

* markdown is nicer than rdoc
* fix metadata and readme to not refer to apache cookbook
* more flexibility in logrotate_app definition and readme updates
  • Loading branch information...
1 parent 77ef175 commit bf88900bf923ca4cb3a311c7d02cc590a18215c4 @jtimberman jtimberman committed Mar 25, 2011
View
@@ -0,0 +1,72 @@
+DESCRIPTION
+====
+
+Manages the logrotate package and provides a definition to manage application specific logrotate configuration.
+
+REQUIREMENTS
+====
+
+Should work on any platform that includes a 'logrotate' package and writes logrotate configuration to /etc/logrotate.d. Tested on Ubuntu, Debian and Red Hat/CentOS.
+
+DEFINITIONS
+====
+
+* ``logrotate_app``
+
+This definition can be used to drop off customized logrotate config files on a per application basis.
+
+The definition takes the following params:
+
+* path: specifies a single path (string) or multiple paths (array) that should have logrotation stanzas created in the config file. No default, this must be specified.
+* enable: true/false, if true it will create the template in /etc/logrotate.d.
+* frequency: sets the frequency for rotation. Default value is 'weekly'. Valid values are: daily, weekly, monthly, yearly, see the logrotate man page for more information.
+* template: sets the template source, default is "logrotate.erb".
+* cookbook: select the template source from the specified cookbook. By default it will use the cookbook where the definition is used.
+* create: creation parameters for the logrotate "create" config, follows the form "mode owner group".
+
+See USAGE below.
+
+USAGE
+====
+
+The default recipe will ensure logrotate is always up to date.
+
+To create application specific logrotate configs, use the `logrotate_app` definition. For example, to rotate logs for a tomcat application named myapp that writes its log file to /var/log/tomcat/myapp.log:
+
+ logrotate_app "tomcat-myapp" do
+ cookbook "logrotate"
+ path "/var/log/tomcat/myapp.log"
+ frequency "daily"
+ rotate 30
+ create "644 root adm"
+ end
+
+To rotate multiple logfile paths, specify the path as an array:
+
+ logrotate_app "tomcat-myapp" do
+ cookbook "logrotate"
+ path [ "/var/log/tomcat/myapp.log", "/opt/local/tomcat/catalina.out" ]
+ frequency "daily"
+ create "644 root adm"
+ rotate 7
+ end
+
+LICENSE AND AUTHOR
+====
+
+Author:: Scott M. Likens (<scott@likens.us>)
+Author:: Joshua Timberman (<joshua@opscode.com>)
+Copyright:: 2009, Scott M. Likens
+Copyright:: 2011, Opscode, 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.
View
@@ -1,47 +0,0 @@
-= DESCRIPTION:
-
-Logrotate configuration
-
-= REQUIREMENTS:
-
-Debian or Ubuntu preferred.
-
-Red Hat/CentOS and Fedora can be used but will be converted to a Debian/Ubuntu style Apache as it's far easier to manage with chef.
-
-= ATTRIBUTES:
-
-* none
-
-General settings and prefork/worker attributes are tunable.
-
-= USAGE:
-
-include the recipe and it will install a default logrotate, if you want it to do more however...
-
-make a recipe such as,
-
-logrotate_app "chef" do
- paths "/var/log/chef/*.log"
- rotate 4
-end
-
-== Defines:
-
-* logrotate_app:: sets up a logrotate configuration file
-
-= LICENSE & AUTHOR:
-
-Author:: Scott M. Likens (<scott@likens.us>)
-Copyright:: 2009, Scott M. Likens
-
-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.
@@ -17,26 +17,36 @@
# limitations under the License.
#
-define :logrotate_app, :enable => true do
+define :logrotate_app, :enable => true, :frequency => "weekly", :template => "logrotate.erb", :cookbook => "logrotate" do
include_recipe "logrotate"
- if params[:enable]
- template "/etc/logrotate.d/#{params[:name]}" do
- source "logrotate.erb"
- mode 0440
- owner "root"
- group "root"
- backup false
- variables(
- :paths => params[:paths],
- :rotate => params[:rotate]
- )
- end
- else
- execute "rm /etc/logrotate.d/#{params[:name]}" do
+ path = params[:path].respond_to?(:each) ? params[:path] : params[:path].split
+ create = params[:create] ? params[:create] : "644 root adm"
+
+ if params[:enable]
+
+ template "/etc/logrotate.d/#{params[:name]}" do
+ source params[:template]
+ cookbook params[:cookbook]
+ mode 0440
+ owner "root"
+ group "root"
+ backup false
+ variables(
+ :path => path,
+ :create => create,
+ :frequency => params[:frequency],
+ :rotate => params[:rotate]
+ )
+ end
+
+ else
+
+ execute "rm /etc/logrotate.d/#{params[:name]}" do
only_if FileTest.exists?("/etc/logrotate.d/#{params[:name]}")
command "rm /etc/logrotate.d/#{params[:name]}"
- end
end
+
+ end
end
View
@@ -1,42 +1,42 @@
{
- "recommendations": {
- },
- "attributes": {
- },
- "maintainer": "Scott M. Likens",
- "suggestions": {
- },
- "dependencies": {
- },
- "maintainer_email": "scott@likens.us",
- "conflicting": {
- },
- "platforms": {
- "debian": [
+ "name": "logrotate",
+ "description": "Keeps logrotate package updated and has definition for logrotate configs",
+ "long_description": "DESCRIPTION\n====\n\nManages the logrotate package and provides a definition to manage application specific logrotate configuration.\n\nREQUIREMENTS\n====\n\nShould work on any platform that includes a 'logrotate' package and writes logrotate configuration to /etc/logrotate.d. Tested on Ubuntu, Debian and Red Hat/CentOS.\n\nDEFINITIONS\n====\n\n* ``logrotate_app``\n\nThis definition can be used to drop off customized logrotate config files on a per application basis.\n\nThe definition takes the following params:\n\n* path: specifies a single path (string) or multiple paths (array) that should have logrotation stanzas created in the config file. No default, this must be specified.\n* enable: true/false, if true it will create the template in /etc/logrotate.d.\n* frequency: sets the frequency for rotation. Default value is 'weekly'. Valid values are: daily, weekly, monthly, yearly, see the logrotate man page for more information.\n* template: sets the template source, default is \"logrotate.erb\".\n* cookbook: select the template source from the specified cookbook. By default it will use the cookbook where the definition is used.\n* create: creation parameters for the logrotate \"create\" config, follows the form \"mode owner group\".\n\nSee USAGE below.\n\nUSAGE\n====\n\nThe default recipe will ensure logrotate is always up to date.\n\nTo create application specific logrotate configs, use the `logrotate_app` definition. For example, to rotate logs for a tomcat application named myapp that writes its log file to /var/log/tomcat/myapp.log:\n\n logrotate_app \"tomcat-myapp\" do\n cookbook \"logrotate\"\n path \"/var/log/tomcat/myapp.log\"\n frequency \"daily\"\n rotate 30\n create \"644 root adm\"\n end\n\nTo rotate multiple logfile paths, specify the path as an array:\n\n logrotate_app \"tomcat-myapp\" do\n cookbook \"logrotate\"\n path [ \"/var/log/tomcat/myapp.log\", \"/opt/local/tomcat/catalina.out\" ]\n frequency \"daily\"\n create \"644 root adm\"\n rotate 7\n end\n\nLICENSE AND AUTHOR\n====\n\nAuthor:: Scott M. Likens (<scott@likens.us>)\nAuthor:: Joshua Timberman (<joshua@opscode.com>)\nCopyright:: 2009, Scott M. Likens\nCopyright:: 2011, Opscode, Inc.\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",
+ "maintainer": "Opscode, Inc.",
+ "maintainer_email": "cookbooks@opscode.com",
+ "license": "Apache 2.0",
+ "platforms": {
+ "redhat": [
- ],
- "centos": [
+ ],
+ "centos": [
- ],
- "ubuntu": [
+ ],
+ "debian": [
- ],
- "redhat": [
+ ],
+ "ubuntu": [
- ]
- },
- "license": "Apache 2.0",
- "version": "0.8.1",
- "providing": {
- },
- "recipes": {
- "logrotate": "Installs logrotate"
- },
- "replacing": {
- },
- "name": "logrotate",
- "description": "Installs logrotate",
- "groupings": {
- },
- "long_description": "= DESCRIPTION:\n\nLogrotate configuration\n\n= REQUIREMENTS:\n\nDebian or Ubuntu preferred.\n\nRed Hat/CentOS and Fedora can be used but will be converted to a Debian/Ubuntu style Apache as it's far easier to manage with chef. \n\n= ATTRIBUTES:\n\n* none\n\nGeneral settings and prefork/worker attributes are tunable.\n\n= USAGE:\n\ninclude the recipe and it will install a default logrotate, if you want it to do more however...\n\nmake a recipe such as,\n\nlogrotate_app \"chef\" do\n paths \"/var/log/chef/*.log\"\n rotate 4\nend\n\n== Defines:\n\n* logrotate_app:: sets up a logrotate configuration file\n\n= LICENSE & AUTHOR:\n\nAuthor:: Scott M. Likens (<scott@likens.us>)\nCopyright:: 2009, Scott M. Likens\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"
- }
+ ]
+ },
+ "dependencies": {
+ },
+ "recommendations": {
+ },
+ "suggestions": {
+ },
+ "conflicting": {
+ },
+ "providing": {
+ },
+ "replacing": {
+ },
+ "attributes": {
+ },
+ "groupings": {
+ },
+ "recipes": {
+ "logrotate": "Keeps logrotate package updated"
+ },
+ "version": "0.8.2"
+}
View
@@ -1,11 +1,11 @@
-maintainer "Scott M. Likens"
-maintainer_email "scott@likens.us"
+maintainer "Opscode, Inc."
+maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
-description "Installs logrotate"
-long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
-version "0.8.1"
+description "Keeps logrotate package updated and has definition for logrotate configs"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
+version "0.8.2"
-recipe "logrotate", "Installs logrotate"
+recipe "logrotate", "Keeps logrotate package updated"
%w{ redhat centos debian ubuntu }.each do |os|
supports os
@@ -1,9 +1,12 @@
-<%= @paths %> {
- weekly
- missingok
- rotate <%= @rotate %>
- compress
- delaycompress
- copytruncate
+<% @path.each do |p| -%>
+<%= p %> {
+ <%= @frequency %>
+ missingok
+ rotate <%= @rotate %>
+ compress
+ delaycompress
+ copytruncate
+ notifempty
+ create <%= @create %>
}
-
+<% end -%>

0 comments on commit bf88900

Please sign in to comment.