Skip to content
This repository has been archived by the owner on Jan 23, 2020. It is now read-only.

[WIP] Freebsd 10 support #119

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Attic
*~
tmp
logs
*.lock
*.txz

# YARD artifacts
.yardoc
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'mixlib-shellout', '1.4.0'
gem 'systemu', '2.2.0'
gem 'systemu', '2.6.5'
gem 'ohai', '6.18.0'
gem 'bunchr', '0.1.6'
gem 'bunchr', '0.1.7'
49 changes: 0 additions & 49 deletions Gemfile.lock

This file was deleted.

64 changes: 47 additions & 17 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
gem 'systemu', '2.2.0'
gem 'systemu', '2.6.5'
gem 'ohai', '6.18.0'
gem 'bunchr', '0.1.6'
gem 'bunchr', '0.1.7'

require 'bunchr'
require 'fileutils'
Expand Down Expand Up @@ -29,6 +29,8 @@ Bunchr::Packages.new do |t|
t.description = 'A monitoring framework that aims to be simple, malleable, and scalable.'
t.maintainer = 'Sensu Helpdesk <[email protected]>'

os = t.ohai.os
arch = t.ohai.kernel["machine"]
platform_family = t.ohai.platform_family

case platform_family
Expand All @@ -51,6 +53,10 @@ Bunchr::Packages.new do |t|
t.scripts[:after_install] = 'pkg_scripts/rpm/post'
t.scripts[:before_remove] = 'pkg_scripts/rpm/preun'
t.scripts[:after_remove] = 'pkg_scripts/rpm/postun'
when 'freebsd'
t.scripts[:after_install] = 'pkg_scripts/freebsd/postinst'
t.scripts[:before_remove] = 'pkg_scripts/freebsd/prerm'
t.scripts[:after_remove] = 'pkg_scripts/freebsd/postrm'
end

t.include_software('ruby')
Expand All @@ -60,28 +66,52 @@ Bunchr::Packages.new do |t|
t.include_software('sensu_configs')
t.include_software('sensu_bin_stubs')

etc_path = "/etc"
bin_path = "/usr/bin"
share_path = "/usr/share"
log_path = "/var/log"

if os == "freebsd"
etc_path = "/usr/local/etc"
bin_path = "/usr/local/bin"
share_path = "/usr/local/share"
end

t.files << Bunchr.install_dir
t.files << '/usr/share/sensu'
t.files << '/var/log/sensu'
t.files << '/etc/sensu/plugins'
t.files << '/etc/sensu/mutators'
t.files << '/etc/sensu/handlers'
t.files << '/etc/sensu/extensions'
t.files << "#{share_path}/sensu"
t.files << "#{log_path}/sensu"
t.files << "#{etc_path}/sensu/plugins"
t.files << "#{etc_path}/sensu/mutators"
t.files << "#{etc_path}/sensu/handlers"
t.files << "#{etc_path}/sensu/extensions"

# all linux platforms are currently using init.d
# this may change in the future.
t.files << '/etc/init.d/sensu-service'
t.files << '/etc/init.d/sensu-api'
t.files << '/etc/init.d/sensu-client'
t.files << '/etc/init.d/sensu-server'
t.files << '/usr/bin/sensu-install'
if os == "linux"
t.files << "#{etc_path}/init.d/sensu-service"
t.files << "#{etc_path}/init.d/sensu-api"
t.files << "#{etc_path}/init.d/sensu-client"
t.files << "#{etc_path}/init.d/sensu-server"
t.files << "#{bin_path}/sensu-install"
end

if os == "freebsd"
t.files << "#{etc_path}/rc.d/sensu-service"
t.files << "#{etc_path}/rc.d/sensu-api"
t.files << "#{etc_path}/rc.d/sensu-client"
t.files << "#{etc_path}/rc.d/sensu-server"
t.files << "#{bin_path}/sensu-install"
end

# need to enumerate config files for fpm
# these are installed from recipe/sensu_configs.rake
t.config_files << '/etc/sensu/config.json.example'
t.config_files << '/etc/sensu/conf.d/README.md'
t.config_files << '/etc/logrotate.d/sensu'
t.config_files << '/etc/default/sensu'
t.config_files << "#{etc_path}/sensu/config.json.example"
t.config_files << "#{etc_path}/sensu/conf.d/README.md"
t.config_files << "#{etc_path}/default/sensu"

if os == "linux"
t.config_files << "#{etc_path}/logrotate.d/sensu"
end
end
end

Expand Down
38 changes: 38 additions & 0 deletions pkg_scripts/freebsd/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

set -e

create_sensu_user_group() {
# create sensu group
if ! getent group sensu >/dev/null; then
pw groupadd sensu
fi

# create sensu user
if ! getent passwd sensu >/dev/null; then
pw adduser sensu -g sensu -d /nonexistent \
-s /usr/sbin/nologin -c "Sensu Monitoring Framework"
fi
}

make_sensu_dirs() {
mkdir -p /var/run/sensu
}

chown_sensu_dirs() {
chown -R sensu:sensu /usr/local/etc/sensu
chown -R sensu:sensu /var/log/sensu
chown -R sensu:sensu /opt/sensu/sv
chown -R sensu:sensu /var/run/sensu
}

chmod_sensu_files() {
chmod +x /usr/local/bin/sensu-install
}

create_sensu_user_group
make_sensu_dirs
chown_sensu_dirs
chmod_sensu_files

exit 0
38 changes: 38 additions & 0 deletions pkg_scripts/freebsd/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

set -e

sensu_services="sensu-client sensu-server sensu-api"

purge_sensu_services() {
for service in $sensu_services; do
if [ -f "/usr/local/etc/rc.d/$service" ]; then
rm /usr/local/etc/rc.d/$service
fi
done
}

purge_sensu_files() {
if [ -d "/usr/local/share/sensu" ]; then
rm -r /usr/local/share/sensu
fi
if [ -d "/opt/sensu" ]; then
rm -r /opt/sensu
fi
rm -rf /tmp/sensu_*_loaded_files
}

purge_sensu_user_group() {
if getent passwd sensu >/dev/null; then
pw userdel sensu
fi
if getent group sensu >/dev/null; then
pw groupdel sensu
fi
}

purge_sensu_services
purge_sensu_files
purge_sensu_user_group

exit 0
24 changes: 24 additions & 0 deletions pkg_scripts/freebsd/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

set -e

sensu_services="sensu-client sensu-server sensu-api"

# try to stop any running sensu services (not all will be running)
stop_sensu_services() {
for service in $sensu_services; do
if [ -x "/usr/local/etc/rc.d/$service" ]; then
/usr/local/etc/rc.d/$service stop || true
fi
if [ -L "/opt/sensu/service/$service" ]; then
rm /opt/sensu/service/$service
fi
done

# some time for sensu services to stop
sleep 6
}

stop_sensu_services

exit 0
24 changes: 24 additions & 0 deletions recipes/libffi.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Bunchr::Software.new do |t|
os = t.ohai["os"]

if os == "freebsd"
t.name = "libffi"
t.version = "1.9.10"
t.work_dir = "/usr/ports/devel/libffi"

install_prefix = "#{Bunchr.install_dir}/embedded"

t.build_environment["PREFIX"] = install_prefix
t.build_environment["BATCH"] = "yes"

t.build_commands << "make"

t.install_environment["PREFIX"] = install_prefix
t.install_environment["BATCH"] = "yes"

t.install_commands << "make deinstall"
t.install_commands << "make install clean"

CLEAN << install_prefix
end
end
24 changes: 24 additions & 0 deletions recipes/libgmp.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Bunchr::Software.new do |t|
os = t.ohai["os"]

if os == "freebsd"
t.name = "libgmp"
t.version = "5.1.3_2"
t.work_dir = "/usr/ports/math/gmp"

install_prefix = "#{Bunchr.install_dir}/embedded"

t.build_environment["PREFIX"] = install_prefix
t.build_environment["BATCH"] = "yes"

t.build_commands << "make"

t.install_environment["PREFIX"] = install_prefix
t.install_environment["BATCH"] = "yes"

t.install_commands << "make deinstall"
t.install_commands << "make install clean"

CLEAN << install_prefix
end
end
15 changes: 15 additions & 0 deletions recipes/libstdc++.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Bunchr::Software.new do |t|
os = t.ohai["os"]

if os == "freebsd"
t.name = "libstdc++"
t.version = "4.9.4"
t.work_dir = "."

install_prefix = "#{Bunchr.install_dir}/embedded"

t.install_commands << "cp /usr/local/lib/gcc49/libstdc++.so.6 #{install_prefix}/lib"

CLEAN << install_prefix
end
end
6 changes: 6 additions & 0 deletions recipes/libyaml.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ Bunchr::Software.new do |t|

install_prefix = "#{Bunchr.install_dir}/embedded"

os = t.ohai['os']

t.download_commands << "curl -O http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz"
t.download_commands << "tar xfvz yaml-0.1.4.tar.gz"

t.work_dir = "yaml-#{t.version}"

if os == 'freebsd'
t.build_environment['CFLAGS'] = '-fPIC'
end

t.build_commands << "./configure --prefix=#{install_prefix}"
t.build_commands << "make"

Expand Down
9 changes: 9 additions & 0 deletions recipes/ruby.rake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ Bunchr::Software.new do |t|
t.name = 'ruby'
t.version = '2.3.0'

os = t.ohai['os']
arch = t.ohai['kernel']['machine']

t.depends_on('libgmp') if os == "freebsd"
t.depends_on('libffi') if os == "freebsd"
t.depends_on('libstdc++') if os == "freebsd"
t.depends_on('autoconf')
t.depends_on('zlib')
t.depends_on('openssl')
Expand All @@ -24,6 +30,9 @@ Bunchr::Software.new do |t|
elsif os == 'solaris2'
t.build_environment['LDFLAGS'] = "-R#{install_prefix}/lib -L#{install_prefix}/lib -I#{install_prefix}/include"
t.build_environment['CFLAGS'] = "-L#{install_prefix}/lib -I#{install_prefix}/include"
elsif os == 'freebsd'
t.build_environment['LDFLAGS'] = "-Wl,-rpath #{install_prefix}/lib -L#{install_prefix}/lib -I#{install_prefix}/include"
t.build_environment['CFLAGS'] = "-L#{install_prefix}/lib -I#{install_prefix}/include"
end

if arch == "armv6l" || arch == "armv7l"
Expand Down
Loading