Skip to content

Instantly share code, notes, and snippets.

@stevendanna
stevendanna / gist:5552324
Last active November 30, 2022 07:02
A small chef-solo example

An example cookbook directory

sdanna@gaius ~/tmp/example > tree
.
├── cookbooks
│   └── foobar
│       ├── CHANGELOG.md
│       ├── README.md
│       ├── attributes
│       ├── definitions
@stevendanna
stevendanna / gist:5582647
Last active December 17, 2015 08:49
Foodcritic Exceptions Explanation

Explanation of Foodcritic Exceptions

The following are brief justifications of the foodcritic exceptions being used in the first pass of foodcritic bug-bashing. In most cases we are excluding rules to make the amount of work more manageable for this first pass. In a few cases, the core cookbook team doesn't think that a rule is appropriate for the Opscode community cookbooks.

FC003 Check whether you are running with chef server before using server-specific features

Ensuring that a cookbook works without a Chef Server is often more work than a simple if statement around a call to search. The READMEs for these cookbooks should clearly state that they currently require a Chef Server and adding conditionals throughout a recipe to also account for this limitation often only serves to clutter the recipe.

In the long run, we welcome better support for chef-solo-style use cases.

> cat providers/default.rb
action :start do
ruby_block "foo" do
true
true
true
true
true
true
true
@stevendanna
stevendanna / daemon.rb
Last active October 18, 2018 13:48
"Old School" Ruby Daemon Example Code
#!/usr/bin/env ruby
# What does getrlimit tell us?
# What are we doing here and why?
# If we are on linux, is there a better alternative?
(3).upto(Process.getrlimit(Process::RLIMIT_NOFILE)[0]) do |n|
begin
if(fd = File.for_fd(n))
puts "Closing FD #{n}"
fd.close
@stevendanna
stevendanna / pipe.c
Created March 30, 2014 18:18
Basic pipe implementation
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
int main(int argc, char *argv[]) {
int pipefd[2];
pid_t cpid1;
pid_t cpid2;
ruby_block "dump run_state" do
block do
require 'pp'
pp node.run_state
end
end
whyrun_safe_ruby_block "log" do
block do
Chef::Log.info "foo"
end
end
#!/usr/bin/env bash
#
# Authors:: Chef Support Team <[email protected]>
#
modified_within_last_x_minutes=180
tail_lines=10000
type='EC'
if [[ -n $1 ]];
then
@stevendanna
stevendanna / gist:cc34968e4626eb11bf72
Last active August 29, 2015 14:04
verify monkey-patch
class Chef::Resource::File
def verify(&block)
if block_given?
@verify_block=block
else
@verify_block
end
end
end
sdanna@thrace ~/tmp/foo > irb
irb(main):001:0> Dir.pwd
=> "/Users/sdanna/tmp/foo"
irb(main):002:0>
[1]+ Stopped irb
146 sdanna@thrace ~/tmp/foo > cd
sdanna@thrace ~ > rm -rf ~/tmp/foo
sdanna@thrace ~ > fg
irb (wd: ~/tmp/foo)
Dir.pwd