Sha256: df8b619835993585ed5ea2e25d9d8c006c8ee9dfc8b3c6693ad4dc09ab470bcd

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

# This file is meant ONLY as a way to make a hookit hook directly executable.
#
# Normally hookit is bootstrapped via `hookit hook-name "payload"`.
#
# This script allows a ruby executable script to bootstrap hookit and run as
# a hook directly.
#
# Usage:
#
# #!/usr/bin/env ruby
#
# # optionally, set some configuration
# # (if not set, MODULE_ROOT will default to the directory if this script)
#
# $LOG_LEVEL = :error
# $LOGFILE = '/var/log/hookit/hookit.log'
# $MODULE_DIR = "/opt/local/hookit/mod"
#
# # load hookit/setup to bootstrap hookit
# require 'hookit/setup'
#
# execute 'list all the files!' do
#   command 'ls -lah /'
# end
#

# This won't handle every scenario, but essentially it tries to find the
# location of the script that was executed
hook = begin
  if $0[0] == '/'
    $0
  else
    "#{Dir.getwd}/#{$0}"
  end
end

module_dir = File.dirname(hook)

MODULE_DIR = $MODULE_DIR  || ENV['MODULE_DIR']  || module_dir
LOG_LEVEL  = $LOG_LEVEL   || ENV['LOG_LEVEL']   || :error
LOGFILE    = $LOGFILE     || ENV['LOGFILE']     || '/var/log/hookit/hookit.log'

require 'hookit'
require 'json'

include Hookit::Hook   # payload helpers / resource dsl

set :log_level,   LOG_LEVEL
set :logfile,     LOGFILE
set :module_root, MODULE_DIR

# require hook libs
Dir.glob("#{MODULE_DIR}/lib/*.rb").each do |file|
  require file
end

logger.info ""
logger.info "hook: #{hook}"
logger.info "payload: #{payload.to_json}"

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
micro-hookit-0.12.13 lib/hookit/setup.rb
micro-hookit-0.12.12 lib/hookit/setup.rb
micro-hookit-0.12.11 lib/hookit/setup.rb