Undefined method `checksum' for Chef::Resource::Directory - checksum

While running a recipe for Pyramid, the following is failing in chef-solo:
================================================================================
Error executing action `create` on resource 'directory[/etc/service/pyramid/supervise/status]'
================================================================================
NoMethodError
-------------
undefined method `checksum' for Chef::Resource::Directory
Resource Declaration:
---------------------
# In /var/chef-solo/cookbooks/project/recipes/pyramid.rb
22: directory "#{node['runit']['service_dir']}/pyramid#{dir}/supervise/#{f}" do
23: owner login
24: group login
25: end
26: end
Compiled Resource:
------------------
# Declared in /var/chef-solo/cookbooks/project/recipes/pyramid.rb:22:in `block (2 levels) in from_file'
directory("/etc/service/pyramid/supervise/status") do
provider Chef::Provider::Directory
action :create
retries 0
retry_delay 2
path "/etc/service/pyramid/supervise/status"
cookbook_name :project
recipe_name "pyramid"
owner "myusername"
group "myusername"
mode 420
end
Why is this getting "undefined method checksum" and what can I do about it?
This error doesn't appear to be consistent. Sometimes the chef run appears to hang. Other times, after multiple runs, chef is able to pass this point.
I'm running on a vanilla Ubuntu server 12.04LTS with chef installed with a deploy script:
sudo apt-get install -y ruby1.9.1 ruby1.9.1-dev make &&
sudo gem1.9.1 install chef ohai --no-rdoc --no-ri
This is the full Pyramid recipe:
login = node["user"]["login"]
home = node["user"]["home"]
app_root = node["user"]["app_root"]
runit_service "pyramid" do #, :template_name => "site" do
template_name "pyramid"
owner login
group login
options({
:login => login,
:app_root => app_root,
:home => home,
:config => "#{app_root}/config/gunicorn.conf.py"
})
end
["", "/log"].each do |dir|
directory "#{node['runit']['service_dir']}/pyramid#{dir}/supervise" do
mode "0755"
end
%w(ok control status).each do |f|
directory "#{node['runit']['service_dir']}/pyramid#{dir}/supervise/#{f}" do
owner login
group login
end
end
end

This was my solution - found after some hacking around plus the tip from #Draco-ater...
Where the recipe referenced directory("/etc/service/pyramid/supervise/status"), the status 'directory' is a file that already exists which was causing issues.
In addition, the script also tried to update the control and ok pipes as directories - which was also failing. I solved this by using bash and chmod:
bash "give_perms_pyramid" do
user "chef"
cwd "#{node['runit']['service_dir']}/pyramid#{dir}/supervise"
code <<-EOH
sudo chown myuser:root control
sudo chmod g+rw control
EOH
Maybe that will help someone.

Related

STORYBLOK, RUBY: undefined method `[]' for nil:NilClass (NoMethodError)

I don't know that much about RUBY, just thought that you guys might help me with this. I'm using Storyblok as my headless CMS and JEKYLL when I'm building serve it this is the error that I got;
33: from C:/project/test/_plugins/storyblok_generator.rb:8:in `generate'
32: from C:/project/test/_plugins/storyblok_cms/generator.rb:12:in `generate!'
C:/project/test/vendor/cache/ruby/2.7.0/gems/storyblok-3.0.1/lib/storyblok/client.rb:354:in `block (2 levels) in find_and_fill_links': undefined method `[]' for nil:NilClass (NoMethodError)
the code below is from _plugins/storyblok_cms/generator.rb
def generate!
timestamp = Time.now.to_i
links = client.links(cv: timestamp)['data']['links']
stories = client.stories(per_page: 100, page: 1, cv: timestamp)['data']['stories'] #line 12
stories.each do |story|
# create all pages except global (header,footer,etc.)
content_type = story['content']['component']
if content_type != 'shared'
site.pages << create_page(site, story, links)
end
rescue UnknownContentTypeError => e
# for production, raise unknown content type error;
# for preview and other environments, issue an warning only since the content_type might be available
# but the code handling that content type might be in a different branch.
Jekyll.env == 'production' ? raise : Jekyll.logger.warn(e.message)
end
site.data['stories'] = stories
site.data['articles'] = stories.select { |story| story['full_slug'].start_with?('articles') }
site.data['shared'] = stories.select { |story| story['full_slug'].start_with?('shared') }
end
the code below is from _plugins/storyblok_generator.rb
require "storyblok"
module Jekyll
class StoryblokGenerator < Jekyll::Generator
safe true
def generate(site)
StoryblokCms::Generator.new(site).generate! #line 8
end
end
end
Additional Info:
ruby version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x64-mingw32]
jekyll version: jekyll 4.2.1
OS: Windows 10
I've actually found the solution to this, So this error occurs because I have created a page template in Block Library in Storyblok and then firing bundle exec jekyll serve command in terminal without creating the page template source/file in my project directory.
So I have an about_us block (content-type) in Block Library created and then when I fire bundle exec jekyll serve without creating an about_us.html first in _layouts folder, It would trigger the error.
Solution;
Make sure to create the source/file first in the _layouts folder if you have created a block (content-type) in block library.

Ruby / Brew Stopped Working Yosemite

I'm fairly new to this so hang with me..
I have been searching for a solution to this problem for a week now.
Ruby does not seem to be working
ruby
-bash: ruby: command not found
or
ruby -v
-bash: ruby: command not found
and whenever I try homebrew this is what comes back
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 21: /usr/local/Library/brew.rb: Undefined error: 0
as you can see above I had changed the ruby framework to read from 1.8 to Current as others had suggested, however this did not solve the problem as it did for users who had encountered the same issue.
So the search continues on...
My usr/local/bin/brew script looks like this -
#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -W0
# encoding: UTF-8
std_trap = trap("INT") { exit! 130 } # no backtrace thanks
HOMEBREW_BREW_FILE = ENV['HOMEBREW_BREW_FILE']
if ARGV == %w{--prefix}
puts File.dirname(File.dirname(HOMEBREW_BREW_FILE))
exit 0
end
require 'pathname'
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.dirname.parent.join("Library/Homebrew").to_s
$:.unshift(HOMEBREW_LIBRARY_PATH + '/vendor')
$:.unshift(HOMEBREW_LIBRARY_PATH)
require 'global'
case ARGV.first when '-h', '--help', '--usage', '-?', 'help', nil
require 'cmd/help'
puts Homebrew.help_s
exit ARGV.first ? 0 : 1
when '--version'
puts HOMEBREW_VERSION
exit 0
when '-v'
puts "Homebrew #{HOMEBREW_VERSION}"
# Shift the -v to the end of the parameter list
ARGV << ARGV.shift
# If no other arguments, just quit here.
exit 0 if ARGV.length == 1
end
# Check for bad xcode-select before anything else, because `doctor` and
# many other things will hang
# Note that this bug was fixed in 10.9
if OS.mac? && `xcode-select -print-path 2>/dev/null`.chomp == '/' && MacOS.version < :mavericks
ofail <<-EOS.undent
Your xcode-select path is currently set to '/'.
This causes the `xcrun` tool to hang, and can render Homebrew unusable.
If you are using Xcode, you should:
sudo xcode-select -switch /Applications/Xcode.app
Otherwise, you should:
sudo rm -rf /usr/share/xcode-select
EOS
exit 1
end
case HOMEBREW_PREFIX.to_s when '/', '/usr'
# it may work, but I only see pain this route and don't want to support it
abort "Cowardly refusing to continue at this prefix: #{HOMEBREW_PREFIX}"
end
if OS.mac? and MacOS.version < "10.5"
abort <<-EOABORT.undent
Homebrew requires Leopard or higher. For Tiger support, see:
https://github.com/mistydemeo/tigerbrew
EOABORT
end
# Many Pathname operations use getwd when they shouldn't, and then throw
# odd exceptions. Reduce our support burden by showing a user-friendly error.
Dir.getwd rescue abort "The current working directory doesn't exist, cannot proceed."
def require? path
require path.to_s.chomp
rescue LoadError => e
# HACK :( because we should raise on syntax errors but
# not if the file doesn't exist. TODO make robust!
raise unless e.to_s.include? path
end
begin
trap("INT", std_trap) # restore default CTRL-C handler
aliases = {'ls' => 'list',
'homepage' => 'home',
'-S' => 'search',
'up' => 'update',
'ln' => 'link',
'instal' => 'install', # gem does the same
'rm' => 'uninstall',
'remove' => 'uninstall',
'configure' => 'diy',
'abv' => 'info',
'dr' => 'doctor',
'--repo' => '--repository',
'environment' => '--env',
'-c1' => '--config',
}
cmd = ARGV.shift
cmd = aliases[cmd] if aliases[cmd]
sudo_check = Set.new %w[ install link pin unpin upgrade ]
if sudo_check.include? cmd
if Process.uid.zero? and not File.stat(HOMEBREW_BREW_FILE).uid.zero?
raise "Cowardly refusing to `sudo brew #{cmd}`\n#{SUDO_BAD_ERRMSG}"
end
end
# Add contributed commands to PATH before checking.
ENV['PATH'] += ":#{HOMEBREW_CONTRIB}/cmd"
if require? HOMEBREW_REPOSITORY/"Library/Homebrew/cmd"/cmd
Homebrew.send cmd.to_s.gsub('-', '_').downcase
elsif which "brew-#{cmd}"
%w[CACHE CELLAR LIBRARY_PATH PREFIX REPOSITORY].each do |e|
ENV["HOMEBREW_#{e}"] = Object.const_get "HOMEBREW_#{e}"
end
exec "brew-#{cmd}", *ARGV
elsif require? which("brew-#{cmd}.rb").to_s
exit 0
else
onoe "Unknown command: #{cmd}"
exit 1
end
rescue FormulaUnspecifiedError
abort "This command requires a formula argument"
rescue KegUnspecifiedError
abort "This command requires a keg argument"
rescue UsageError
onoe "Invalid usage"
abort ARGV.usage
rescue SystemExit
puts "Kernel.exit" if ARGV.verbose?
raise
rescue Interrupt => e
puts # seemingly a newline is typical
exit 130
rescue BuildError => e
e.dump
exit 1
rescue RuntimeError, SystemCallError => e
raise if e.message.empty?
onoe e
puts e.backtrace if ARGV.debug?
exit 1
rescue Exception => e
onoe e
puts "#{Tty.white}Please report this bug:"
puts " #{Tty.em}#{ISSUES_URL}#{Tty.reset}"
puts e.backtrace
exit 1
else
exit 1 if Homebrew.failed?
end
enter code here
Does any of this make sense or ring any bells?
Could it have anything to do with why I'm getting the Homebrew or Ruby error?
Any help would be greatly appreciated.
I'd be happy to provide as much information as possible for us to solve this problem! :)
EDIT:
This is what happens when I try to run brew doctor:
rvm install ruby
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/10.10/x86_64/ruby- 2.2.1.tar.bz2
Checking requirements for osx.
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 21: /usr/local/Library/brew.rb: Undefined error: 0
ERROR: '/bin' is not writable - it is required for Homebrew, try 'brew doctor' to fix it!
Requirements installation failed with status: 1.
$ brew doctor
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 21: /usr/local/Library/brew.rb: Undefined error: 0
If you can't run echo "puts 'hello world'" | /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby at a terminal prompt, something has happened that has uninstalled your system Ruby and you should reinstall OS X to restore it.

Whenever gem on aws opsworks

Does anyone have experience/success using the whenever gem on aws opsworks? Is there a good recipe? Can I put that recipe on a separate layer and associate one instance with that additional layer? Or is there a better way to do it? Thanks!!!
EDIT:
We ended up doing it a bit differently...
Code:
Can’t really post the real code, but it’s like this:
in deploy/before_migrate.rb:
[:schedule].each do |config_name|
Chef::Log.info("Processing config for #{config_name}")
begin
template "#{release_path}/config/#{config_name}.rb" do |_config_file|
variables(
config_name => node[:deploy][:APP_NAME][:config_files][config_name]
)
local true
source "#{release_path}/config/#{config_name}.rb.erb"
end
rescue => e
Chef::Log.error e
raise "Error processing config for #{config_name}: #{e}"
end
end
in deploy/after_restart.rb:
execute 'start whenever' do
cwd release_path
user node[:deploy][:APP_NAME][:user] || 'deploy'
command 'bundle exec whenever -i APP_NAME'
end
in config/schedule.rb.erb:
<% schedule = #schedule || {} %>
set :job_template, "bash -l -c 'export PATH=/usr/local/bin:${PATH} && :job'"
job_type :runner, 'cd :path && bundle exec rails runner -e :environment ":task" :output'
job_type :five_runner, 'cd :path && timeout 300 bundle exec rails runner -e :environment ":task" :output'
set :output, 'log/five_minute_job.log'
every 5.minutes, at: <%= schedule[:five_minute_job_minute] || 0 %> do
five_runner 'Model.method'
end
We have a whenever cookbook in our repo we use that you would be more than welcome to use here: https://github.com/freerunningtech/frt-opsworks-cookbooks. I assume you're familiar with adding custom cookbooks to your opsworks stacks.
We generally run it on its own layer that also includes the rails cookbooks required for application deployment (while not the app server):
Configure: rails::configure
Deploy: deploy::rails whenever
Undeploy: deploy::rails-undeploy
However, we usually also deploy this instance as an application server, meaning we do end up serving requests from the box we're using for whenever as well.
There is one "gotcha", in that you must set your path in the env at the top of the schedule.rb like this:
env :PATH, ENV['PATH']

chef template variable #node seems to throw error

I'm going through peepcode's Chef tutorial, so far so good. For some reason there is a failure when using template variables. The example is for nginx.
In the nginx/attributes/nginx.rb I have:
default[:nginx][:worker_processes] = 4
In the nginx.conf.erb template I refer to:
worker_processes <%= #node[:nginx][:worker_processes] %>;
Below is the error I get running chef-solo:
Template Context:
-----------------
on line #2
1: user www-data;
2: worker_processes <%= #node[:nginx][:worker_processes] %>;
3:
4: error_log /var/log/nginx/error.log;
5: pid /var/run/nginx.pid;
[2013-07-14T19:46:36+02:00] ERROR: Running exception handlers
[2013-07-14T19:46:36+02:00] ERROR: Exception handlers complete
Chef Client failed. 0 resources updated
[2013-07-14T19:46:36+02:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-07-14T19:46:36+02:00] FATAL: Chef::Mixin::Template::TemplateError: undefined method `[]' for nil:NilClass
Other part of the error output:
Starting Chef Client, version 11.4.4
Compiling Cookbooks...
Converging 3 resources
Recipe: nginx::default
* package[nginx] action install (up to date)
* service[nginx] action enable (up to date)
* service[nginx] action start (up to date)
* template[/etc/nginx/nginx.conf] action create
================================================================================
Error executing action `create` on resource 'template[/etc/nginx/nginx.conf]'
================================================================================
Chef::Mixin::Template::TemplateError
------------------------------------
undefined method `[]' for nil:NilClass
Resource Declaration:
---------------------
# In /cookbooks/nginx/recipes/default.rb
8: template "/etc/nginx/nginx.conf" do
9: notifies :reload, "service[nginx]"
10: end
Compiled Resource:
------------------
# Declared in /cookbooks/nginx/recipes/default.rb:8:in `from_file'
template("/etc/nginx/nginx.conf") do
provider Chef::Provider::Template
action "create"
retries 0
retry_delay 2
path "/etc/nginx/nginx.conf"
backup 5
source "nginx.conf.erb"
cookbook_name :nginx
recipe_name "default"
end
You can access object variables (the ones that start with #) in templates, only if you passed them through variables method of template like that:
template("/etc/nginx/nginx.conf") do
[...]
variables( :my_var => node )
[...]
end
Then you will have #my_var available in template. But you don't have to pass the node, because it is already available in templates. You just have to access it not as an object variable. The following code in template should work.
<%= node[:nginx][:worker_processes] %>
Just remove the # from the front of node.
The node object is not accessible via an instance variable (the thing starting with an # sign). Instead, it is a method in the current context.
Change:
<%= #node[:nginx][:worker_processes] %>
to
<%= node[:nginx][:worker_processes] %>
Notice the removal of the #-sign? You only need the #-sign when passing in variables to the template via the variables parameter.

How can one set up Chef Recipes with delayed_job to spawn multiple workers?

I can find little to no documentation on this, nor any help from EngineYard.
This is my delayed_job/recipes/default.rb :
if ['solo', 'app', 'app_master'].include?(node[:instance_role])
# be sure to replace "app_name" with the name of your application.
run_for_app("HQ_Channel2") do |app_name, data|
# this is something trip added. beware.
worker_count = 3
worker_count.times do |count|
template "/etc/monit.d/delayed_job#{count+1}.#{app_name}.monitrc" do
source "delayed_job_worker.monitrc.erb"
owner "root"
group "root"
mode 0644
variables({
:app_name => app_name,
:user => node[:owner_name],
:worker_name => "delayed_job#{count+1}",
:framework_env => node[:environment][:framework_env]
})
end
end
# this is something trip removed. beware.
#worker_name = "delayed_job"
# The symlink is created in /data/app_name/current/tmp/pids -> /data/app_name/shared/pids, but shared/pids doesn't seem to be?
directory "/data/#{app_name}/shared/pids" do
owner node[:owner_name]
group node[:owner_name]
mode 0755
end
template "/etc/monit.d/delayed_job_worker.#{app_name}.monitrc" do
source "delayed_job_worker.monitrc.erb"
#owner node[:owner_name]
#group node[:owner_name]
owner "root"
group "root"
mode 0644
variables({
:app_name => app_name,
:user => node[:owner_name],
:worker_name => worker_name,
:framework_env => node[:environment][:framework_env]
})
end
bash "monit-reload-restart" do
user "root"
code "monit reload && monit"
end
end
end
Then I do ey-recipes upload -e production && ey-recipes apply -e production.
Everything goes through.
But when I ey deploy -e production, I get a
Beginning deploy for 'HQ_Channel2' in 'production' on server...
Application master's status is not "running" (green); it is "error".
I checked out my custom log and it returns :
[Thu, 01 Dec 2011 06:07:17 -0800] INFO: Starting Chef Solo Run
/usr/local/ey_resin/ruby/lib/ruby/gems/1.8/gems/chef-0.6.0.2/lib/chef/recipe.rb:196:in `method_missing': Cannot find Chef::Resource::Template for template (NameError)
Why am I getting this error?
Take a look at this answer (written by someone else).
https://gist.github.com/334674

Resources