diff --git a/.gitignore b/.gitignore index 4baea35..e86bbf6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ libcgroup-0.36.2.tar.bz2 /libcgroup-0.37.tar.bz2 /libcgroup-0.37.1.tar.bz2 +/libcgroup-0.38.rc1.tar.bz2 diff --git a/README.Fedora b/README.Fedora deleted file mode 100644 index 2f64d60..0000000 --- a/README.Fedora +++ /dev/null @@ -1,35 +0,0 @@ -Libcgroup integration into Fedora -================================= - -Apart from standard libcgroup features, Fedora adds support for starting system -services in given control group(s). - -If a service init script -1) uses daemon() function from /etc/init.d/functions to start the service -2) and uses /etc/sysconfig/ for its configuration, -you can add CGROUP_DAEMON="" to the -/etc/sysconfig/ to start the service in given group. - - -Example -------- -How to start Apache web server in group cpu,cpuacct:/daemons/http: -1. Configure your group in /etc/cgconfig.conf (see cgconfig.conf man page). -2. Add following line to /etc/sysconfig/httpd: -CGROUP_DAEMON="cpu,cpuacct:/daemons/http" - -During next boot (or after restart of cgconfig and httpd services), your http -daemon and all its children should be started in the given groups. - - -Details -------- -The daemon() function in /etc/init.d/functions was modified to start the daemon -in control group(s) specified by CGROUP_DAEMON environment variable. Therefore it -won't work on all services, but only those which satisfy the two aforementioned -conditions. - -CGROUP_DAEMON can contain more than one control group, separate them with space -then: -CGROUP_DAEMON="cpu:/daemons/http cpuacct:/daemons" - diff --git a/cgconfig.service b/cgconfig.service new file mode 100644 index 0000000..9b546a6 --- /dev/null +++ b/cgconfig.service @@ -0,0 +1,17 @@ +[Unit] +Description=Control Group configuration service + +# The service should be able to start as soon as possible, +# before any 'normal' services: +DefaultDependencies=no +Conflicts=shutdown.target +Before=basic.target shutdown.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/sbin/cgconfigparser -l /etc/cgconfig.conf -s 1664 +ExecStop=/usr/sbin/cgclear -l /etc/cgconfig.conf -e + +[Install] +WantedBy=sysinit.target diff --git a/cgred.service b/cgred.service new file mode 100644 index 0000000..69eb13e --- /dev/null +++ b/cgred.service @@ -0,0 +1,11 @@ +[Unit] +Description=CGroups Rules Engine Daemon +After=syslog.target + +[Service] +Type=forking +EnvironmentFile=-/etc/sysconfig/cgred +ExecStart=/usr/sbin/cgrulesengd $OPTIONS + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/cgred.sysconfig b/cgred.sysconfig new file mode 100644 index 0000000..6979662 --- /dev/null +++ b/cgred.sysconfig @@ -0,0 +1,2 @@ +# cgrulesengd command line options. See cgrulesengd(8). +OPTIONS="-s -g cgred" \ No newline at end of file diff --git a/fedora-fix-initscripts.patch b/fedora-fix-initscripts.patch deleted file mode 100644 index e2897e1..0000000 --- a/fedora-fix-initscripts.patch +++ /dev/null @@ -1,46 +0,0 @@ -Remove depencency on LSB. The redhat-lsb package pulls lot of dependencies -we do not care about (like X11, QT, ...). We want libcgroup to be able to -run without this bloat. - -From: Jan Safranek -diff -up libcgroup-0.36.2/scripts/init.d/cgconfig.in.lsb libcgroup-0.36.2/scripts/init.d/cgconfig.in ---- libcgroup-0.36.2/scripts/init.d/cgconfig.in.lsb 2010-03-11 13:05:16.000000000 +0100 -+++ libcgroup-0.36.2/scripts/init.d/cgconfig.in 2010-06-22 14:33:43.000000000 +0200 -@@ -44,7 +44,16 @@ servicename=cgconfig - # - # Source LSB routines - # --. /lib/lsb/init-functions -+. /etc/rc.d/init.d/functions -+log_success_msg () { -+ echo -n $*; success "$*"; echo -+} -+log_failure_msg () { -+ echo -n $*; failure "$*"; echo -+} -+log_warning_msg () { -+ echo -n $*; warning "$*"; echo -+} - - # read the config - CREATE_DEFAULT=yes -diff -up libcgroup-0.36.2/scripts/init.d/cgred.in.lsb libcgroup-0.36.2/scripts/init.d/cgred.in ---- libcgroup-0.36.2/scripts/init.d/cgred.in.lsb 2010-01-17 00:27:36.000000000 +0100 -+++ libcgroup-0.36.2/scripts/init.d/cgred.in 2010-06-22 14:33:43.000000000 +0200 -@@ -40,7 +40,15 @@ CGRED_BIN=$sbindir/cgrulesengd - - # Source function library & LSB routines - . /etc/rc.d/init.d/functions --. /lib/lsb/init-functions -+log_success_msg () { -+ echo -n $*; success "$*"; echo -+} -+log_failure_msg () { -+ echo -n $*; failure "$*"; echo -+} -+log_warning_msg () { -+ echo -n $*; warning "$*"; echo -+} - - # Read in configuration options. - if [ -f "/etc/sysconfig/cgred.conf" ] ; then diff --git a/libcgroup-0.36.2-systemd.patch b/libcgroup-0.36.2-systemd.patch deleted file mode 100644 index e1cf0c5..0000000 --- a/libcgroup-0.36.2-systemd.patch +++ /dev/null @@ -1,24 +0,0 @@ -Ignore systemd hierarchy. Quick&dirity fix for bug #627378 - -Author: Dhaval Giani - -@@ -, +, @@ - src/api.c | 8 ++++++++ - 1 file changed, 8 insertions(+) ---- libcgroup-0.36.2/src/api.c -+++ libcgroup-0.36.2/src/api.c -@@ -772,6 +772,14 @@ int cgroup_init(void) - * Check if it is a duplicate - */ - duplicate = 0; -+ -+ /* -+ * Ignore anything to do with systemd -+ */ -+ if (strncmp(mntopt, "name=systemd", -+ strlen("name=systemd")) == 0) -+ continue; -+ - for (j = 0; j < found_mnt; j++) { - if (strncmp(mntopt, cg_mount_table[j].name, - FILENAME_MAX) == 0) { diff --git a/libcgroup-0.37.1-systemd.patch b/libcgroup-0.37.1-systemd.patch deleted file mode 100644 index 8512201..0000000 --- a/libcgroup-0.37.1-systemd.patch +++ /dev/null @@ -1,194 +0,0 @@ -702111 - Starting LSB: start and stop the WLM configuration failed - - - cgconfigparser should not unmount stuff it did not mounted - - cgconfigparser should accept empty config file - - rename the service - -Backported these 3 pacthes: - -commit 7155cc27430619be5ffcf1ddc2b6bd8cf7d6d7e0 -Author: Dhaval Giani -Date: Fri May 27 10:36:19 2011 +0200 - - cgconfig: Do not touch subsystems not mounted by cgconfig - - cgconfig: Do not touch subsystems not mounted by cgconfig - - In its failure path, cgconfig should only touch the subsystems - it had something to do with. Currently, it unmounts all the - subsystems in the config file. Correct this. - - Signed-off-by: Dhaval Giani - Signed-off-by: Jan Safranek - -commit 431587f4e21b36a3f08bc595d716a70d70314e70 -Author: Jan Safranek -Date: Fri May 20 15:53:05 2011 +0200 - - Updated cgconfig service descriptions - - Signed-off-by: Jan Safranek - -commit 74e1b1e3d04c2f7999e367a20bf73396b61f9b64 -Author: Jan Safranek -Date: Fri May 20 15:52:58 2011 +0200 - - Fixed cgconfigparser to allow configs with no 'mount' section - - cgconfig service fails when something else mounts cgroup hierarchies during - boot (e.g. systemd). Therefore we should allow cgconfig.conf to have no - 'mount' section -> it's up to admin to ensure that controllers are mounted as - needed. - - Because 'group' section is already optional, with this patch cgconfigparser - will accept empty configuration file. This is probably the best default - config for distros with systemd. - - Changelog: - - fixed case with empty config file and no mounted controllers - - reworked the if conditions to be more clear - - Signed-off-by: Jan Safranek - -diff -up libcgroup-0.37.1/doc/man/cgconfig.conf.5.systemd2 libcgroup-0.37.1/doc/man/cgconfig.conf.5 ---- libcgroup-0.37.1/doc/man/cgconfig.conf.5.systemd2 2011-03-03 09:29:41.000000000 +0100 -+++ libcgroup-0.37.1/doc/man/cgconfig.conf.5 2011-05-30 15:06:45.083249011 +0200 -@@ -12,8 +12,8 @@ The file consists of - .I mount - and - .I group --sections. These sections can be in arbitrary order. Any line starting with --'#' is considered as a comment line and is ignored. -+sections. These sections can be in arbitrary order and both are optional. -+Any line starting with '#' is considered as a comment line and is ignored. - .LP - .I mount - section has this form: -@@ -50,6 +50,11 @@ controller, shall be mounted. The direct - automatically on cgconfig service startup if it does not exist and - is deleted on service shutdown. - .LP -+ -+If no -+.I mount -+section is specified, no controllers are mounted. -+ - .I group - section has this form: - .RS -@@ -171,6 +176,10 @@ created. Optionally it can be enclosed i - contain spaces then. - .RE - -+If no -+.I group -+section is specified, no groups are created. -+ - .\"********************************************" - .SH EXAMPLES - .LP -diff -up libcgroup-0.37.1/scripts/init.d/cgconfig.in.systemd2 libcgroup-0.37.1/scripts/init.d/cgconfig.in ---- libcgroup-0.37.1/scripts/init.d/cgconfig.in.systemd2 2011-05-30 15:00:36.269947252 +0200 -+++ libcgroup-0.37.1/scripts/init.d/cgconfig.in 2011-05-30 15:00:36.284946695 +0200 -@@ -25,8 +25,8 @@ - # Required-Stop: - # Should-Start: - # Should-Stop: --# Short-Description: start and stop the WLM configuration --# Description: This script allows us to create a default configuration -+# Short-Description: Create and setup control group filesystem(s) -+# Description: Create and setup control group filesystem(s) - ### END INIT INFO - - # get correct location of binaries from configure -diff -up libcgroup-0.37.1/src/config.c.systemd2 libcgroup-0.37.1/src/config.c ---- libcgroup-0.37.1/src/config.c.systemd2 2011-03-03 09:29:41.000000000 +0100 -+++ libcgroup-0.37.1/src/config.c 2011-05-30 15:17:08.317101247 +0200 -@@ -394,6 +394,7 @@ static int cgroup_config_mount_fs(void) - int ret; - struct stat buff; - int i; -+ int error; - - for (i = 0; i < config_table_index; i++) { - struct cg_mount_table_s *curr = &(config_mount_table[i]); -@@ -402,26 +403,39 @@ static int cgroup_config_mount_fs(void) - - if (ret < 0 && errno != ENOENT) { - last_errno = errno; -- return ECGOTHER; -+ error = ECGOTHER; -+ goto out_err; - } - - if (errno == ENOENT) { - ret = cg_mkdir_p(curr->path); -- if (ret) -- return ret; -+ if (ret) { -+ error = ret; -+ goto out_err; -+ } - } else if (!S_ISDIR(buff.st_mode)) { - errno = ENOTDIR; - last_errno = errno; -- return ECGOTHER; -+ error = ECGOTHER; -+ goto out_err; - } - - ret = mount(CGROUP_FILESYSTEM, curr->path, CGROUP_FILESYSTEM, - 0, curr->name); - -- if (ret < 0) -- return ECGMOUNTFAIL; -+ if (ret < 0) { -+ error = ECGMOUNTFAIL; -+ goto out_err; -+ } - } - return 0; -+out_err: -+ /* -+ * If we come here, we have failed. Since we have touched only -+ * mountpoints prior to i, we shall operate on only them now. -+ */ -+ config_table_index = 1; -+ return error; - } - - /* -@@ -681,24 +695,25 @@ int cgroup_config_load_config(const char - mount_enabled = (config_mount_table[0].name[0] != '\0'); - - /* -- * The configuration should have either namespace or mount. -- * Not both and not none. -+ * The configuration should have namespace or mount, not both. - */ -- if (namespace_enabled == mount_enabled) { -+ if (namespace_enabled && mount_enabled) { - free(config_cgroup_table); - return ECGMOUNTNAMESPACE; - } - -- /* -- * We do not allow both mount and namespace sections in the -- * same configuration file. So test for that -- */ -- - error = cgroup_config_mount_fs(); - if (error) - goto err_mnt; - - error = cgroup_init(); -+ if (error == ECGROUPNOTMOUNTED && cgroup_table_index == 0) { -+ /* -+ * The config file seems to be empty. -+ */ -+ error = 0; -+ goto err_mnt; -+ } - if (error) - goto err_mnt; - diff --git a/libcgroup.spec b/libcgroup.spec index 85f2e63..213a941 100644 --- a/libcgroup.spec +++ b/libcgroup.spec @@ -1,27 +1,30 @@ -%define soversion 1.0.37 +%define soversion 1.0.38 %define soversion_major 1 Name: libcgroup Summary: Library to control and monitor control groups Group: Development/Libraries -Version: 0.37.1 -Release: 4%{?dist} +Version: 0.38 +Release: 0.1.rc1%{?dist} License: LGPLv2+ URL: http://libcg.sourceforge.net/ -Source0: http://downloads.sourceforge.net/libcg/%{name}-%{version}.tar.bz2 -Source1: README.Fedora +Source0: http://downloads.sourceforge.net/libcg/%{name}-%{version}.rc1.tar.bz2 +Source1: cgconfig.service +Source2: cgred.service +Source3: cgred.sysconfig Patch1: fedora-config.patch -Patch2: fedora-fix-initscripts.patch -Patch3: libcgroup-0.36.2-systemd.patch -Patch4: libcgroup-0.37.1-systemd.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildRequires: pam-devel BuildRequires: byacc BuildRequires: flex BuildRequires: coreutils +BuildRequires: systemd-units Requires(pre): shadow-utils Requires(post): chkconfig, /sbin/service Requires(preun): /sbin/chkconfig +Requires(post): systemd-units +Requires(preun): systemd-units +Requires(postun): systemd-units %description Control groups infrastructure. The library helps manipulate, control, @@ -56,14 +59,11 @@ future allow creation of persistent configuration for control groups and provide scripts to manage that configuration. %prep -%setup -q +%setup -q -n %{name}-%{version}.rc1 %patch1 -p1 -b .config -%patch2 -p1 -b .lsb -%patch3 -p1 -b .systemd -%patch4 -p1 -b .systemd2 %build -%configure --bindir=/bin --sbindir=/sbin --libdir=%{_libdir} --enable-initscript-install --enable-pam-module-dir=/%{_lib}/security +%configure --enable-pam-module-dir=/%{_lib}/security --enable-opaque-hierarchy="name=systemd" make %{?_smp_mflags} @@ -73,30 +73,23 @@ rm -rf $RPM_BUILD_ROOT make DESTDIR=$RPM_BUILD_ROOT install # install config files -mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig -cp samples/cgred.conf $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/cgred.conf -cp samples/cgconfig.sysconfig $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/cgconfig -cp samples/cgconfig.conf $RPM_BUILD_ROOT/%{_sysconfdir}/cgconfig.conf -cp samples/cgrules.conf $RPM_BUILD_ROOT/%{_sysconfdir}/cgrules.conf -cp samples/cgsnapshot_blacklist.conf $RPM_BUILD_ROOT/%{_sysconfdir}/cgsnapshot_blacklist.conf +install -d ${RPM_BUILD_ROOT}%{_sysconfdir} +install -m 644 samples/cgconfig.conf $RPM_BUILD_ROOT/%{_sysconfdir}/cgconfig.conf +install -m 644 samples/cgrules.conf $RPM_BUILD_ROOT/%{_sysconfdir}/cgrules.conf +install -m 644 samples/cgsnapshot_blacklist.conf $RPM_BUILD_ROOT/%{_sysconfdir}/cgsnapshot_blacklist.conf # sanitize pam module, we need only pam_cgroup.so mv -f $RPM_BUILD_ROOT/%{_lib}/security/pam_cgroup.so.*.*.* $RPM_BUILD_ROOT/%{_lib}/security/pam_cgroup.so rm -f $RPM_BUILD_ROOT/%{_lib}/security/pam_cgroup.la $RPM_BUILD_ROOT/%{_lib}/security/pam_cgroup.so.* -# move the libraries to / -mkdir -p $RPM_BUILD_ROOT/%{_lib} -mv -f $RPM_BUILD_ROOT/%{_libdir}/libcgroup.so.%{soversion} $RPM_BUILD_ROOT/%{_lib} -rm -f $RPM_BUILD_ROOT/%{_libdir}/libcgroup.so.%{soversion_major} -ln -sf libcgroup.so.%{soversion} $RPM_BUILD_ROOT/%{_lib}/libcgroup.so.%{soversion_major} -ln -sf ../../%{_lib}/libcgroup.so.%{soversion} $RPM_BUILD_ROOT/%{_libdir}/libcgroup.so rm -f $RPM_BUILD_ROOT/%{_libdir}/*.la -# pre-create /cgroup directory -mkdir $RPM_BUILD_ROOT/cgroup - -# install README.Fedora -cp %SOURCE1 . +# install unit and sysconfig files +install -d ${RPM_BUILD_ROOT}%{_unitdir} +install -m 644 %SOURCE1 ${RPM_BUILD_ROOT}%{_unitdir}/ +install -m 644 %SOURCE2 ${RPM_BUILD_ROOT}%{_unitdir}/ +install -d ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig +install -m 644 %SOURCE3 ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/cgred %clean rm -rf $RPM_BUILD_ROOT @@ -109,49 +102,70 @@ rm -rf $RPM_BUILD_ROOT getent group cgred >/dev/null || groupadd -r cgred %post tools -/sbin/chkconfig --add cgred -/sbin/chkconfig --add cgconfig - -%preun tools -if [ $1 = 0 ]; then - /sbin/service cgred stop > /dev/null 2>&1 || : - /sbin/service cgconfig stop > /dev/null 2>&1 || : - /sbin/chkconfig --del cgconfig - /sbin/chkconfig --del cgred +if [ $1 -eq 1 ] ; then + # Initial installation + /bin/systemctl daemon-reload >/dev/null 2>&1 || : fi +%preun tools +if [ $1 -eq 0 ] ; then + # Package removal, not upgrade + /bin/systemctl --no-reload disable cgconfig.service > /dev/null 2>&1 || : + /bin/systemctl stop cgconfig.service > /dev/null 2>&1 || : + /bin/systemctl --no-reload disable cgred.service > /dev/null 2>&1 || : + /bin/systemctl stop cgred.service > /dev/null 2>&1 || : +fi + +%postun tools +/bin/systemctl daemon-reload >/dev/null 2>&1 || : +if [ $1 -ge 1 ] ; then + # Package upgrade, not uninstall + /bin/systemctl try-restart cgconfig.service >/dev/null 2>&1 || : + /bin/systemctl try-restart cgred.service >/dev/null 2>&1 || : +fi + +%triggerun -- libcgroup < 0.38 +# Save the current service runlevel info +# User must manually run systemd-sysv-convert --apply cgconfig/cgred +# to migrate them to systemd targets +/usr/bin/systemd-sysv-convert --save cgconfig >/dev/null 2>&1 ||: +/usr/bin/systemd-sysv-convert --save cgred >/dev/null 2>&1 ||: + +# Run these because the SysV package being removed won't do them +/sbin/chkconfig --del cgconfig >/dev/null 2>&1 || : +/bin/systemctl try-restart cgconfig.service >/dev/null 2>&1 || : +/sbin/chkconfig --del cgred >/dev/null 2>&1 || : +/bin/systemctl try-restart cgred.service >/dev/null 2>&1 || : %files %defattr(-,root,root,-) -/%{_lib}/libcgroup.so.* -%doc COPYING INSTALL README.Fedora -%attr(0755,root,root) %ghost %dir /cgroup +%{_libdir}/libcgroup.so.* +%doc COPYING INSTALL %files tools %defattr(-,root,root,-) -%doc README_daemon -%config(noreplace) %{_sysconfdir}/sysconfig/cgred.conf -%config(noreplace) %{_sysconfdir}/sysconfig/cgconfig +%doc README_daemon README_systemd %config(noreplace) %{_sysconfdir}/cgconfig.conf %config(noreplace) %{_sysconfdir}/cgrules.conf %config(noreplace) %{_sysconfdir}/cgsnapshot_blacklist.conf -/bin/cgclassify -/bin/cgcreate -/bin/cgget -/bin/cgset -/bin/cgdelete -/bin/lscgroup -/bin/lssubsys -/sbin/cgconfigparser -/sbin/cgrulesengd -/sbin/cgclear -/bin/cgsnapshot -%attr(2755, root, cgred) /bin/cgexec +%config(noreplace) %{_sysconfdir}/sysconfig/cgred +/usr/bin/cgclassify +/usr/bin/cgcreate +/usr/bin/cgget +/usr/bin/cgset +/usr/bin/cgdelete +/usr/bin/lscgroup +/usr/bin/lssubsys +/usr/sbin/cgconfigparser +/usr/sbin/cgrulesengd +/usr/sbin/cgclear +/usr/bin/cgsnapshot +%attr(2755, root, cgred) /usr/bin/cgexec %attr(0644, root, root) %{_mandir}/man1/* %attr(0644, root, root) %{_mandir}/man5/* %attr(0644, root, root) %{_mandir}/man8/* -%attr(0755,root,root) %{_initrddir}/cgconfig -%attr(0755,root,root) %{_initrddir}/cgred +%{_unitdir}/cgconfig.service +%{_unitdir}/cgred.service %files pam %defattr(-,root,root,-) @@ -162,11 +176,14 @@ fi %defattr(-,root,root,-) %{_includedir}/libcgroup.h %{_includedir}/libcgroup/*.h -%{_libdir}/libcgroup.* -/%{_libdir}/pkgconfig/libcgroup.pc +%{_libdir}/libcgroup.so +%{_libdir}/pkgconfig/libcgroup.pc %doc COPYING INSTALL %changelog +* Fri Feb 3 2012 Jan Safranek 0.38.rc1-1 +- updated to 0.38 + * Mon May 30 2011 Jan Safranek 0.37.1-4 - fixed cgconfig service not to unmount stuff it did not mount - added better sample cgconfig.conf file to reflect systemd diff --git a/sources b/sources index e90669b..abe083f 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -24a41b18de112e8d085bb1f7d9e82af7 libcgroup-0.37.1.tar.bz2 +6c2100af9840f54f8bf97836887a4517 libcgroup-0.38.rc1.tar.bz2