Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add centos support #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
34 changes: 13 additions & 21 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
---
driver_plugin: vagrant
driver_config:
require_chef_omnibus: true
driver:
name: vagrant

provisioner:
name: chef_zero

platforms:
- name: ubuntu-12.04
driver_config:
box: opscode-ubuntu-12.04
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
- name: ubuntu-10.04
driver_config:
box: opscode-ubuntu-10.04
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_provisionerless.box
- name: centos-6.4
driver_config:
box: opscode-centos-6.4
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box
- name: centos-5.9
driver_config:
box: opscode-centos-5.9
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-5.9_provisionerless.box
- name: debian-7.8
- name: ubuntu-10.04
- name: ubuntu-12.04
- name: ubuntu-14.10
- name: centos-6.6
- name: centos-7.0

suites:
- name: default
run_list: []
attributes: {}
run_list:
- recipe[sysfs::default]
19 changes: 18 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
default['sysfs']['package'] = "sysfsutils"
default['sysfs']['package'] = 'sysfsutils'
default['sysfs']['service'] = 'sysfsutils'

default['sysfs']['init_type'] = value_for_platform(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it not be better to do some detection rather than having to manage a list of versions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, now detecting versions

Copy link

@majormoses majormoses Jun 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant something more along the lines of some helper functions detect the presence of systemd, upstart, and fall back to sysvinit:

def systemd?
  IO.read('/proc/1/comm').chomp == 'systemd'
end

def upstart?
  File.executable?('/sbin/initctl')
end

def determine_init_subsytem
  if systemd?
    'systemd'
  elsif upstart?
    'upstart'
  else
    'sysv'
  end
end

We can still choose to overwrite it if we want (such as in a docker container where you would never run systemd) but we can try doing some sane default detection.

%w(redhat centos) => {
%w(6.0 6.1 6.2 6.3 6.4 6.5 6.6) => 'sysv',
'default' => 'systemd'
},
'default' => nil
)

default['sysfs']['disable_tuned'] = value_for_platform(
%w(redhat centos) => {
%w(6.0 6.1 6.2 6.3 6.4 6.5 6.6) => false,
'default' => true
},
'default' => false
)
22 changes: 22 additions & 0 deletions files/default/sysfs.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# /etc/sysfs.conf - Configuration file for setting sysfs attributes.
#
# The sysfs mount directory is automatically prepended to the attribute paths.
#
# Syntax:
# attribute = value
# mode attribute = 0600 # (any valid argument for chmod)
# owner attribute = root:wheel # (any valid argument for chown)
#
# Examples:
#
# Always use the powersave CPU frequency governor
# devices/system/cpu/cpu0/cpufreq/scaling_governor = powersave
#
# Use userspace CPU frequency governor and set initial speed
# devices/system/cpu/cpu0/cpufreq/scaling_governor = userspace
# devices/system/cpu/cpu0/cpufreq/scaling_setspeed = 600000
#
# Set permissions of suspend control file
# mode power/state = 0660
# owner power/state = root:power
147 changes: 147 additions & 0 deletions files/default/sysfsutils
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#! /bin/sh -e

### BEGIN INIT INFO
# Provides: sysfsconf
# Required-Start: mountkernfs
# Should-Start: udev module-init-tools cpufrequtils
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Set sysfs variables from /etc/sysfs.conf
# Description: Similarly to /etc/init.d/procps.sh, you can configure
# values for sysfs variables (such as power management
# defaults) and /sys file permissions in /etc/sysfs.conf.
### END INIT INFO

# /etc/init.d/sysfsutils:
#
# (c) 2005 Martin Pitt <[email protected]>

CONFFILE=/etc/sysfs.conf
CONFDIR=/etc/sysfs.d

[ -r "$CONFFILE" -o -d "$CONFDIR" ] || exit 0

# RHEL does not have the init-functions file, so lets copy what we need
#. /lib/lsb/init-functions
log_begin_msg () {
if [ -z "${1:-}" ]; then
return 1
fi
echo -n "$@"
}

log_failure_msg () {
if [ -n "${1:-}" ]; then
log_begin_msg $@ "..."
fi
log_end_msg 1 || true
}

log_end_msg_pre () { :; }
log_end_msg_post () { :; }

log_use_fancy_output () {
TPUT=/usr/bin/tput
EXPR=/usr/bin/expr
if [ -t 1 ] && [ "x${TERM:-}" != "x" ] && [ "x${TERM:-}" != "xdumb" ] && [ -x $TPUT ] && [ -x $EXPR ] && $TPUT hpa 60 >/dev/null 2>&1 && $TPUT setaf 1 >/dev/null 2>&1; then
[ -z $FANCYTTY ] && FANCYTTY=1 || true
else
FANCYTTY=0
fi
case "$FANCYTTY" in
1|Y|yes|true) true;;
*) false;;
esac
}

# int log_end_message (int exitstatus)
log_end_msg () {
# If no arguments were passed, return
if [ -z "${1:-}" ]; then
return 1
fi

retval=$1

log_end_msg_pre "$@"

# Only do the fancy stuff if we have an appropriate terminal
# and if /usr is already mounted
if log_use_fancy_output; then
RED=`$TPUT setaf 1`
YELLOW=`$TPUT setaf 3`
NORMAL=`$TPUT op`
else
RED=''
YELLOW=''
NORMAL=''
fi

if [ $1 -eq 0 ]; then
echo "."
elif [ $1 -eq 255 ]; then
/bin/echo -e " ${YELLOW}(warning).${NORMAL}"
else
/bin/echo -e " ${RED}failed!${NORMAL}"
fi
log_end_msg_post "$@"
return $retval
}

# End of copy

load_conffile() {
FILE="$1"
sed 's/#.*$//; /^[[:space:]]*$/d;
s/^[[:space:]]*\([^=[:space:]]*\)[[:space:]]*\([^=[:space:]]*\)[[:space:]]*=[[:space:]]*\(.*\)/\1 \2 \3/' \
$FILE | {
while read f1 f2 f3; do
if [ "$f1" = "mode" -a -n "$f2" -a -n "$f3" ]; then
if [ -f "/sys/$f2" ] || [ -d "/sys/$f2" ]; then
chmod "$f3" "/sys/$f2"
else
log_failure_msg "unknown attribute $f2"
fi
elif [ "$f1" = "owner" -a -n "$f2" -a -n "$f3" ]; then
if [ -f "/sys/$f2" ]; then
chown "$f3" "/sys/$f2"
else
log_failure_msg "unknown attribute $f2"
fi
elif [ "$f1" -a -n "$f2" -a -z "$f3" ]; then
if [ -f "/sys/$f1" ]; then
# Some fields need a terminating newline, others
# need the terminating newline to be absent :-(
echo -n "$f2" > "/sys/$f1" 2>/dev/null ||
echo "$f2" > "/sys/$f1"
else
log_failure_msg "unknown attribute $f1"
fi
else
log_failure_msg "syntax error in $CONFFILE: '$f1' '$f2' '$f3'"
log_end_msg 1
exit 1
fi
done
}
}

case "$1" in
start|restart|force-reload)
log_begin_msg "Setting sysfs variables..."

for file in $CONFFILE $CONFDIR/*.conf; do
[ -r "$file" ] || continue
load_conffile "$file"
done

log_end_msg 0
;;
stop)
;;
*)
echo "Usage: /etc/init.d/sysfsutils {start|stop|force-reload|restart}"
exit 1
;;
esac
9 changes: 9 additions & 0 deletions files/default/sysfsutils.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Sysfsutils Service

[Service]
Type=simple
ExecStart=/etc/init.d/sysfsutils start

[Install]
WantedBy=multi-user.target
5 changes: 3 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name 'sysfs'
name 'sysfs'
maintainer "Guilhem Lettron"
maintainer_email "[email protected]"
license "Apache v2.0"
description "Configures sysfs parameters"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.0.2"
version "0.1.0"
supports "ubuntu"
supports "debian"
supports "centos"
13 changes: 13 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@
#

package node['sysfs']['package']

if node['sysfs']['init_type']
include_recipe "sysfs::#{node['sysfs']['init_type']}"
end

service node['sysfs']['service'] do
action [ :start, :enable ]
end

service 'tuned' do
action :disable
only_if { node['sysfs']['disable_tuned'] }
end
29 changes: 29 additions & 0 deletions recipes/systemd.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Cookbook Name:: sysfs
# Recipe:: systemd
# Author:: Jonathan Morley <[email protected]>
#
# Copyright 2015, Cvent, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe 'sysfs::sysv'

cookbook_file '/etc/systemd/system/sysfsutils.service' do
source 'sysfsutils.service'
owner 'root'
group 'root'
mode '0644'
action :create
end
42 changes: 42 additions & 0 deletions recipes/sysv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#
# Cookbook Name:: sysfs
# Recipe:: sysv
# Author:: Jonathan Morley <[email protected]>
#
# Copyright 2015, Cvent, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

cookbook_file '/etc/sysfs.conf' do
source 'sysfs.conf'
owner 'root'
group 'root'
mode '0644'
action :create
end

cookbook_file '/etc/init.d/sysfsutils' do
source 'sysfsutils'
owner 'root'
group 'root'
mode '0755'
action :create
end

directory "/etc/sysfs.d" do
owner 'root'
group 'root'
mode '0755'
action :create
end
8 changes: 8 additions & 0 deletions test/integration/default/serverspec/sysfs_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'serverspec'

# Required by serverspec
set :backend, :exec

describe service('sysfsutils') do
it { should be_enabled }
end