Skip to content

Commit

Permalink
Bugfix/#16232 cgroup update (#2)
Browse files Browse the repository at this point in the history
* check cgroups function

* removing comments

* parametrized node name

* Script to check and update if necessary

* moving checker to configure script

* renaming because this script will not be executable

* making it executable

* removing copied code

* i was supposing cgroup empty means inactive

* chomping consule return

* comment

* run script as ruby by default, getting better hostname

* dinamic version and realease normalization

* refactoring needed

* readme update because user functionality

* rubywrapper added

* unmangle shebangs to avoid no env ruby

* Removing comments, ruby lint function call

* lint frozen literal

* lint identation size

* Lint doc module

* lint more def less lines in one

* lint, call as a function, not as a class

* refactor literal string

* lint fixes

* versioning
  • Loading branch information
ljblancoredborder authored Mar 7, 2024
1 parent c9722b5 commit 9435cf6
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ To install redborder-cgroups, follow these steps:
Create a file in /etc/cgroup.conf with the services in yaml format, for more info take a look at [Cgroup Cookbook](https://github.com/redBorder/cookbook-rb-cgroup)

Then start `rb_configure_cgroup.sh` and it will reassign memory for each service
Or just check if the memory services need to be reconfigured with `rb_check_cgroups.sh`

## Authors

Expand Down
9 changes: 7 additions & 2 deletions packaging/rpm/redborder-cgroups.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
%undefine __brp_mangle_shebangs

Name: redborder-cgroups
Version: 0.0.1
Release: 1%{?dist}
Version: %{__version}
Release: %{__release}%{?dist}
BuildArch: noarch
Summary: redborder-cgroups package for configuring cgroup in redborder environments

Expand Down Expand Up @@ -28,6 +30,7 @@ install -m 0755 resources/scripts/* %{buildroot}/usr/lib/redborder/scripts/
%pre

%post
/usr/lib/redborder/bin/rb_rubywrapper.sh -c
systemctl daemon-reload
systemctl enable redborder-cgroups

Expand All @@ -41,6 +44,8 @@ systemctl enable redborder-cgroups
%doc

%changelog
* Fri Feb 23 2024 - Luis Blanco <ljblanco@redborder.com> - 0.1.0-1
- Ruby wrapper added, and unmangle shebangs
* Tue Sep 28 2023 - Miguel Álvarez <malvarez@redborder.com> - 0.0.1-1
- Initial spec version

20 changes: 20 additions & 0 deletions resources/bin/rb_check_cgroups.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

#######################################################################
# Copyright (c) 2024 ENEO Tecnología S.L.
# This file is part of redBorder.
# redBorder is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# redBorder is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License License for more details.
# You should have received a copy of the GNU Affero General Public License License
# along with redBorder. If not, see <http://www.gnu.org/licenses/>.
#######################################################################

source /etc/profile.d/rvm.sh

/usr/lib/redborder/scripts/rb_check_cgroups.rb $*
37 changes: 37 additions & 0 deletions resources/scripts/rb_check_cgroups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'socket'
require 'chef'

# Module to interact with Cgroup v2 in an easy way
module RedBorder
# Module to check if cgroups need to be reassigned
module Checker
def self.check_memservices_cgroups
Chef::Log.info('Memservices Check')
active_memory_services.all? do |s|
cgroup = `systemctl show -p ControlGroup #{s}`.gsub('ControlGroup=', '').chomp
s = s.delete('\",-').chomp
# every assigned cgroup should cointain redborder-....slice any else false
cgroup.include?("redborder-#{s}.slice")
end
end

def self.hostname
`hostname -s`.strip
end

def self.memory_services
`knife node show #{hostname} -l -F json | jq '.default.redborder.memory_services | keys[]'`.chomp.lines
end

def self.active_memory_services
memory_services.select do |s|
`systemctl is-active #{s}`.chomp == 'active'
end
end
end
end

RedBorder::Checker.check_memservices_cgroups

0 comments on commit 9435cf6

Please sign in to comment.