@@ -1,10 +1,29 @@
default[:instrumental] = {}
default[:instrumental][:api_key] = nil
default[:instrumental][:version] = "1.0.0"
default[:instrumental][:repo] = "https://s3.amazonaws.com/instrumental-tools"
default[:instrumental][:curl_path] = "/usr/bin/curl"
default[:instrumental][:wget_path] = "/usr/bin/wget"
default[:instrumental][:dist_init_file] = "/opt/instrumental-tools/lib/app/debian/instrument_server"
default[:instrumental][:dest_init_file] = "/etc/init.d/instrument_server"
default[:instrumental][:use_local] = false
default[:instrumental][:local_path] = nil
default[:instrumental] = {}
default[:instrumental][:api_key] = nil

default[:instrumental][:version] = "1.0.0"
default[:instrumental][:repo] = "https://s3.amazonaws.com/instrumental-tools"

default[:instrumental][:curl_path] = "/usr/bin/curl"
default[:instrumental][:wget_path] = "/usr/bin/wget"

default[:instrumental][:dest_init_file] = "/etc/init.d/instrument_server"

default[:instrumental][:enable_scripts] = false


if node[:platform_family] == "windows"
default[:instrumental][:destination_dir] = "C:\\Program Files (x86)\\Instrumental Tools"
default[:instrumental][:config_file] = "C:\\Program Files (x86)\\Instrumental Tools\\etc\\instrumental.yml"
default[:instrumental][:script_dir] = "C:\\Program Files (x86)\\Instrumental Tools\\scripts"
else
default[:instrumental][:destination_dir] = "/opt/instrumental-tools/"
default[:instrumental][:config_file] = "/etc/instrumental.yml"
default[:instrumental][:script_dir] = "/opt/instrumental-tools/.scripts"
default[:instrumental][:pid_file] = "/opt/instrumental-tools/instrument_server.pid"
default[:instrumental][:log_file] = "/opt/instrumental-tools/instrument_server.log"
default[:instrumental][:user] = "nobody"
end

default[:instrumental][:use_local] = false
default[:instrumental][:local_path] = nil
@@ -25,12 +25,16 @@
"instrumental-tools_%s_linux-%s.tar.gz" % [version, arch]
end
local_path = ::File.join(node[:instrumental][:local_path], file_name)
dest_dir = node[:instrumental][:destination_dir]
conf_file = node[:instrumental][:config_file]

case node["platform_family"]
when "debian", "rhel", "fedora"
if node[:instrumental][:use_local]
package local_path_path do
action[:upgrade]
package "instrumental-tools" do
action :install
source local_path
provider node["platform_family"] == "debian" ? Chef::Provider::Package::Dpkg : Chef::Provider::Package::Yum
end
else
packagecloud_repo "expectedbehavior/instrumental" do
@@ -48,19 +52,39 @@
end
end

template "/etc/instrumental.yml" do
template conf_file do
source "instrumental.yml.erb"
mode "0440"
owner "nobody"
variables(
:api_key => node[:instrumental][:api_key]
)
end

template node["instrumental"]["dest_init_file"] do
source "instrument_server.erb"
mode "0755"
owner "nobody"
variables(
:dest_dir => dest_dir,
:config_file => conf_file,
:enable_scripts => !!node[:instrumental][:enable_scripts],
:script_dir => node[:instrumental][:script_dir],
:log_file => node[:instrumental][:log_file],
:pid_file => node[:instrumental][:pid_file],
:user => node[:instrumental][:user]
)
end

service "instrument_server" do
action :restart
end

when "arch", "gentoo", "slackware", "suse", "osx"

local_path = "/opt/instrumental-tools/%s" % file_name
local_path = "%s/%s" % [dest_dir, file_name]

directory "/opt/instrumental-tools" do
directory dest_dir do
owner "nobody"
action :create
recursive true
@@ -69,22 +93,22 @@
if node[:instrumental][:use_local]
execute "copy_instrumental_tools_package" do
command "cp %s %s" % [local_path, ::File.basename(local_path)]
cwd "/opt/instrumental-tools"
cwd dest_dir
user "nobody"
end
else
remote_name = "%s/%s/%s" % [node["instrumental"]["repo"], version, file_name]
if ::File.exists?(node["instrumental"]["curl_path"])
execute "curl_download_instrumental_tools_package" do
command "%s -O %s" % [node["instrumental"]["curl_path"], remote_name]
cwd "/opt/instrumental-tools"
cwd dest_dir
not_if { ::File.exists?(local_path) }
user "nobody"
end
elsif ::File.exists?(node["instrumental"]["wget_path"])
execute "wget_download_instrumental_tools_package" do
command "%s %s" % [node["instrumental"]["wget_path"], remote_name]
cwd "/opt/instrumental-tools"
cwd dest_dir
not_if { ::File.exists?(local_path) }
user "nobody"
end
@@ -97,21 +121,26 @@
execute "untar_instrumental_tools_package" do
command "tar --strip-components=3 -zxvf %s" % file_name
user "nobody"
cwd "/opt/instrumental-tools"
cwd dest_dir
only_if { ::File.exists?(local_path) }
end

execute "copy_service_into_place" do
distributed_file = node["instrumental"]["dist_init_file"]
destination_file = node["instrumental"]["dest_init_file"]
command <<-EOSCRIPT % [distributed_file, destination_file, destination_file]
cp %s %s
chmod +x %s
EOSCRIPT
not_if { ::File.exists?(node["instrumental"]["dest_init_file"]) }
template node["instrumental"]["dest_init_file"] do
source "instrument_server.erb"
mode "0755"
owner "nobody"
variables(
:dest_dir => dest_dir,
:config_file => conf_file,
:enable_scripts => !!node[:instrumental][:enable_scripts],
:script_dir => node[:instrumental][:script_dir],
:log_file => node[:instrumental][:log_file],
:pid_file => node[:instrumental][:pid_file],
:user => node[:instrumental][:user]
)
end

template "/etc/instrumental.yml" do
template conf_file do
source "instrumental.yml.erb"
mode "0440"
owner "nobody"
@@ -128,9 +157,17 @@
when "windows"
if node[:instrumental][:use_local]
execute "install-tools" do
command "call %s /S" % local_path
command "call %s %s /S" % [local_path, dest_dir]
end
end

template conf_file do
source "instrumental.yml.erb"
variables(
:api_key => node[:instrumental][:api_key]
)
end

service "instrument_server" do
action [:enable, :start]
end
@@ -0,0 +1,46 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: instrument_server
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start instrument_server at boot to provide system metrics
# Description: Report system level metrics to the Instrumental service (https://instrumentalapp.com/)
### END INIT INFO

set -e

DIRECTORY="<%= @dest_dir %>"
CONFIG_FILE="<%= @config_file %>"
TMPDIR=$DIRECTORY
PID="<%= @pid_file %>"
LOG="<%= @log_file %>"
SCRIPT_LOCATION="<%= @script_dir %>"
USER_TO_RUN_AS="<%= @user %>"
ARGS="-f ${CONFIG_FILE} -p ${PID} -l ${LOG} -s ${SCRIPT_LOCATION} -u ${USER_TO_RUN_AS} -t ${TMPDIR} <%= '-e' if @enable_scripts %>"
PROCESS="${DIRECTORY}instrument_server ${ARGS}"

case "$1" in
start)
$PROCESS start
;;
stop)
$PROCESS stop
;;
restart)
$PROCESS restart
;;
status)
$PROCESS status
;;
force-reload)
$PROCESS stop && $PROCESS clean && $PROCESS start
;;
*)
echo "Usage: /etc/init.d/instrumental-tools {start|stop|restart|status}"
exit 1
;;
esac

exit 0
@@ -1,6 +1,6 @@
---
# Replace YOUR_API_KEY with the API key for your Instrumental project and
# remove the # from the beginning of the following line to have instrument_server
# start sending metrics to your account.

api_key: <%= @api_key %>
---
# Replace YOUR_API_KEY with the API key for your Instrumental project and
# remove the # from the beginning of the following line to have instrument_server
# start sending metrics to your account.

api_key: <%= @api_key %>
@@ -1,6 +1,6 @@
---
# Replace YOUR_API_KEY with the API key for your Instrumental project and
# remove the # from the beginning of the following line to have instrument_server
# start sending metrics to your account.

#api_key: YOUR_API_KEY
---
# Replace YOUR_API_KEY with the API key for your Instrumental project and
# remove the # from the beginning of the following line to have instrument_server
# start sending metrics to your account.

#api_key: YOUR_API_KEY
@@ -53,4 +53,5 @@ Gem::Specification.new do |s|
s.add_development_dependency(%q<librarian-puppet>, [">=0"])
s.add_development_dependency(%q<puppet>, [">=0"])
s.add_development_dependency(%q<serverspec>, [">=0"])
s.add_development_dependency(%q<winrm-transport>, ["~>1.0"])
end